Commit be810856 authored by Tom Niget's avatar Tom Niget

Enhance error handling

parent 2be850ba
...@@ -8,6 +8,7 @@ from transpiler.phases.typing.class_ import ScoperClassVisitor ...@@ -8,6 +8,7 @@ from transpiler.phases.typing.class_ import ScoperClassVisitor
from transpiler.phases.typing.scope import VarDecl, VarKind, ScopeKind from transpiler.phases.typing.scope import VarDecl, VarKind, ScopeKind
from transpiler.phases.typing.types import BaseType, TypeVariable, FunctionType, IncompatibleTypesError, \ from transpiler.phases.typing.types import BaseType, TypeVariable, FunctionType, IncompatibleTypesError, \
Promise, TY_NONE, PromiseKind, TupleType, UserType, TypeType, ModuleType Promise, TY_NONE, PromiseKind, TupleType, UserType, TypeType, ModuleType
from transpiler.phases.utils import PlainBlock
@dataclass @dataclass
...@@ -23,6 +24,9 @@ class ScoperBlockVisitor(ScoperVisitor): ...@@ -23,6 +24,9 @@ class ScoperBlockVisitor(ScoperVisitor):
def visit_Import(self, node: ast.Import): def visit_Import(self, node: ast.Import):
for alias in node.names: for alias in node.names:
mod = self.scope.get(alias.name, VarKind.MODULE) mod = self.scope.get(alias.name, VarKind.MODULE)
if mod is None:
raise NameError(alias.name)
assert isinstance(mod, VarDecl), mod
self.scope.vars[alias.asname or alias.name] = dataclasses.replace(mod, kind=VarKind.LOCAL) self.scope.vars[alias.asname or alias.name] = dataclasses.replace(mod, kind=VarKind.LOCAL)
def visit_ImportFrom(self, node: ast.ImportFrom): def visit_ImportFrom(self, node: ast.ImportFrom):
...@@ -174,7 +178,7 @@ class ScoperBlockVisitor(ScoperVisitor): ...@@ -174,7 +178,7 @@ class ScoperBlockVisitor(ScoperVisitor):
try: try:
iter_type = seq_type.methods["__iter__"].return_type iter_type = seq_type.methods["__iter__"].return_type
except: except:
raise IncompatibleTypesError(f"{seq_type} is not iterable") raise IncompatibleTypesError(f"{seq_type} is not iterable in `{ast.unparse(node.iter)}`")
try: try:
next_type = iter_type.methods["__next__"].return_type next_type = iter_type.methods["__next__"].return_type
except: except:
......
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