1.1 --- a/tests/lambda.py Sat Sep 02 01:56:02 2023 +0200
1.2 +++ b/tests/lambda.py Sat Sep 02 22:08:53 2023 +0200
1.3 @@ -1,5 +1,9 @@
1.4 f = lambda x: (x, 1)
1.5
1.6 +g = lambda x: x.f
1.7 +
1.8 +h = lambda x: x(234)
1.9 +
1.10 class C:
1.11 f = lambda x: (x, 2)
1.12
1.13 @@ -15,3 +19,11 @@
1.14 C.f = f
1.15 c2 = C()
1.16 print c2.f(123) # (123, 1)
1.17 +
1.18 +print g # __main__.C.$l1
1.19 +print g(c) # __main__.C.$l0
1.20 +
1.21 +a = g(c)
1.22 +print a(123) # (123, 1)
1.23 +
1.24 +print h(a) # (234, 1)
2.1 --- a/translator.py Sat Sep 02 01:56:02 2023 +0200
2.2 +++ b/translator.py Sat Sep 02 22:08:53 2023 +0200
2.3 @@ -341,11 +341,15 @@
2.4 else:
2.5 return None
2.6
2.7 - def process_statement_node(self, node):
2.8 + def process_statement_node(self, node, is_lambda=False):
2.9
2.10 "Process the given statement 'node'."
2.11
2.12 self.reset_temp_counters()
2.13 +
2.14 + if is_lambda:
2.15 + self.result_target_name = "__result"
2.16 +
2.17 return CommonModule.process_statement_node(self, node)
2.18
2.19 def process_structure_node(self, n):
2.20 @@ -912,7 +916,9 @@
2.21
2.22 # Produce the body and any additional return statement.
2.23
2.24 - expr = self.process_statement_node(n.code) or \
2.25 + is_lambda = isinstance(n, compiler.ast.Lambda)
2.26 +
2.27 + expr = self.process_statement_node(n.code, is_lambda) or \
2.28 self.in_method() and \
2.29 function_name.rsplit(".", 1)[-1] == "__init__" and \
2.30 TrResolvedNameRef("self", self.importer.function_locals[function_name]["self"]) or \