Commit e643dbd0 authored by Tom Niget's avatar Tom Niget

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

parent f964bee3
...@@ -10,6 +10,14 @@ ...@@ -10,6 +10,14 @@
#include <ostream> #include <ostream>
#include <string> #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; using namespace std::literals;
// typon_len // typon_len
......
...@@ -408,9 +408,13 @@ class BlockVisitor(NodeVisitor): ...@@ -408,9 +408,13 @@ class BlockVisitor(NodeVisitor):
return result return result
except UnsupportedNodeError as e: except UnsupportedNodeError as e:
if isinstance(e.node, ast.Yield): 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 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]: def visit_func(self, node: ast.FunctionDef, generator: CoroutineMode) -> Iterable[str]:
templ, args, names = self.process_args(node.args) templ, args, names = self.process_args(node.args)
if templ: if templ:
...@@ -478,6 +482,8 @@ class BlockVisitor(NodeVisitor): ...@@ -478,6 +482,8 @@ class BlockVisitor(NodeVisitor):
elif decl.kind in (VarKind.GLOBAL, VarKind.NONLOCAL): # `global` and `nonlocal` just get hoisted as-is. elif decl.kind in (VarKind.GLOBAL, VarKind.NONLOCAL): # `global` and `nonlocal` just get hoisted as-is.
inner_scope.vars[var] = decl inner_scope.vars[var] = decl
yield from child_code # Yeet back the child node code. 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 "}" yield "}"
def visit_lvalue(self, lvalue: ast.expr, val: Optional[ast.AST] = None) -> Iterable[str]: 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