Commit 8ef51d10 authored by Tom Niget's avatar Tom Niget

Enhance error handling

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