Commit 968bedc0 authored by Tom Niget's avatar Tom Niget

Fix some Python unification problems

parent 551ba3cc
...@@ -76,8 +76,8 @@ class ModuleVisitor(BlockVisitor): ...@@ -76,8 +76,8 @@ class ModuleVisitor(BlockVisitor):
yield "" yield ""
elif node.module_obj.is_python: elif node.module_obj.is_python:
for alias in node.names: for alias in node.names:
fty = alias.item_obj fty = alias.item_obj.resolve()
assert isinstance(fty, FunctionType) #assert isinstance(fty, FunctionType)
yield from self.emit_python_func(node.module, alias.name, alias.asname or alias.name, fty) yield from self.emit_python_func(node.module, alias.name, alias.asname or alias.name, fty)
else: else:
......
...@@ -131,14 +131,18 @@ class ScoperExprVisitor(ScoperVisitor): ...@@ -131,14 +131,18 @@ class ScoperExprVisitor(ScoperVisitor):
init: FunctionType = self.visit_getattr(ftype, "__init__").remove_self() init: FunctionType = self.visit_getattr(ftype, "__init__").remove_self()
init.return_type = ftype.type_object init.return_type = ftype.type_object
return self.visit_function_call(init, arguments) return self.visit_function_call(init, arguments)
if not isinstance(ftype, FunctionType): if isinstance(ftype, FunctionType):
ret = ftype.return_type
elif isinstance(ftype, TypeVariable):
ret = TypeVariable()
else:
from transpiler.phases.typing.exceptions import NotCallableError from transpiler.phases.typing.exceptions import NotCallableError
raise NotCallableError(ftype) raise NotCallableError(ftype)
#is_generic = any(isinstance(arg, TypeVariable) for arg in ftype.to_list()) #is_generic = any(isinstance(arg, TypeVariable) for arg in ftype.to_list())
equivalent = FunctionType(arguments, ftype.return_type) equivalent = FunctionType(arguments, ret)
equivalent.is_intermediary = True equivalent.is_intermediary = True
ftype.unify(equivalent) ftype.unify(equivalent)
return ftype.return_type return equivalent.return_type
def visit_Lambda(self, node: ast.Lambda) -> BaseType: def visit_Lambda(self, node: ast.Lambda) -> BaseType:
argtypes = [TypeVariable() for _ in node.args.args] argtypes = [TypeVariable() for _ in node.args.args]
......
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