Commit 944721b8 authored by Tom Niget's avatar Tom Niget

Fix `Self` handling in classes

parent af719a0a
......@@ -15,7 +15,10 @@ class TypeAnnotationVisitor(NodeVisitorSeq):
def visit_str(self, node: str) -> BaseType:
if node in ("Self", "self") and self.cur_class:
return TY_SELF
if isinstance(self.cur_class.type_object, abc.ABCMeta) or self.cur_class.type_object.is_protocol_gen or self.cur_class.type_object.is_protocol:
return TY_SELF
else:
return self.cur_class.type_object
if existing := self.scope.get(node):
ty = existing.type
if isinstance(ty, TypeType) and isinstance(ty.type_object, TypeVariable):
......
......@@ -116,13 +116,14 @@ class ScoperBlockVisitor(ScoperVisitor):
def visit_ClassDef(self, node: ast.ClassDef):
ctype = UserType(node.name)
self.scope.vars[node.name] = VarDecl(VarKind.LOCAL, TypeType(ctype))
cttype = TypeType(ctype)
self.scope.vars[node.name] = VarDecl(VarKind.LOCAL, cttype)
scope = self.scope.child(ScopeKind.CLASS)
scope.obj_type = ctype
scope.class_ = scope
node.inner_scope = scope
node.type = ctype
visitor = ScoperClassVisitor(scope)
visitor = ScoperClassVisitor(scope, cur_class=cttype)
visitor.visit_block(node.body)
def visit_If(self, node: ast.If):
......
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