From 8028bd03fbf6a6c909b3403c281d0e848a0aa6ae Mon Sep 17 00:00:00 2001 From: Erik Ernst Date: Sat, 9 May 2026 07:13:11 -0700 Subject: [PATCH] Resolve test failures with web configurations This CL adds code such that web compilers can recognize that `Let` nodes can have a non-temporary variable as parameter. Before this CL, ddc configurations fail in many anonymous method tests because the given explicitly declared parameter isn't made available to the body of the anonymous method. Bug: https://github.com/dart-lang/sdk/issues/63184 Change-Id: I308c89e91e3856a06fa8f003d213cda0d93ae261 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/498060 Reviewed-by: Nicholas Shahan Commit-Queue: Erik Ernst --- pkg/dev_compiler/lib/src/kernel/compiler.dart | 6 ++++++ pkg/dev_compiler/lib/src/kernel/compiler_new.dart | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/pkg/dev_compiler/lib/src/kernel/compiler.dart b/pkg/dev_compiler/lib/src/kernel/compiler.dart index 721f433a732..ca43d5a9dbf 100644 --- a/pkg/dev_compiler/lib/src/kernel/compiler.dart +++ b/pkg/dev_compiler/lib/src/kernel/compiler.dart @@ -8065,6 +8065,12 @@ class ProgramCompiler extends ComputeOnceConstantVisitor var init = _visitExpression(v.initializer!); var body = _visitExpression(node.body); var temp = _tempVariables.remove(v); + // TODO(eernst): Remove the following `if` if anonymous-methods is rejected. + // Otherwise, revise this method to be more readable. + // See https://github.com/dart-lang/language/issues/260. + if (temp == null && !_isTemporaryVariable(v)) { + temp = _emitVariableRef(v); + } if (temp != null) { if (_letVariables != null) { init = js_ast.Assignment(temp, init); diff --git a/pkg/dev_compiler/lib/src/kernel/compiler_new.dart b/pkg/dev_compiler/lib/src/kernel/compiler_new.dart index a19b2c5c526..922e363bfbe 100644 --- a/pkg/dev_compiler/lib/src/kernel/compiler_new.dart +++ b/pkg/dev_compiler/lib/src/kernel/compiler_new.dart @@ -8938,6 +8938,12 @@ class LibraryCompiler extends ComputeOnceConstantVisitor var init = _visitExpression(v.initializer!); var body = _visitExpression(node.body); var temp = _tempVariables.remove(v); + // TODO(eernst): Remove the following `if` if anonymous-methods is rejected. + // Otherwise, revise this method to be more readable. + // See https://github.com/dart-lang/language/issues/260. + if (temp == null && !_isTemporaryVariable(v)) { + temp = _emitVariableRef(v); + } if (temp != null) { if (_letVariables != null) { init = js_ast.Assignment(temp, init);