[cfe] Handle duplicates in augmentation libraries
Change-Id: I6200ffa7e3b2b68dbda2233f8bd3da7c76d7438a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/259360
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
diff --git a/pkg/front_end/lib/src/fasta/scope.dart b/pkg/front_end/lib/src/fasta/scope.dart
index 4f6834f..3c0292e 100644
--- a/pkg/front_end/lib/src/fasta/scope.dart
+++ b/pkg/front_end/lib/src/fasta/scope.dart
@@ -1369,13 +1369,24 @@
}
void _addAugmentationScope(T parentBuilder, Scope scope) {
+ // TODO(johnniwinther): Use `scope.filteredNameIterator` instead of
+ // `scope.forEachLocalMember`/`scope.forEachLocalSetter`.
+
// Include all augmentation scope members to the origin scope.
scope.forEachLocalMember((String name, Builder member) {
+ // In case of duplicates we use the first declaration.
+ while (member.isDuplicate) {
+ member = member.next!;
+ }
_addBuilderToMergedScope(parentBuilder, name, member,
_originScope.lookupLocalMember(name, setter: false),
setter: false);
});
scope.forEachLocalSetter((String name, Builder member) {
+ // In case of duplicates we use the first declaration.
+ while (member.isDuplicate) {
+ member = member.next!;
+ }
_addBuilderToMergedScope(parentBuilder, name, member,
_originScope.lookupLocalMember(name, setter: true),
setter: true);
diff --git a/pkg/front_end/testcases/general/multiple_class_patches/libraries.json b/pkg/front_end/testcases/general/multiple_class_patches/libraries.json
new file mode 100644
index 0000000..8621f1d
--- /dev/null
+++ b/pkg/front_end/testcases/general/multiple_class_patches/libraries.json
@@ -0,0 +1,13 @@
+{
+ "none": {
+ "libraries": {
+ "test": {
+ "patches": [
+ "patch_lib1.dart",
+ "patch_lib2.dart"
+ ],
+ "uri": "origin_lib.dart"
+ }
+ }
+ }
+}
diff --git a/pkg/front_end/testcases/general/multiple_class_patches/main.dart b/pkg/front_end/testcases/general/multiple_class_patches/main.dart
new file mode 100644
index 0000000..bfca532
--- /dev/null
+++ b/pkg/front_end/testcases/general/multiple_class_patches/main.dart
@@ -0,0 +1,18 @@
+// Copyright (c) 2022, 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.
+
+import 'dart:test';
+
+main() {
+ Class c = new Class();
+ expect(42, c.method1());
+ expect(87, c.method2());
+ expect(123, c.method3());
+}
+
+expect(expected, actual) {
+ if (expected != actual) {
+ throw 'Expected $expected, actual $actual';
+ }
+}
diff --git a/pkg/front_end/testcases/general/multiple_class_patches/main.dart.textual_outline.expect b/pkg/front_end/testcases/general/multiple_class_patches/main.dart.textual_outline.expect
new file mode 100644
index 0000000..a6150ab2
--- /dev/null
+++ b/pkg/front_end/testcases/general/multiple_class_patches/main.dart.textual_outline.expect
@@ -0,0 +1,4 @@
+import 'dart:test';
+
+main() {}
+expect(expected, actual) {}
diff --git a/pkg/front_end/testcases/general/multiple_class_patches/main.dart.textual_outline_modelled.expect b/pkg/front_end/testcases/general/multiple_class_patches/main.dart.textual_outline_modelled.expect
new file mode 100644
index 0000000..e14d79b
--- /dev/null
+++ b/pkg/front_end/testcases/general/multiple_class_patches/main.dart.textual_outline_modelled.expect
@@ -0,0 +1,4 @@
+import 'dart:test';
+
+expect(expected, actual) {}
+main() {}
diff --git a/pkg/front_end/testcases/general/multiple_class_patches/main.dart.weak.expect b/pkg/front_end/testcases/general/multiple_class_patches/main.dart.weak.expect
new file mode 100644
index 0000000..0f8a5da
--- /dev/null
+++ b/pkg/front_end/testcases/general/multiple_class_patches/main.dart.weak.expect
@@ -0,0 +1,66 @@
+library /*isNonNullableByDefault*/;
+import self as self;
+import "dart:test" as test;
+import "dart:core" as core;
+
+import "dart:test";
+
+static method main() → dynamic {
+ test::Class c = new test::Class::•();
+ self::expect(42, c.{test::Class::method1}(){() → core::int});
+ self::expect(87, c.{test::Class::method2}(){() → core::int});
+ self::expect(123, c.{test::Class::method3}(){() → core::int});
+}
+static method expect(dynamic expected, dynamic actual) → dynamic {
+ if(!(expected =={core::Object::==}{(core::Object) → core::bool} actual)) {
+ throw "Expected ${expected}, actual ${actual}";
+ }
+}
+
+library /*isNonNullableByDefault*/;
+//
+// Problems in library:
+//
+// pkg/front_end/testcases/general/multiple_class_patches/patch_lib2.dart:9:7: Error: 'Class' is already declared in this scope.
+// class Class {
+// ^^^^^
+// pkg/front_end/testcases/general/multiple_class_patches/patch_lib1.dart:9:7: Context: Previous declaration of 'Class'.
+// class Class {
+// ^^^^^
+//
+import self as test;
+import "dart:_internal" as _in;
+import "dart:core" as core;
+
+import "dart:_internal";
+import "dart:_internal";
+
+@#C1
+class Class#1#1 extends core::Object { // from org-dartlang-testcase:///patch_lib2.dart
+ synthetic constructor •() → test::Class#1#1
+ : super core::Object::•()
+ ;
+ @#C1
+ method method2() → core::int
+ return 87;
+ @#C1
+ method method3() → core::int
+ return 123;
+}
+@#C1
+class Class extends core::Object {
+ synthetic constructor •() → test::Class
+ : super core::Object::•()
+ ;
+ @#C1
+ method /* from org-dartlang-testcase:///patch_lib1.dart */ method1() → core::int
+ return 42;
+ external method method2() → core::int;
+ @#C1
+ method /* from org-dartlang-testcase:///patch_lib1.dart */ method3() → core::int
+ return 321;
+}
+
+constants {
+ #C1 = _in::_Patch {}
+}
diff --git a/pkg/front_end/testcases/general/multiple_class_patches/main.dart.weak.modular.expect b/pkg/front_end/testcases/general/multiple_class_patches/main.dart.weak.modular.expect
new file mode 100644
index 0000000..0f8a5da
--- /dev/null
+++ b/pkg/front_end/testcases/general/multiple_class_patches/main.dart.weak.modular.expect
@@ -0,0 +1,66 @@
+library /*isNonNullableByDefault*/;
+import self as self;
+import "dart:test" as test;
+import "dart:core" as core;
+
+import "dart:test";
+
+static method main() → dynamic {
+ test::Class c = new test::Class::•();
+ self::expect(42, c.{test::Class::method1}(){() → core::int});
+ self::expect(87, c.{test::Class::method2}(){() → core::int});
+ self::expect(123, c.{test::Class::method3}(){() → core::int});
+}
+static method expect(dynamic expected, dynamic actual) → dynamic {
+ if(!(expected =={core::Object::==}{(core::Object) → core::bool} actual)) {
+ throw "Expected ${expected}, actual ${actual}";
+ }
+}
+
+library /*isNonNullableByDefault*/;
+//
+// Problems in library:
+//
+// pkg/front_end/testcases/general/multiple_class_patches/patch_lib2.dart:9:7: Error: 'Class' is already declared in this scope.
+// class Class {
+// ^^^^^
+// pkg/front_end/testcases/general/multiple_class_patches/patch_lib1.dart:9:7: Context: Previous declaration of 'Class'.
+// class Class {
+// ^^^^^
+//
+import self as test;
+import "dart:_internal" as _in;
+import "dart:core" as core;
+
+import "dart:_internal";
+import "dart:_internal";
+
+@#C1
+class Class#1#1 extends core::Object { // from org-dartlang-testcase:///patch_lib2.dart
+ synthetic constructor •() → test::Class#1#1
+ : super core::Object::•()
+ ;
+ @#C1
+ method method2() → core::int
+ return 87;
+ @#C1
+ method method3() → core::int
+ return 123;
+}
+@#C1
+class Class extends core::Object {
+ synthetic constructor •() → test::Class
+ : super core::Object::•()
+ ;
+ @#C1
+ method /* from org-dartlang-testcase:///patch_lib1.dart */ method1() → core::int
+ return 42;
+ external method method2() → core::int;
+ @#C1
+ method /* from org-dartlang-testcase:///patch_lib1.dart */ method3() → core::int
+ return 321;
+}
+
+constants {
+ #C1 = _in::_Patch {}
+}
diff --git a/pkg/front_end/testcases/general/multiple_class_patches/main.dart.weak.outline.expect b/pkg/front_end/testcases/general/multiple_class_patches/main.dart.weak.outline.expect
new file mode 100644
index 0000000..769015a
--- /dev/null
+++ b/pkg/front_end/testcases/general/multiple_class_patches/main.dart.weak.outline.expect
@@ -0,0 +1,59 @@
+library /*isNonNullableByDefault*/;
+import self as self;
+
+import "dart:test";
+
+static method main() → dynamic
+ ;
+static method expect(dynamic expected, dynamic actual) → dynamic
+ ;
+
+library /*isNonNullableByDefault*/;
+//
+// Problems in library:
+//
+// pkg/front_end/testcases/general/multiple_class_patches/patch_lib2.dart:9:7: Error: 'Class' is already declared in this scope.
+// class Class {
+// ^^^^^
+// pkg/front_end/testcases/general/multiple_class_patches/patch_lib1.dart:9:7: Context: Previous declaration of 'Class'.
+// class Class {
+// ^^^^^
+//
+import self as self2;
+import "dart:_internal" as _in;
+import "dart:core" as core;
+
+import "dart:_internal";
+import "dart:_internal";
+
+@_in::patch
+class Class#1#1 extends core::Object { // from org-dartlang-testcase:///patch_lib2.dart
+ synthetic constructor •() → self2::Class#1#1
+ ;
+ @_in::patch
+ method method2() → core::int
+ ;
+ @_in::patch
+ method method3() → core::int
+ ;
+}
+@_in::patch
+class Class extends core::Object {
+ synthetic constructor •() → self2::Class
+ ;
+ @_in::patch
+ external method method1() → core::int;
+ external method method2() → core::int;
+ @_in::patch
+ external method method3() → core::int;
+}
+
+
+Extra constant evaluation status:
+Evaluated: StaticGet @ org-dartlang-testcase:///patch_lib2.dart:8:2 -> InstanceConstant(const _Patch{})
+Evaluated: StaticGet @ org-dartlang-testcase:///patch_lib2.dart:10:4 -> InstanceConstant(const _Patch{})
+Evaluated: StaticGet @ org-dartlang-testcase:///patch_lib2.dart:13:4 -> InstanceConstant(const _Patch{})
+Evaluated: StaticGet @ org-dartlang-testcase:///origin_lib.dart:7:23 -> InstanceConstant(const _Patch{})
+Evaluated: StaticGet @ org-dartlang-testcase:///origin_lib.dart:8:20 -> InstanceConstant(const _Patch{})
+Evaluated: StaticGet @ (unknown position in org-dartlang-testcase:///origin_lib.dart) -> InstanceConstant(const _Patch{})
+Extra constant evaluation: evaluated: 6, effectively constant: 6
diff --git a/pkg/front_end/testcases/general/multiple_class_patches/main.dart.weak.transformed.expect b/pkg/front_end/testcases/general/multiple_class_patches/main.dart.weak.transformed.expect
new file mode 100644
index 0000000..0f8a5da
--- /dev/null
+++ b/pkg/front_end/testcases/general/multiple_class_patches/main.dart.weak.transformed.expect
@@ -0,0 +1,66 @@
+library /*isNonNullableByDefault*/;
+import self as self;
+import "dart:test" as test;
+import "dart:core" as core;
+
+import "dart:test";
+
+static method main() → dynamic {
+ test::Class c = new test::Class::•();
+ self::expect(42, c.{test::Class::method1}(){() → core::int});
+ self::expect(87, c.{test::Class::method2}(){() → core::int});
+ self::expect(123, c.{test::Class::method3}(){() → core::int});
+}
+static method expect(dynamic expected, dynamic actual) → dynamic {
+ if(!(expected =={core::Object::==}{(core::Object) → core::bool} actual)) {
+ throw "Expected ${expected}, actual ${actual}";
+ }
+}
+
+library /*isNonNullableByDefault*/;
+//
+// Problems in library:
+//
+// pkg/front_end/testcases/general/multiple_class_patches/patch_lib2.dart:9:7: Error: 'Class' is already declared in this scope.
+// class Class {
+// ^^^^^
+// pkg/front_end/testcases/general/multiple_class_patches/patch_lib1.dart:9:7: Context: Previous declaration of 'Class'.
+// class Class {
+// ^^^^^
+//
+import self as test;
+import "dart:_internal" as _in;
+import "dart:core" as core;
+
+import "dart:_internal";
+import "dart:_internal";
+
+@#C1
+class Class#1#1 extends core::Object { // from org-dartlang-testcase:///patch_lib2.dart
+ synthetic constructor •() → test::Class#1#1
+ : super core::Object::•()
+ ;
+ @#C1
+ method method2() → core::int
+ return 87;
+ @#C1
+ method method3() → core::int
+ return 123;
+}
+@#C1
+class Class extends core::Object {
+ synthetic constructor •() → test::Class
+ : super core::Object::•()
+ ;
+ @#C1
+ method /* from org-dartlang-testcase:///patch_lib1.dart */ method1() → core::int
+ return 42;
+ external method method2() → core::int;
+ @#C1
+ method /* from org-dartlang-testcase:///patch_lib1.dart */ method3() → core::int
+ return 321;
+}
+
+constants {
+ #C1 = _in::_Patch {}
+}
diff --git a/pkg/front_end/testcases/general/multiple_class_patches/origin_lib.dart b/pkg/front_end/testcases/general/multiple_class_patches/origin_lib.dart
new file mode 100644
index 0000000..cccced9
--- /dev/null
+++ b/pkg/front_end/testcases/general/multiple_class_patches/origin_lib.dart
@@ -0,0 +1,9 @@
+// Copyright (c) 2022, 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.
+
+class Class {
+ external int method1();
+ external int method2();
+ external int method3();
+}
diff --git a/pkg/front_end/testcases/general/multiple_class_patches/patch_lib1.dart b/pkg/front_end/testcases/general/multiple_class_patches/patch_lib1.dart
new file mode 100644
index 0000000..1220b53
--- /dev/null
+++ b/pkg/front_end/testcases/general/multiple_class_patches/patch_lib1.dart
@@ -0,0 +1,15 @@
+// Copyright (c) 2022, 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.
+
+// ignore: import_internal_library
+import 'dart:_internal';
+
+@patch
+class Class {
+ @patch
+ int method1() => 42;
+
+ @patch
+ int method3() => 321;
+}
diff --git a/pkg/front_end/testcases/general/multiple_class_patches/patch_lib2.dart b/pkg/front_end/testcases/general/multiple_class_patches/patch_lib2.dart
new file mode 100644
index 0000000..645e96a
--- /dev/null
+++ b/pkg/front_end/testcases/general/multiple_class_patches/patch_lib2.dart
@@ -0,0 +1,15 @@
+// Copyright (c) 2022, 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.
+
+// ignore: import_internal_library
+import 'dart:_internal';
+
+@patch
+class Class {
+ @patch
+ int method2() => 87;
+
+ @patch
+ int method3() => 123;
+}
diff --git a/pkg/front_end/testcases/macros/duplicate_augment.dart b/pkg/front_end/testcases/macros/duplicate_augment.dart
new file mode 100644
index 0000000..9f19520
--- /dev/null
+++ b/pkg/front_end/testcases/macros/duplicate_augment.dart
@@ -0,0 +1,12 @@
+// Copyright (c) 2022, 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.
+
+import augment 'duplicate_augment_lib.dart';
+
+void augmentedTopLevelMethod() {}
+
+class AugmentedClass {
+ void augmentedInstanceMethod() {}
+ static void augmentedStaticMethod() {}
+}
\ No newline at end of file
diff --git a/pkg/front_end/testcases/macros/duplicate_augment.dart.strong.expect b/pkg/front_end/testcases/macros/duplicate_augment.dart.strong.expect
new file mode 100644
index 0000000..79663e1
--- /dev/null
+++ b/pkg/front_end/testcases/macros/duplicate_augment.dart.strong.expect
@@ -0,0 +1,48 @@
+library /*isNonNullableByDefault*/;
+//
+// Problems in library:
+//
+// pkg/front_end/testcases/macros/duplicate_augment_lib.dart:9:14: Error: 'augmentedTopLevelMethod' is already declared in this scope.
+// augment void augmentedTopLevelMethod() {
+// ^^^^^^^^^^^^^^^^^^^^^^^
+// pkg/front_end/testcases/macros/duplicate_augment_lib.dart:5:14: Context: Previous declaration of 'augmentedTopLevelMethod'.
+// augment void augmentedTopLevelMethod() {
+// ^^^^^^^^^^^^^^^^^^^^^^^
+//
+// pkg/front_end/testcases/macros/duplicate_augment_lib.dart:22:15: Error: 'AugmentedClass' is already declared in this scope.
+// augment class AugmentedClass {
+// ^^^^^^^^^^^^^^
+// pkg/front_end/testcases/macros/duplicate_augment_lib.dart:13:15: Context: Previous declaration of 'AugmentedClass'.
+// augment class AugmentedClass {
+// ^^^^^^^^^^^^^^
+//
+import self as self;
+import "dart:core" as core;
+
+import "org-dartlang-testcase:///duplicate_augment.dart";
+
+class AugmentedClass#1#1 extends core::Object { // from org-dartlang-testcase:///duplicate_augment_lib.dart
+ synthetic constructor •() → self::AugmentedClass#1#1
+ : super core::Object::•()
+ ;
+ method augmentedInstanceMethod() → void {
+ core::print("augmentedInstanceMethod#2");
+ }
+ static method augmentedStaticMethod() → void {
+ core::print("augmentedStaticMethod#2");
+ }
+}
+class AugmentedClass extends core::Object {
+ synthetic constructor •() → self::AugmentedClass
+ : super core::Object::•()
+ ;
+ method /* from org-dartlang-testcase:///duplicate_augment_lib.dart */ augmentedInstanceMethod() → void {
+ core::print("augmentedInstanceMethod#1");
+ }
+ static method /* from org-dartlang-testcase:///duplicate_augment_lib.dart */ augmentedStaticMethod() → void {
+ core::print("augmentedStaticMethod#1");
+ }
+}
+static method /* from org-dartlang-testcase:///duplicate_augment_lib.dart */ augmentedTopLevelMethod() → void {
+ core::print("augmentedTopLevelMethod#1");
+}
diff --git a/pkg/front_end/testcases/macros/duplicate_augment.dart.strong.transformed.expect b/pkg/front_end/testcases/macros/duplicate_augment.dart.strong.transformed.expect
new file mode 100644
index 0000000..79663e1
--- /dev/null
+++ b/pkg/front_end/testcases/macros/duplicate_augment.dart.strong.transformed.expect
@@ -0,0 +1,48 @@
+library /*isNonNullableByDefault*/;
+//
+// Problems in library:
+//
+// pkg/front_end/testcases/macros/duplicate_augment_lib.dart:9:14: Error: 'augmentedTopLevelMethod' is already declared in this scope.
+// augment void augmentedTopLevelMethod() {
+// ^^^^^^^^^^^^^^^^^^^^^^^
+// pkg/front_end/testcases/macros/duplicate_augment_lib.dart:5:14: Context: Previous declaration of 'augmentedTopLevelMethod'.
+// augment void augmentedTopLevelMethod() {
+// ^^^^^^^^^^^^^^^^^^^^^^^
+//
+// pkg/front_end/testcases/macros/duplicate_augment_lib.dart:22:15: Error: 'AugmentedClass' is already declared in this scope.
+// augment class AugmentedClass {
+// ^^^^^^^^^^^^^^
+// pkg/front_end/testcases/macros/duplicate_augment_lib.dart:13:15: Context: Previous declaration of 'AugmentedClass'.
+// augment class AugmentedClass {
+// ^^^^^^^^^^^^^^
+//
+import self as self;
+import "dart:core" as core;
+
+import "org-dartlang-testcase:///duplicate_augment.dart";
+
+class AugmentedClass#1#1 extends core::Object { // from org-dartlang-testcase:///duplicate_augment_lib.dart
+ synthetic constructor •() → self::AugmentedClass#1#1
+ : super core::Object::•()
+ ;
+ method augmentedInstanceMethod() → void {
+ core::print("augmentedInstanceMethod#2");
+ }
+ static method augmentedStaticMethod() → void {
+ core::print("augmentedStaticMethod#2");
+ }
+}
+class AugmentedClass extends core::Object {
+ synthetic constructor •() → self::AugmentedClass
+ : super core::Object::•()
+ ;
+ method /* from org-dartlang-testcase:///duplicate_augment_lib.dart */ augmentedInstanceMethod() → void {
+ core::print("augmentedInstanceMethod#1");
+ }
+ static method /* from org-dartlang-testcase:///duplicate_augment_lib.dart */ augmentedStaticMethod() → void {
+ core::print("augmentedStaticMethod#1");
+ }
+}
+static method /* from org-dartlang-testcase:///duplicate_augment_lib.dart */ augmentedTopLevelMethod() → void {
+ core::print("augmentedTopLevelMethod#1");
+}
diff --git a/pkg/front_end/testcases/macros/duplicate_augment.dart.textual_outline.expect b/pkg/front_end/testcases/macros/duplicate_augment.dart.textual_outline.expect
new file mode 100644
index 0000000..65489d0
--- /dev/null
+++ b/pkg/front_end/testcases/macros/duplicate_augment.dart.textual_outline.expect
@@ -0,0 +1,6 @@
+import augment 'duplicate_augment_lib.dart';
+void augmentedTopLevelMethod() {}
+class AugmentedClass {
+ void augmentedInstanceMethod() {}
+ static void augmentedStaticMethod() {}
+}
diff --git a/pkg/front_end/testcases/macros/duplicate_augment.dart.weak.expect b/pkg/front_end/testcases/macros/duplicate_augment.dart.weak.expect
new file mode 100644
index 0000000..79663e1
--- /dev/null
+++ b/pkg/front_end/testcases/macros/duplicate_augment.dart.weak.expect
@@ -0,0 +1,48 @@
+library /*isNonNullableByDefault*/;
+//
+// Problems in library:
+//
+// pkg/front_end/testcases/macros/duplicate_augment_lib.dart:9:14: Error: 'augmentedTopLevelMethod' is already declared in this scope.
+// augment void augmentedTopLevelMethod() {
+// ^^^^^^^^^^^^^^^^^^^^^^^
+// pkg/front_end/testcases/macros/duplicate_augment_lib.dart:5:14: Context: Previous declaration of 'augmentedTopLevelMethod'.
+// augment void augmentedTopLevelMethod() {
+// ^^^^^^^^^^^^^^^^^^^^^^^
+//
+// pkg/front_end/testcases/macros/duplicate_augment_lib.dart:22:15: Error: 'AugmentedClass' is already declared in this scope.
+// augment class AugmentedClass {
+// ^^^^^^^^^^^^^^
+// pkg/front_end/testcases/macros/duplicate_augment_lib.dart:13:15: Context: Previous declaration of 'AugmentedClass'.
+// augment class AugmentedClass {
+// ^^^^^^^^^^^^^^
+//
+import self as self;
+import "dart:core" as core;
+
+import "org-dartlang-testcase:///duplicate_augment.dart";
+
+class AugmentedClass#1#1 extends core::Object { // from org-dartlang-testcase:///duplicate_augment_lib.dart
+ synthetic constructor •() → self::AugmentedClass#1#1
+ : super core::Object::•()
+ ;
+ method augmentedInstanceMethod() → void {
+ core::print("augmentedInstanceMethod#2");
+ }
+ static method augmentedStaticMethod() → void {
+ core::print("augmentedStaticMethod#2");
+ }
+}
+class AugmentedClass extends core::Object {
+ synthetic constructor •() → self::AugmentedClass
+ : super core::Object::•()
+ ;
+ method /* from org-dartlang-testcase:///duplicate_augment_lib.dart */ augmentedInstanceMethod() → void {
+ core::print("augmentedInstanceMethod#1");
+ }
+ static method /* from org-dartlang-testcase:///duplicate_augment_lib.dart */ augmentedStaticMethod() → void {
+ core::print("augmentedStaticMethod#1");
+ }
+}
+static method /* from org-dartlang-testcase:///duplicate_augment_lib.dart */ augmentedTopLevelMethod() → void {
+ core::print("augmentedTopLevelMethod#1");
+}
diff --git a/pkg/front_end/testcases/macros/duplicate_augment.dart.weak.modular.expect b/pkg/front_end/testcases/macros/duplicate_augment.dart.weak.modular.expect
new file mode 100644
index 0000000..79663e1
--- /dev/null
+++ b/pkg/front_end/testcases/macros/duplicate_augment.dart.weak.modular.expect
@@ -0,0 +1,48 @@
+library /*isNonNullableByDefault*/;
+//
+// Problems in library:
+//
+// pkg/front_end/testcases/macros/duplicate_augment_lib.dart:9:14: Error: 'augmentedTopLevelMethod' is already declared in this scope.
+// augment void augmentedTopLevelMethod() {
+// ^^^^^^^^^^^^^^^^^^^^^^^
+// pkg/front_end/testcases/macros/duplicate_augment_lib.dart:5:14: Context: Previous declaration of 'augmentedTopLevelMethod'.
+// augment void augmentedTopLevelMethod() {
+// ^^^^^^^^^^^^^^^^^^^^^^^
+//
+// pkg/front_end/testcases/macros/duplicate_augment_lib.dart:22:15: Error: 'AugmentedClass' is already declared in this scope.
+// augment class AugmentedClass {
+// ^^^^^^^^^^^^^^
+// pkg/front_end/testcases/macros/duplicate_augment_lib.dart:13:15: Context: Previous declaration of 'AugmentedClass'.
+// augment class AugmentedClass {
+// ^^^^^^^^^^^^^^
+//
+import self as self;
+import "dart:core" as core;
+
+import "org-dartlang-testcase:///duplicate_augment.dart";
+
+class AugmentedClass#1#1 extends core::Object { // from org-dartlang-testcase:///duplicate_augment_lib.dart
+ synthetic constructor •() → self::AugmentedClass#1#1
+ : super core::Object::•()
+ ;
+ method augmentedInstanceMethod() → void {
+ core::print("augmentedInstanceMethod#2");
+ }
+ static method augmentedStaticMethod() → void {
+ core::print("augmentedStaticMethod#2");
+ }
+}
+class AugmentedClass extends core::Object {
+ synthetic constructor •() → self::AugmentedClass
+ : super core::Object::•()
+ ;
+ method /* from org-dartlang-testcase:///duplicate_augment_lib.dart */ augmentedInstanceMethod() → void {
+ core::print("augmentedInstanceMethod#1");
+ }
+ static method /* from org-dartlang-testcase:///duplicate_augment_lib.dart */ augmentedStaticMethod() → void {
+ core::print("augmentedStaticMethod#1");
+ }
+}
+static method /* from org-dartlang-testcase:///duplicate_augment_lib.dart */ augmentedTopLevelMethod() → void {
+ core::print("augmentedTopLevelMethod#1");
+}
diff --git a/pkg/front_end/testcases/macros/duplicate_augment.dart.weak.outline.expect b/pkg/front_end/testcases/macros/duplicate_augment.dart.weak.outline.expect
new file mode 100644
index 0000000..f133d5b
--- /dev/null
+++ b/pkg/front_end/testcases/macros/duplicate_augment.dart.weak.outline.expect
@@ -0,0 +1,41 @@
+library /*isNonNullableByDefault*/;
+//
+// Problems in library:
+//
+// pkg/front_end/testcases/macros/duplicate_augment_lib.dart:9:14: Error: 'augmentedTopLevelMethod' is already declared in this scope.
+// augment void augmentedTopLevelMethod() {
+// ^^^^^^^^^^^^^^^^^^^^^^^
+// pkg/front_end/testcases/macros/duplicate_augment_lib.dart:5:14: Context: Previous declaration of 'augmentedTopLevelMethod'.
+// augment void augmentedTopLevelMethod() {
+// ^^^^^^^^^^^^^^^^^^^^^^^
+//
+// pkg/front_end/testcases/macros/duplicate_augment_lib.dart:22:15: Error: 'AugmentedClass' is already declared in this scope.
+// augment class AugmentedClass {
+// ^^^^^^^^^^^^^^
+// pkg/front_end/testcases/macros/duplicate_augment_lib.dart:13:15: Context: Previous declaration of 'AugmentedClass'.
+// augment class AugmentedClass {
+// ^^^^^^^^^^^^^^
+//
+import self as self;
+import "dart:core" as core;
+
+import "org-dartlang-testcase:///duplicate_augment.dart";
+
+class AugmentedClass#1#1 extends core::Object { // from org-dartlang-testcase:///duplicate_augment_lib.dart
+ synthetic constructor •() → self::AugmentedClass#1#1
+ ;
+ method augmentedInstanceMethod() → void
+ ;
+ static method augmentedStaticMethod() → void
+ ;
+}
+class AugmentedClass extends core::Object {
+ synthetic constructor •() → self::AugmentedClass
+ ;
+ method augmentedInstanceMethod() → void
+ ;
+ static method augmentedStaticMethod() → void
+ ;
+}
+static method augmentedTopLevelMethod() → void
+ ;
diff --git a/pkg/front_end/testcases/macros/duplicate_augment.dart.weak.transformed.expect b/pkg/front_end/testcases/macros/duplicate_augment.dart.weak.transformed.expect
new file mode 100644
index 0000000..79663e1
--- /dev/null
+++ b/pkg/front_end/testcases/macros/duplicate_augment.dart.weak.transformed.expect
@@ -0,0 +1,48 @@
+library /*isNonNullableByDefault*/;
+//
+// Problems in library:
+//
+// pkg/front_end/testcases/macros/duplicate_augment_lib.dart:9:14: Error: 'augmentedTopLevelMethod' is already declared in this scope.
+// augment void augmentedTopLevelMethod() {
+// ^^^^^^^^^^^^^^^^^^^^^^^
+// pkg/front_end/testcases/macros/duplicate_augment_lib.dart:5:14: Context: Previous declaration of 'augmentedTopLevelMethod'.
+// augment void augmentedTopLevelMethod() {
+// ^^^^^^^^^^^^^^^^^^^^^^^
+//
+// pkg/front_end/testcases/macros/duplicate_augment_lib.dart:22:15: Error: 'AugmentedClass' is already declared in this scope.
+// augment class AugmentedClass {
+// ^^^^^^^^^^^^^^
+// pkg/front_end/testcases/macros/duplicate_augment_lib.dart:13:15: Context: Previous declaration of 'AugmentedClass'.
+// augment class AugmentedClass {
+// ^^^^^^^^^^^^^^
+//
+import self as self;
+import "dart:core" as core;
+
+import "org-dartlang-testcase:///duplicate_augment.dart";
+
+class AugmentedClass#1#1 extends core::Object { // from org-dartlang-testcase:///duplicate_augment_lib.dart
+ synthetic constructor •() → self::AugmentedClass#1#1
+ : super core::Object::•()
+ ;
+ method augmentedInstanceMethod() → void {
+ core::print("augmentedInstanceMethod#2");
+ }
+ static method augmentedStaticMethod() → void {
+ core::print("augmentedStaticMethod#2");
+ }
+}
+class AugmentedClass extends core::Object {
+ synthetic constructor •() → self::AugmentedClass
+ : super core::Object::•()
+ ;
+ method /* from org-dartlang-testcase:///duplicate_augment_lib.dart */ augmentedInstanceMethod() → void {
+ core::print("augmentedInstanceMethod#1");
+ }
+ static method /* from org-dartlang-testcase:///duplicate_augment_lib.dart */ augmentedStaticMethod() → void {
+ core::print("augmentedStaticMethod#1");
+ }
+}
+static method /* from org-dartlang-testcase:///duplicate_augment_lib.dart */ augmentedTopLevelMethod() → void {
+ core::print("augmentedTopLevelMethod#1");
+}
diff --git a/pkg/front_end/testcases/macros/duplicate_augment_lib.dart b/pkg/front_end/testcases/macros/duplicate_augment_lib.dart
new file mode 100644
index 0000000..6ab100d
--- /dev/null
+++ b/pkg/front_end/testcases/macros/duplicate_augment_lib.dart
@@ -0,0 +1,29 @@
+// Copyright (c) 2022, 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.
+
+augment void augmentedTopLevelMethod() {
+ print('augmentedTopLevelMethod#1');
+}
+
+augment void augmentedTopLevelMethod() {
+ print('augmentedTopLevelMethod#2');
+}
+
+augment class AugmentedClass {
+ augment void augmentedInstanceMethod() {
+ print('augmentedInstanceMethod#1');
+ }
+ augment static void augmentedStaticMethod() {
+ print('augmentedStaticMethod#1');
+ }
+}
+
+augment class AugmentedClass {
+ augment void augmentedInstanceMethod() {
+ print('augmentedInstanceMethod#2');
+ }
+ augment static void augmentedStaticMethod() {
+ print('augmentedStaticMethod#2');
+ }
+}
\ No newline at end of file
diff --git a/pkg/front_end/testcases/macros/multiple_augment_class.dart b/pkg/front_end/testcases/macros/multiple_augment_class.dart
new file mode 100644
index 0000000..68c153d
--- /dev/null
+++ b/pkg/front_end/testcases/macros/multiple_augment_class.dart
@@ -0,0 +1,25 @@
+// Copyright (c) 2022, 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.
+
+import augment 'multiple_augment_class_lib1.dart';
+import augment 'multiple_augment_class_lib2.dart';
+
+class Class {
+ external int method1();
+ external int method2();
+ external int method3();
+}
+
+main() {
+ Class c = new Class();
+ expect(42, c.method1());
+ expect(87, c.method2());
+ expect(123, c.method3());
+}
+
+expect(expected, actual) {
+ if (expected != actual) {
+ throw 'Expected $expected, actual $actual';
+ }
+}
diff --git a/pkg/front_end/testcases/macros/multiple_augment_class.dart.strong.expect b/pkg/front_end/testcases/macros/multiple_augment_class.dart.strong.expect
new file mode 100644
index 0000000..732d315
--- /dev/null
+++ b/pkg/front_end/testcases/macros/multiple_augment_class.dart.strong.expect
@@ -0,0 +1,29 @@
+library /*isNonNullableByDefault*/;
+import self as self;
+import "dart:core" as core;
+
+import "org-dartlang-testcase:///multiple_augment_class.dart";
+import "org-dartlang-testcase:///multiple_augment_class.dart";
+
+class Class extends core::Object {
+ synthetic constructor •() → self::Class
+ : super core::Object::•()
+ ;
+ method /* from org-dartlang-testcase:///multiple_augment_class_lib1.dart */ method1() → core::int
+ return 42;
+ method /* from org-dartlang-testcase:///multiple_augment_class_lib2.dart */ method2() → core::int
+ return 87;
+ method /* from org-dartlang-testcase:///multiple_augment_class_lib2.dart */ method3() → core::int
+ return 123;
+}
+static method main() → dynamic {
+ self::Class c = new self::Class::•();
+ self::expect(42, c.{self::Class::method1}(){() → core::int});
+ self::expect(87, c.{self::Class::method2}(){() → core::int});
+ self::expect(123, c.{self::Class::method3}(){() → core::int});
+}
+static method expect(dynamic expected, dynamic actual) → dynamic {
+ if(!(expected =={core::Object::==}{(core::Object) → core::bool} actual)) {
+ throw "Expected ${expected}, actual ${actual}";
+ }
+}
diff --git a/pkg/front_end/testcases/macros/multiple_augment_class.dart.strong.transformed.expect b/pkg/front_end/testcases/macros/multiple_augment_class.dart.strong.transformed.expect
new file mode 100644
index 0000000..732d315
--- /dev/null
+++ b/pkg/front_end/testcases/macros/multiple_augment_class.dart.strong.transformed.expect
@@ -0,0 +1,29 @@
+library /*isNonNullableByDefault*/;
+import self as self;
+import "dart:core" as core;
+
+import "org-dartlang-testcase:///multiple_augment_class.dart";
+import "org-dartlang-testcase:///multiple_augment_class.dart";
+
+class Class extends core::Object {
+ synthetic constructor •() → self::Class
+ : super core::Object::•()
+ ;
+ method /* from org-dartlang-testcase:///multiple_augment_class_lib1.dart */ method1() → core::int
+ return 42;
+ method /* from org-dartlang-testcase:///multiple_augment_class_lib2.dart */ method2() → core::int
+ return 87;
+ method /* from org-dartlang-testcase:///multiple_augment_class_lib2.dart */ method3() → core::int
+ return 123;
+}
+static method main() → dynamic {
+ self::Class c = new self::Class::•();
+ self::expect(42, c.{self::Class::method1}(){() → core::int});
+ self::expect(87, c.{self::Class::method2}(){() → core::int});
+ self::expect(123, c.{self::Class::method3}(){() → core::int});
+}
+static method expect(dynamic expected, dynamic actual) → dynamic {
+ if(!(expected =={core::Object::==}{(core::Object) → core::bool} actual)) {
+ throw "Expected ${expected}, actual ${actual}";
+ }
+}
diff --git a/pkg/front_end/testcases/macros/multiple_augment_class.dart.textual_outline.expect b/pkg/front_end/testcases/macros/multiple_augment_class.dart.textual_outline.expect
new file mode 100644
index 0000000..8cef7dc
--- /dev/null
+++ b/pkg/front_end/testcases/macros/multiple_augment_class.dart.textual_outline.expect
@@ -0,0 +1,9 @@
+import augment 'multiple_augment_class_lib1.dart';
+import augment 'multiple_augment_class_lib2.dart';
+class Class {
+ external int method1();
+ external int method2();
+ external int method3();
+}
+main() {}
+expect(expected, actual) {}
diff --git a/pkg/front_end/testcases/macros/multiple_augment_class.dart.weak.expect b/pkg/front_end/testcases/macros/multiple_augment_class.dart.weak.expect
new file mode 100644
index 0000000..732d315
--- /dev/null
+++ b/pkg/front_end/testcases/macros/multiple_augment_class.dart.weak.expect
@@ -0,0 +1,29 @@
+library /*isNonNullableByDefault*/;
+import self as self;
+import "dart:core" as core;
+
+import "org-dartlang-testcase:///multiple_augment_class.dart";
+import "org-dartlang-testcase:///multiple_augment_class.dart";
+
+class Class extends core::Object {
+ synthetic constructor •() → self::Class
+ : super core::Object::•()
+ ;
+ method /* from org-dartlang-testcase:///multiple_augment_class_lib1.dart */ method1() → core::int
+ return 42;
+ method /* from org-dartlang-testcase:///multiple_augment_class_lib2.dart */ method2() → core::int
+ return 87;
+ method /* from org-dartlang-testcase:///multiple_augment_class_lib2.dart */ method3() → core::int
+ return 123;
+}
+static method main() → dynamic {
+ self::Class c = new self::Class::•();
+ self::expect(42, c.{self::Class::method1}(){() → core::int});
+ self::expect(87, c.{self::Class::method2}(){() → core::int});
+ self::expect(123, c.{self::Class::method3}(){() → core::int});
+}
+static method expect(dynamic expected, dynamic actual) → dynamic {
+ if(!(expected =={core::Object::==}{(core::Object) → core::bool} actual)) {
+ throw "Expected ${expected}, actual ${actual}";
+ }
+}
diff --git a/pkg/front_end/testcases/macros/multiple_augment_class.dart.weak.modular.expect b/pkg/front_end/testcases/macros/multiple_augment_class.dart.weak.modular.expect
new file mode 100644
index 0000000..732d315
--- /dev/null
+++ b/pkg/front_end/testcases/macros/multiple_augment_class.dart.weak.modular.expect
@@ -0,0 +1,29 @@
+library /*isNonNullableByDefault*/;
+import self as self;
+import "dart:core" as core;
+
+import "org-dartlang-testcase:///multiple_augment_class.dart";
+import "org-dartlang-testcase:///multiple_augment_class.dart";
+
+class Class extends core::Object {
+ synthetic constructor •() → self::Class
+ : super core::Object::•()
+ ;
+ method /* from org-dartlang-testcase:///multiple_augment_class_lib1.dart */ method1() → core::int
+ return 42;
+ method /* from org-dartlang-testcase:///multiple_augment_class_lib2.dart */ method2() → core::int
+ return 87;
+ method /* from org-dartlang-testcase:///multiple_augment_class_lib2.dart */ method3() → core::int
+ return 123;
+}
+static method main() → dynamic {
+ self::Class c = new self::Class::•();
+ self::expect(42, c.{self::Class::method1}(){() → core::int});
+ self::expect(87, c.{self::Class::method2}(){() → core::int});
+ self::expect(123, c.{self::Class::method3}(){() → core::int});
+}
+static method expect(dynamic expected, dynamic actual) → dynamic {
+ if(!(expected =={core::Object::==}{(core::Object) → core::bool} actual)) {
+ throw "Expected ${expected}, actual ${actual}";
+ }
+}
diff --git a/pkg/front_end/testcases/macros/multiple_augment_class.dart.weak.outline.expect b/pkg/front_end/testcases/macros/multiple_augment_class.dart.weak.outline.expect
new file mode 100644
index 0000000..8195b2746
--- /dev/null
+++ b/pkg/front_end/testcases/macros/multiple_augment_class.dart.weak.outline.expect
@@ -0,0 +1,18 @@
+library /*isNonNullableByDefault*/;
+import self as self;
+import "dart:core" as core;
+
+import "org-dartlang-testcase:///multiple_augment_class.dart";
+import "org-dartlang-testcase:///multiple_augment_class.dart";
+
+class Class extends core::Object {
+ synthetic constructor •() → self::Class
+ ;
+ external method method1() → core::int;
+ external method method2() → core::int;
+ external method method3() → core::int;
+}
+static method main() → dynamic
+ ;
+static method expect(dynamic expected, dynamic actual) → dynamic
+ ;
diff --git a/pkg/front_end/testcases/macros/multiple_augment_class.dart.weak.transformed.expect b/pkg/front_end/testcases/macros/multiple_augment_class.dart.weak.transformed.expect
new file mode 100644
index 0000000..732d315
--- /dev/null
+++ b/pkg/front_end/testcases/macros/multiple_augment_class.dart.weak.transformed.expect
@@ -0,0 +1,29 @@
+library /*isNonNullableByDefault*/;
+import self as self;
+import "dart:core" as core;
+
+import "org-dartlang-testcase:///multiple_augment_class.dart";
+import "org-dartlang-testcase:///multiple_augment_class.dart";
+
+class Class extends core::Object {
+ synthetic constructor •() → self::Class
+ : super core::Object::•()
+ ;
+ method /* from org-dartlang-testcase:///multiple_augment_class_lib1.dart */ method1() → core::int
+ return 42;
+ method /* from org-dartlang-testcase:///multiple_augment_class_lib2.dart */ method2() → core::int
+ return 87;
+ method /* from org-dartlang-testcase:///multiple_augment_class_lib2.dart */ method3() → core::int
+ return 123;
+}
+static method main() → dynamic {
+ self::Class c = new self::Class::•();
+ self::expect(42, c.{self::Class::method1}(){() → core::int});
+ self::expect(87, c.{self::Class::method2}(){() → core::int});
+ self::expect(123, c.{self::Class::method3}(){() → core::int});
+}
+static method expect(dynamic expected, dynamic actual) → dynamic {
+ if(!(expected =={core::Object::==}{(core::Object) → core::bool} actual)) {
+ throw "Expected ${expected}, actual ${actual}";
+ }
+}
diff --git a/pkg/front_end/testcases/macros/multiple_augment_class_lib1.dart b/pkg/front_end/testcases/macros/multiple_augment_class_lib1.dart
new file mode 100644
index 0000000..f396fe9
--- /dev/null
+++ b/pkg/front_end/testcases/macros/multiple_augment_class_lib1.dart
@@ -0,0 +1,8 @@
+// Copyright (c) 2022, 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.
+
+augment class Class {
+ augment int method1() => 42;
+ augment int method3() => 321;
+}
diff --git a/pkg/front_end/testcases/macros/multiple_augment_class_lib2.dart b/pkg/front_end/testcases/macros/multiple_augment_class_lib2.dart
new file mode 100644
index 0000000..7dcc285
--- /dev/null
+++ b/pkg/front_end/testcases/macros/multiple_augment_class_lib2.dart
@@ -0,0 +1,8 @@
+// Copyright (c) 2022, 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.
+
+augment class Class {
+ augment int method2() => 87;
+ augment int method3() => 123;
+}
diff --git a/pkg/front_end/testcases/textual_outline.status b/pkg/front_end/testcases/textual_outline.status
index d344b76..5d85637 100644
--- a/pkg/front_end/testcases/textual_outline.status
+++ b/pkg/front_end/testcases/textual_outline.status
@@ -117,10 +117,12 @@
macros/augment_concrete: FormatterCrash
macros/augment_super: FormatterCrash
macros/class_members: FormatterCrash
+macros/duplicate_augment: FormatterCrash
macros/extend_augmented: FormatterCrash
macros/inject_constructor: FormatterCrash
macros/library_members: FormatterCrash
macros/macro_class: FormatterCrash
+macros/multiple_augment_class: FormatterCrash
macros/multiple_imports: FormatterCrash
macros/scope_access: FormatterCrash
nnbd_mixed/inheritance_from_opt_in: FormatterCrash
diff --git a/pkg/front_end/testcases/weak.status b/pkg/front_end/testcases/weak.status
index aa16c3a..373926e 100644
--- a/pkg/front_end/testcases/weak.status
+++ b/pkg/front_end/testcases/weak.status
@@ -161,6 +161,7 @@
general/mixin_application_override: TypeCheckError
general/mixin_constructors_with_default_values: RuntimeError # Expected
general/mixin_covariant2: RuntimeError
+general/multiple_class_patches/main: RuntimeError
general/operator_method_not_found: RuntimeError # Expected
general/optional: RuntimeError
general/override_check_accessor_after_inference: TypeCheckError # Issue #31620