Skip to content

Commit b425bd6

Browse files
authored
[mypyc] Fix regression with nested functions (#16484)
Fixes #16480 Fix is straightforward, but also suspicious, since I am not sure how it ever worked without this.
1 parent 0699dde commit b425bd6

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

mypyc/irbuild/prebuildvisitor.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,10 @@ def visit_decorator(self, dec: Decorator) -> None:
119119
self.funcs_to_decorators[dec.func] = decorators_to_store
120120
super().visit_decorator(dec)
121121

122-
def visit_func_def(self, fdef: FuncItem) -> None:
122+
def visit_func_def(self, fdef: FuncDef) -> None:
123123
# TODO: What about overloaded functions?
124124
self.visit_func(fdef)
125+
self.visit_symbol_node(fdef)
125126

126127
def visit_lambda_expr(self, expr: LambdaExpr) -> None:
127128
self.visit_func(expr)

mypyc/test-data/run-functions.test

+22
Original file line numberDiff line numberDiff line change
@@ -1286,3 +1286,25 @@ def bar() -> None:
12861286
bar()
12871287
[out]
12881288
{'__module__': 'native', '__name__': 'bar', '__qualname__': 'bar', '__doc__': None, '__wrapped__': <built-in function bar>}
1289+
1290+
[case testCallNestedFunctionWithNamed]
1291+
def f() -> None:
1292+
def a() -> None:
1293+
pass
1294+
def b() -> None:
1295+
a()
1296+
b()
1297+
[file driver.py]
1298+
from native import f
1299+
f()
1300+
1301+
[case testCallNestedFunctionWithLambda]
1302+
def f(x: int) -> int:
1303+
def inc(x: int) -> int:
1304+
return x + 1
1305+
return (lambda x: inc(x))(1)
1306+
[file driver.py]
1307+
from native import f
1308+
print(f(1))
1309+
[out]
1310+
2

0 commit comments

Comments
 (0)