Commit 173e8636 authored by Tom Niget's avatar Tom Niget

Fix user type storage in scope

parent 067451b0
...@@ -6,7 +6,7 @@ from transpiler.phases.typing.expr import ScoperExprVisitor ...@@ -6,7 +6,7 @@ from transpiler.phases.typing.expr import ScoperExprVisitor
from transpiler.phases.typing.class_ import ScoperClassVisitor 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, TY_MODULE, \ from transpiler.phases.typing.types import BaseType, TypeVariable, FunctionType, IncompatibleTypesError, TY_MODULE, \
Promise, TY_NONE, PromiseKind, TupleType, UserType Promise, TY_NONE, PromiseKind, TupleType, UserType, TypeType
@dataclass @dataclass
...@@ -100,7 +100,7 @@ class ScoperBlockVisitor(ScoperVisitor): ...@@ -100,7 +100,7 @@ class ScoperBlockVisitor(ScoperVisitor):
def visit_ClassDef(self, node: ast.ClassDef): def visit_ClassDef(self, node: ast.ClassDef):
ctype = UserType(node.name) ctype = UserType(node.name)
self.scope.vars[node.name] = VarDecl(VarKind.LOCAL, ctype) self.scope.vars[node.name] = VarDecl(VarKind.LOCAL, TypeType(ctype))
scope = self.scope.child(ScopeKind.CLASS) scope = self.scope.child(ScopeKind.CLASS)
scope.obj_type = ctype scope.obj_type = ctype
scope.class_ = scope scope.class_ = scope
......
...@@ -105,9 +105,9 @@ class ScoperExprVisitor(ScoperVisitor): ...@@ -105,9 +105,9 @@ class ScoperExprVisitor(ScoperVisitor):
return actual return actual
def visit_function_call(self, ftype: BaseType, arguments: List[BaseType]): def visit_function_call(self, ftype: BaseType, arguments: List[BaseType]):
if isinstance(ftype, UserType): if isinstance(ftype, TypeType) and isinstance(ftype.type_object, UserType):
init: FunctionType = self.visit_getattr(ftype, "__init__") init: FunctionType = self.visit_getattr(ftype.type_object, "__init__")
ctor = FunctionType(init.args[1:], ftype) ctor = FunctionType(init.args[1:], ftype.type_object)
return self.visit_function_call(ctor, arguments) return self.visit_function_call(ctor, arguments)
if not isinstance(ftype, FunctionType): if not isinstance(ftype, FunctionType):
raise IncompatibleTypesError(f"Cannot call {ftype}") raise IncompatibleTypesError(f"Cannot call {ftype}")
......
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