# HG changeset patch # User Paul Boddie # Date 1693685333 -7200 # Node ID 50ec3f06be032a847a851f956eb73e2c59e62218 # Parent 780203697b708ed4fb6cf28c99797636406a5803 Make sure that the result target is set for lambdas. diff -r 780203697b70 -r 50ec3f06be03 tests/lambda.py --- a/tests/lambda.py Sat Sep 02 01:56:02 2023 +0200 +++ b/tests/lambda.py Sat Sep 02 22:08:53 2023 +0200 @@ -1,5 +1,9 @@ f = lambda x: (x, 1) +g = lambda x: x.f + +h = lambda x: x(234) + class C: f = lambda x: (x, 2) @@ -15,3 +19,11 @@ C.f = f c2 = C() print c2.f(123) # (123, 1) + +print g # __main__.C.$l1 +print g(c) # __main__.C.$l0 + +a = g(c) +print a(123) # (123, 1) + +print h(a) # (234, 1) diff -r 780203697b70 -r 50ec3f06be03 translator.py --- a/translator.py Sat Sep 02 01:56:02 2023 +0200 +++ b/translator.py Sat Sep 02 22:08:53 2023 +0200 @@ -341,11 +341,15 @@ else: return None - def process_statement_node(self, node): + def process_statement_node(self, node, is_lambda=False): "Process the given statement 'node'." self.reset_temp_counters() + + if is_lambda: + self.result_target_name = "__result" + return CommonModule.process_statement_node(self, node) def process_structure_node(self, n): @@ -912,7 +916,9 @@ # Produce the body and any additional return statement. - expr = self.process_statement_node(n.code) or \ + is_lambda = isinstance(n, compiler.ast.Lambda) + + expr = self.process_statement_node(n.code, is_lambda) or \ self.in_method() and \ function_name.rsplit(".", 1)[-1] == "__init__" and \ TrResolvedNameRef("self", self.importer.function_locals[function_name]["self"]) or \