From c10e17348f2eacbbeae80eb6c10c661c0137d849 Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Thu, 16 Nov 2023 11:56:53 +0000 Subject: [PATCH] [mypyc] Fix regression with nested functions (#16484) Fixes https://github.com/python/mypy/issues/16480 Fix is straightforward, but also suspicious, since I am not sure how it ever worked without this. --- mypyc/irbuild/prebuildvisitor.py | 3 ++- mypyc/test-data/run-functions.test | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/mypyc/irbuild/prebuildvisitor.py b/mypyc/irbuild/prebuildvisitor.py index 519b3445e925..17f907d42111 100644 --- a/mypyc/irbuild/prebuildvisitor.py +++ b/mypyc/irbuild/prebuildvisitor.py @@ -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) diff --git a/mypyc/test-data/run-functions.test b/mypyc/test-data/run-functions.test index bd8f1a9197dd..cf519f30dad8 100644 --- a/mypyc/test-data/run-functions.test +++ b/mypyc/test-data/run-functions.test @@ -1286,3 +1286,25 @@ def bar() -> None: bar() [out] {'__module__': 'native', '__name__': 'bar', '__qualname__': 'bar', '__doc__': None, '__wrapped__': } + +[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