[CFE] Fix name for dill extension builderes
If - for instance - reporting an error on a duplicate extensions with
the same name where (at least) one was from dill (and thus a dill
builder) we'd use the encoded name (e.g. `ExtensionName|get#actualName`)
instead of `actualName`, meaning that when we - as context - tries to
give a good error message, but creates a squiggly that's to long,
maybe saying something like
```
org-dartlang-test:///lib1.dart:2:14: Context: This is one of the extension members.
String get onObject => "object #1";
^^^^^^^^^^^^^^^^^^^^^
```
This CL fixes it by giving the expected name for
DillExtensionMemberBuilders.
Change-Id: I02ba460fb8ac8dbc081fdca485058608ae16e04f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/205265
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
diff --git a/pkg/front_end/lib/src/fasta/dill/dill_extension_member_builder.dart b/pkg/front_end/lib/src/fasta/dill/dill_extension_member_builder.dart
index d12400f..07a6d6a 100644
--- a/pkg/front_end/lib/src/fasta/dill/dill_extension_member_builder.dart
+++ b/pkg/front_end/lib/src/fasta/dill/dill_extension_member_builder.dart
@@ -22,6 +22,9 @@
bool get isExternal => member.isExternal;
@override
+ String get name => _descriptor.name.text;
+
+ @override
ProcedureKind get kind {
switch (_descriptor.kind) {
case ExtensionMemberKind.Method:
diff --git a/pkg/front_end/test/incremental_suite.dart b/pkg/front_end/test/incremental_suite.dart
index dbb1cf7..6efa1ec 100644
--- a/pkg/front_end/test/incremental_suite.dart
+++ b/pkg/front_end/test/incremental_suite.dart
@@ -440,6 +440,8 @@
}
int worldNum = 0;
+ // TODO: When needed, we can do this for warnings too.
+ List<Set<String>> worldErrors = [];
for (YamlMap world in worlds) {
worldNum++;
print("----------------");
@@ -891,6 +893,18 @@
}
List<int> incrementalSerializationBytes = serializationResult.output;
+ worldErrors.add(formattedErrors.toSet());
+ assert(worldErrors.length == worldNum);
+ if (world["expectSameErrorsAsWorld"] != null) {
+ int expectSameErrorsAsWorld = world["expectSameErrorsAsWorld"];
+ checkErrorsAndWarnings(
+ worldErrors[expectSameErrorsAsWorld - 1],
+ formattedErrors,
+ {},
+ {},
+ );
+ }
+
Set<String> prevFormattedErrors = formattedErrors.toSet();
Set<String> prevFormattedWarnings = formattedWarnings.toSet();
diff --git a/pkg/front_end/testcases/incremental/extension_prefix_double_import_then_conflict.yaml b/pkg/front_end/testcases/incremental/extension_prefix_double_import_then_conflict.yaml
new file mode 100644
index 0000000..21d2963
--- /dev/null
+++ b/pkg/front_end/testcases/incremental/extension_prefix_double_import_then_conflict.yaml
@@ -0,0 +1,62 @@
+# Copyright (c) 2019, 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.md file.
+
+# This basically first compiles
+# tests/language_2/extension_methods/static_extension_prefix_double_import_test.dart
+# and then compiles
+# tests/language_2/extension_methods/static_extension_prefix_import_conflict_test.dart
+# as this has produced a wrong squigly-length on an error.
+
+type: newworld
+worlds:
+ - entry: main.dart
+ errors: true
+ sources:
+ main.dart: |
+ import "lib1.dart";
+ import "lib2.dart" as p;
+ main() {
+ Object o = 1;
+ o.onObject;
+ }
+ lib1.dart: |
+ extension OnObject on Object {
+ String get onObject => "object #1";
+ }
+ lib2.dart: |
+ extension AlsoOnObject on Object {
+ String get onObject => "object #2";
+ }
+ expectedLibraryCount: 3
+ - entry: main.dart
+ worldType: updated
+ expectInitializeFromDill: false
+ errors: false
+ invalidate:
+ - main.dart
+ sources:
+ main.dart: |
+ import "lib1.dart";
+ import "lib1.dart" as p;
+ main() {
+ Object o = 1;
+ o.onObject;
+ }
+ expectedLibraryCount: 2
+ - entry: main.dart
+ worldType: updated
+ expectInitializeFromDill: false
+ errors: true
+ expectSameErrorsAsWorld: 1
+ invalidate:
+ - main.dart
+ sources:
+ main.dart: |
+ import "lib1.dart";
+ import "lib2.dart" as p;
+ main() {
+ Object o = 1;
+ o.onObject;
+ }
+ expectedLibraryCount: 3
diff --git a/pkg/front_end/testcases/incremental/extension_prefix_double_import_then_conflict.yaml.world.1.expect b/pkg/front_end/testcases/incremental/extension_prefix_double_import_then_conflict.yaml.world.1.expect
new file mode 100644
index 0000000..fa77b0e
--- /dev/null
+++ b/pkg/front_end/testcases/incremental/extension_prefix_double_import_then_conflict.yaml.world.1.expect
@@ -0,0 +1,42 @@
+main = main::main;
+library from "org-dartlang-test:///lib1.dart" as lib1 {
+
+ extension OnObject on dart.core::Object* {
+ get onObject = lib1::OnObject|get#onObject;
+ }
+ static method OnObject|get#onObject(lowered final dart.core::Object* #this) → dart.core::String*
+ return "object #1";
+}
+library from "org-dartlang-test:///lib2.dart" as lib2 {
+
+ extension AlsoOnObject on dart.core::Object* {
+ get onObject = lib2::AlsoOnObject|get#onObject;
+ }
+ static method AlsoOnObject|get#onObject(lowered final dart.core::Object* #this) → dart.core::String*
+ return "object #2";
+}
+library from "org-dartlang-test:///main.dart" as main {
+//
+// Problems in library:
+//
+// org-dartlang-test:///main.dart:5:5: Error: The property 'onObject' is defined in multiple extensions for 'Object' and neither is more specific.
+// - 'Object' is from 'dart:core'.
+// Try using an explicit extension application of the wanted extension or hiding unwanted extensions from scope.
+// o.onObject;
+// ^^^^^^^^
+// org-dartlang-test:///lib1.dart:2:14: Context: This is one of the extension members.
+// String get onObject => "object #1";
+// ^^^^^^^^
+// org-dartlang-test:///lib2.dart:2:14: Context: This is one of the extension members.
+// String get onObject => "object #2";
+// ^^^^^^^^
+//
+
+ import "org-dartlang-test:///lib1.dart";
+ import "org-dartlang-test:///lib2.dart" as p;
+
+ static method main() → dynamic {
+ dart.core::Object* o = 1;
+ invalid-expression "org-dartlang-test:///main.dart:5:5: Error: The property 'onObject' is defined in multiple extensions for 'Object' and neither is more specific.\n - 'Object' is from 'dart:core'.\nTry using an explicit extension application of the wanted extension or hiding unwanted extensions from scope.\n o.onObject;\n ^^^^^^^^";
+ }
+}
diff --git a/pkg/front_end/testcases/incremental/extension_prefix_double_import_then_conflict.yaml.world.2.expect b/pkg/front_end/testcases/incremental/extension_prefix_double_import_then_conflict.yaml.world.2.expect
new file mode 100644
index 0000000..55a319c
--- /dev/null
+++ b/pkg/front_end/testcases/incremental/extension_prefix_double_import_then_conflict.yaml.world.2.expect
@@ -0,0 +1,19 @@
+main = main::main;
+library from "org-dartlang-test:///lib1.dart" as lib1 {
+
+ extension OnObject on dart.core::Object* {
+ get onObject = lib1::OnObject|get#onObject;
+ }
+ static method OnObject|get#onObject(lowered final dart.core::Object* #this) → dart.core::String*
+ return "object #1";
+}
+library from "org-dartlang-test:///main.dart" as main {
+
+ import "org-dartlang-test:///lib1.dart";
+ import "org-dartlang-test:///lib1.dart" as p;
+
+ static method main() → dynamic {
+ dart.core::Object* o = 1;
+ lib1::OnObject|get#onObject(o);
+ }
+}
diff --git a/pkg/front_end/testcases/incremental/extension_prefix_double_import_then_conflict.yaml.world.3.expect b/pkg/front_end/testcases/incremental/extension_prefix_double_import_then_conflict.yaml.world.3.expect
new file mode 100644
index 0000000..fa77b0e
--- /dev/null
+++ b/pkg/front_end/testcases/incremental/extension_prefix_double_import_then_conflict.yaml.world.3.expect
@@ -0,0 +1,42 @@
+main = main::main;
+library from "org-dartlang-test:///lib1.dart" as lib1 {
+
+ extension OnObject on dart.core::Object* {
+ get onObject = lib1::OnObject|get#onObject;
+ }
+ static method OnObject|get#onObject(lowered final dart.core::Object* #this) → dart.core::String*
+ return "object #1";
+}
+library from "org-dartlang-test:///lib2.dart" as lib2 {
+
+ extension AlsoOnObject on dart.core::Object* {
+ get onObject = lib2::AlsoOnObject|get#onObject;
+ }
+ static method AlsoOnObject|get#onObject(lowered final dart.core::Object* #this) → dart.core::String*
+ return "object #2";
+}
+library from "org-dartlang-test:///main.dart" as main {
+//
+// Problems in library:
+//
+// org-dartlang-test:///main.dart:5:5: Error: The property 'onObject' is defined in multiple extensions for 'Object' and neither is more specific.
+// - 'Object' is from 'dart:core'.
+// Try using an explicit extension application of the wanted extension or hiding unwanted extensions from scope.
+// o.onObject;
+// ^^^^^^^^
+// org-dartlang-test:///lib1.dart:2:14: Context: This is one of the extension members.
+// String get onObject => "object #1";
+// ^^^^^^^^
+// org-dartlang-test:///lib2.dart:2:14: Context: This is one of the extension members.
+// String get onObject => "object #2";
+// ^^^^^^^^
+//
+
+ import "org-dartlang-test:///lib1.dart";
+ import "org-dartlang-test:///lib2.dart" as p;
+
+ static method main() → dynamic {
+ dart.core::Object* o = 1;
+ invalid-expression "org-dartlang-test:///main.dart:5:5: Error: The property 'onObject' is defined in multiple extensions for 'Object' and neither is more specific.\n - 'Object' is from 'dart:core'.\nTry using an explicit extension application of the wanted extension or hiding unwanted extensions from scope.\n o.onObject;\n ^^^^^^^^";
+ }
+}