Commit 4855c26b authored by Tom Niget's avatar Tom Niget

Add check that type is unboxed in annotation result

parent 55ebf017
...@@ -4,7 +4,7 @@ from typing import Dict, Optional ...@@ -4,7 +4,7 @@ from typing import Dict, Optional
from transpiler.phases.typing.annotations import TypeAnnotationVisitor from transpiler.phases.typing.annotations import TypeAnnotationVisitor
from transpiler.phases.typing.scope import Scope, ScopeKind, VarDecl from transpiler.phases.typing.scope import Scope, ScopeKind, VarDecl
from transpiler.phases.typing.types import BaseType, TypeVariable, TY_NONE from transpiler.phases.typing.types import BaseType, TypeVariable, TY_NONE, TypeType
from transpiler.phases.utils import NodeVisitorSeq from transpiler.phases.utils import NodeVisitorSeq
PRELUDE = Scope.make_global() PRELUDE = Scope.make_global()
...@@ -19,7 +19,9 @@ class ScoperVisitor(NodeVisitorSeq): ...@@ -19,7 +19,9 @@ class ScoperVisitor(NodeVisitorSeq):
return TypeAnnotationVisitor(self.scope, self.cur_class) return TypeAnnotationVisitor(self.scope, self.cur_class)
def visit_annotation(self, expr: Optional[ast.expr]) -> BaseType: def visit_annotation(self, expr: Optional[ast.expr]) -> BaseType:
return self.anno().visit(expr) if expr else TypeVariable() res = self.anno().visit(expr) if expr else TypeVariable()
assert not isinstance(res, TypeType)
return res
def visit_block(self, block: list[ast.AST]): def visit_block(self, block: list[ast.AST]):
from transpiler.phases.typing.block import ScoperBlockVisitor from transpiler.phases.typing.block import ScoperBlockVisitor
...@@ -34,3 +36,4 @@ class ScoperVisitor(NodeVisitorSeq): ...@@ -34,3 +36,4 @@ class ScoperVisitor(NodeVisitorSeq):
b.decls = decls b.decls = decls
if not node.inner_scope.has_return: if not node.inner_scope.has_return:
rtype.unify(TY_NONE) rtype.unify(TY_NONE)
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