[dart2wasm] Compare named argument names by equality instead of identity

This fixes #60059 when `--minify` is not used.

With minification we expect that runtime and const symbols won't be
equal or identical, even when the symbol names are the same.

Issue: https://github.com/dart-lang/sdk/issues/60059
Change-Id: Id6560558e2bd00cd9bef1f0026e2bd92a74d82fc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/414783
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
This commit is contained in:
Ömer Ağacan
2025-03-25 08:05:54 -07:00
committed by Commit Queue
parent caa192d24c
commit 27d2904b0a
2 changed files with 37 additions and 3 deletions
@@ -5,15 +5,24 @@
part of "core_patch.dart";
/// Finds a named parameter in a named parameter list passed to a dynamic
/// forwarder and returns the index of the value of that named parameter.
/// Returns `null` if the name is not in the list.
/// forwarder or `Function.apply` and returns the index of the value of that
/// named parameter. Returns `null` if the name is not in the list.
@pragma("wasm:entry-point")
int? _getNamedParameterIndex(
WasmArray<Object?> namedArguments,
Symbol paramName,
) {
for (int i = 0; i < namedArguments.length; i += 2) {
if (identical(namedArguments[i], paramName)) {
// `Symbol.==` does not check identity so we have a fast path here checking
// identities.
//
// We can't check just identities as the symbols in the list may not be
// constants in `Function.apply`.
//
// Also, `paramName` will always be a constant, so with `--minify` it can
// only be equal to a symbol in the list if it's also identical to it.
if (identical(namedArguments[i], paramName) ||
(!minify && unsafeCast<Symbol>(namedArguments[i]) == paramName)) {
return i + 1;
}
}
@@ -0,0 +1,25 @@
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// dart2wasmOptions=--extra-compiler-option=--minify
import 'package:expect/expect.dart';
void f({int a = 0}) {
Expect.equals(123, a);
}
bool get runtimeTrue => int.parse('1') == 1;
void main() {
// With minification, non-const symbols won't be identical or equal to the
// const symbols, so `Symbol('a')` here won't match `a` in the `f`'s named
// parameters and `Function.apply` will throw an error.
Expect.throws<NoSuchMethodError>(
() => Function.apply((runtimeTrue ? f : (() {})), [], {Symbol('a'): 123}),
);
// `const` symbols will work as before.
Function.apply((runtimeTrue ? f : (() {})), [], {#a: 123});
}