Skip to content

Commit

Permalink
[mypyc] Fix regression with nested functions (#16484)
Browse files Browse the repository at this point in the history
Fixes #16480

Fix is straightforward, but also suspicious, since I am not sure how it
ever worked without this.
  • Loading branch information
ilevkivskyi authored and JukkaL committed Nov 22, 2023
1 parent e6399d1 commit c10e173
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
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

0 comments on commit c10e173

Please sign in to comment.