Commit 4e289013 authored by Tom Niget's avatar Tom Niget

Fix TypeVar instantiation

parent b4c7b909
...@@ -65,14 +65,11 @@ class StdlibVisitor(NodeVisitorSeq): ...@@ -65,14 +65,11 @@ class StdlibVisitor(NodeVisitorSeq):
ty = FunctionType(arg_types, ret_type) ty = FunctionType(arg_types, ret_type)
if node.args.vararg: if node.args.vararg:
ty.variadic = True ty.variadic = True
#arg_types.append(TY_VARARG)
if self.cur_class: if self.cur_class:
assert isinstance(self.cur_class, TypeType) assert isinstance(self.cur_class, TypeType)
if isinstance(self.cur_class.type_object, ABCMeta): if isinstance(self.cur_class.type_object, ABCMeta):
self.cur_class.type_object.gen_methods[node.name] = lambda t: ty.gen_sub(t, self.typevars) self.cur_class.type_object.gen_methods[node.name] = lambda t: ty.gen_sub(t, self.typevars)
else: else:
# ty_inst = FunctionType(arg_types[1:], ret_type)
# self.cur_class.args[0].add_inst_member(node.name, ty_inst)
self.cur_class.type_object.methods[node.name] = ty.gen_sub(self.cur_class.type_object, self.typevars) self.cur_class.type_object.methods[node.name] = ty.gen_sub(self.cur_class.type_object, self.typevars)
self.scope.vars[node.name] = VarDecl(VarKind.LOCAL, ty) self.scope.vars[node.name] = VarDecl(VarKind.LOCAL, ty)
...@@ -81,9 +78,9 @@ class StdlibVisitor(NodeVisitorSeq): ...@@ -81,9 +78,9 @@ class StdlibVisitor(NodeVisitorSeq):
def visit_Call(self, node: ast.Call) -> BaseType: def visit_Call(self, node: ast.Call) -> BaseType:
ty_op = self.visit(node.func) ty_op = self.visit(node.func)
if isinstance(ty_op, type): if isinstance(ty_op, TypeType):
return ty_op(*[ast.literal_eval(arg) for arg in node.args]) return ty_op.type_object(*[ast.literal_eval(arg) for arg in node.args])
raise NotImplementedError raise NotImplementedError(ast.unparse(node))
def anno(self) -> "TypeAnnotationVisitor": def anno(self) -> "TypeAnnotationVisitor":
return TypeAnnotationVisitor(self.scope, self.cur_class) return TypeAnnotationVisitor(self.scope, self.cur_class)
......
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