From 29c8c6bbf35ee8caefeda32bfbef4cd6502e77a4 Mon Sep 17 00:00:00 2001 From: Daco Harkes Date: Wed, 14 Jan 2026 00:34:03 -0800 Subject: [PATCH] [dart2js] Fix extension methods in `record_use` Apply a workaround for dropping the receiver. This makes the behavior consistent with the VM. Closes: https://github.com/dart-lang/native/issues/2926 We should find a better solution for extension methods that also records the name of the extension and the type its on and the original method name. This will be addressed later. Bug: https://github.com/dart-lang/native/issues/2948 Change-Id: Iaa1f6afb82e4a70ed7af8e8ae4bbf92c4776637e Cq-Include-Trybots: luci.dart.try:pkg-linux-debug-try,pkg-linux-release-arm64-try,pkg-linux-release-try,pkg-mac-release-arm64-try,pkg-mac-release-try,pkg-win-release-arm64-try,pkg-win-release-try,dart2js-linux-chrome-try,dart2js-unit-linux-x64-release-try,dart2wasm-linux-jscm-chrome-try,dart2wasm-linux-optimized-jsc-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/472540 Reviewed-by: Nate Biggs --- pkg/compiler/lib/src/ssa/codegen.dart | 13 +++++++++++-- pkg/compiler/test/record_use/record_use_test.dart | 3 --- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/pkg/compiler/lib/src/ssa/codegen.dart b/pkg/compiler/lib/src/ssa/codegen.dart index ca09f13abe9..143d84d01e4 100644 --- a/pkg/compiler/lib/src/ssa/codegen.dart +++ b/pkg/compiler/lib/src/ssa/codegen.dart @@ -5,6 +5,8 @@ import 'dart:collection' show Queue; import 'dart:io'; +// ignore: implementation_imports +import 'package:front_end/src/api_prototype/lowering_predicates.dart'; // ignore: implementation_imports import 'package:front_end/src/api_unstable/dart2js.dart' show Link, relativizeUri; @@ -2407,14 +2409,21 @@ class SsaCodeGenerator implements HVisitor, HBlockInformationVisitor { record_use.Location? location = _recordUseLocation(sourceInformation); + final name = element.name!; + // TODO(https://github.com/dart-lang/native/issues/2948): Record the name of + // the extension instead of the desugared name. + final isExtensionMethod = hasUnnamedExtensionNamePrefix(name); return RecordedCallWithArguments( identifier: RecordedIdentifier( - name: element.name!, + name: name, parent: element.enclosingClass?.name, uri: relativizeUri(Uri.base, uri, Platform.isWindows), ), location: location, - positionalArguments: arguments.map(_findConstant).toList(), + positionalArguments: arguments + .skip(isExtensionMethod ? 1 : 0) + .map(_findConstant) + .toList(), ); } diff --git a/pkg/compiler/test/record_use/record_use_test.dart b/pkg/compiler/test/record_use/record_use_test.dart index 01dd09d44a2..88fe59502ae 100644 --- a/pkg/compiler/test/record_use/record_use_test.dart +++ b/pkg/compiler/test/record_use/record_use_test.dart @@ -142,7 +142,4 @@ const dart2jsNotSupported = { 'named_both.dart', 'named_optional.dart', 'named_required.dart', - // Extension methods are broken. - // https://github.com/dart-lang/native/issues/2926 - 'extension.dart', };