Commit 45014685 authored by Tom Niget's avatar Tom Niget

Make fake function end unreachable so the compiler doesn't complain about missing return

parent 37e3c944
......@@ -10,6 +10,14 @@
#include <ostream>
#include <string>
#ifdef __cpp_lib_unreachable
#include <utility>
[[noreturn]] inline void TYPON_UNREACHABLE() { std::unreachable(); }
#else
#include <cstdlib>
[[noreturn]] inline void TYPON_UNREACHABLE() { std::abort(); }
#endif
using namespace std::literals;
// typon_len
......
......@@ -408,9 +408,13 @@ class BlockVisitor(NodeVisitor):
return result
except UnsupportedNodeError as e:
if isinstance(e.node, ast.Yield):
return chain(self.visit_func(node, CoroutineMode.FAKE), self.visit_func(node, CoroutineMode.GENERATOR))
return self.visit_coroutine(node)
raise
def visit_coroutine(self, node: ast.FunctionDef) -> Iterable[str]:
yield from self.visit_func(node, CoroutineMode.FAKE)
yield from self.visit_func(node, CoroutineMode.GENERATOR)
def visit_func(self, node: ast.FunctionDef, generator: CoroutineMode) -> Iterable[str]:
templ, args, names = self.process_args(node.args)
if templ:
......@@ -478,6 +482,8 @@ class BlockVisitor(NodeVisitor):
elif decl.kind in (VarKind.GLOBAL, VarKind.NONLOCAL): # `global` and `nonlocal` just get hoisted as-is.
inner_scope.vars[var] = decl
yield from child_code # Yeet back the child node code.
if generator == CoroutineMode.FAKE:
yield "TYPON_UNREACHABLE();" # So the compiler doesn't complain about missing return statements.
yield "}"
def visit_lvalue(self, lvalue: ast.expr, val: Optional[ast.AST] = None) -> Iterable[str]:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment