Commit ae2a779c authored by Tom Niget's avatar Tom Niget

Fix substitution of Self type in functions

parent b3201b2f
...@@ -105,7 +105,7 @@ class ScoperExprVisitor(ScoperVisitor): ...@@ -105,7 +105,7 @@ class ScoperExprVisitor(ScoperVisitor):
def visit_Call(self, node: ast.Call) -> BaseType: def visit_Call(self, node: ast.Call) -> BaseType:
ftype = self.visit(node.func) ftype = self.visit(node.func)
if ftype.typevars: if ftype.typevars:
ftype = ftype.gen_sub(None, {v.name: TypeVariable(v.name) for v in ftype.typevars}) ftype = ftype.gen_sub(ftype, {v.name: TypeVariable(v.name) for v in ftype.typevars})
rtype = self.visit_function_call(ftype, [self.visit(arg) for arg in node.args]) rtype = self.visit_function_call(ftype, [self.visit(arg) for arg in node.args])
actual = rtype actual = rtype
node.is_await = False node.is_await = False
...@@ -174,6 +174,7 @@ class ScoperExprVisitor(ScoperVisitor): ...@@ -174,6 +174,7 @@ class ScoperExprVisitor(ScoperVisitor):
attr.python_func_used = True attr.python_func_used = True
return attr return attr
if meth := ltype.methods.get(name): if meth := ltype.methods.get(name):
meth = meth.gen_sub(ltype, {})
if bound: if bound:
return meth.remove_self() return meth.remove_self()
else: else:
......
...@@ -241,9 +241,10 @@ class TypeOperator(BaseType, ABC): ...@@ -241,9 +241,10 @@ class TypeOperator(BaseType, ABC):
return me return me
if len(self.args) == 0: if len(self.args) == 0:
return self return self
assert all(x is not None for x in self.args)
res = object.__new__(self.__class__) # todo: ugly... should make a clone() res = object.__new__(self.__class__) # todo: ugly... should make a clone()
cache[self] = res cache[self] = res
if isinstance(this, TypeOperator): if isinstance(this, TypeOperator) and not isinstance(this, FunctionType):
vardict = dict(zip(typevars.keys(), this.args)) vardict = dict(zip(typevars.keys(), this.args))
else: else:
vardict = typevars vardict = typevars
......
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