Skip to content

[mypyc] Fix regression with nested functions #16484

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion mypyc/irbuild/prebuildvisitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,10 @@ def visit_decorator(self, dec: Decorator) -> None:
self.funcs_to_decorators[dec.func] = decorators_to_store
super().visit_decorator(dec)

def visit_func_def(self, fdef: FuncItem) -> None:
def visit_func_def(self, fdef: FuncDef) -> None:
# TODO: What about overloaded functions?
self.visit_func(fdef)
self.visit_symbol_node(fdef)

def visit_lambda_expr(self, expr: LambdaExpr) -> None:
self.visit_func(expr)
Expand Down
22 changes: 22 additions & 0 deletions mypyc/test-data/run-functions.test
Original file line number Diff line number Diff line change
Expand Up @@ -1286,3 +1286,25 @@ def bar() -> None:
bar()
[out]
{'__module__': 'native', '__name__': 'bar', '__qualname__': 'bar', '__doc__': None, '__wrapped__': <built-in function bar>}

[case testCallNestedFunctionWithNamed]
def f() -> None:
def a() -> None:
pass
def b() -> None:
a()
b()
[file driver.py]
from native import f
f()

[case testCallNestedFunctionWithLambda]
def f(x: int) -> int:
def inc(x: int) -> int:
return x + 1
return (lambda x: inc(x))(1)
[file driver.py]
from native import f
print(f(1))
[out]
2