Skip to content

Commit 30bbd94

Browse files
johnniwintherCommit Bot
authored and
Commit Bot
committed
[cfe] Handle duplicates in augmentation libraries
Change-Id: I6200ffa7e3b2b68dbda2233f8bd3da7c76d7438a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/259360 Reviewed-by: Jens Johansen <[email protected]> Commit-Queue: Johnni Winther <[email protected]>
1 parent 2189897 commit 30bbd94

33 files changed

+890
-0
lines changed

pkg/front_end/lib/src/fasta/scope.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,13 +1369,24 @@ abstract class MergedScope<T extends Builder> {
13691369
}
13701370

13711371
void _addAugmentationScope(T parentBuilder, Scope scope) {
1372+
// TODO(johnniwinther): Use `scope.filteredNameIterator` instead of
1373+
// `scope.forEachLocalMember`/`scope.forEachLocalSetter`.
1374+
13721375
// Include all augmentation scope members to the origin scope.
13731376
scope.forEachLocalMember((String name, Builder member) {
1377+
// In case of duplicates we use the first declaration.
1378+
while (member.isDuplicate) {
1379+
member = member.next!;
1380+
}
13741381
_addBuilderToMergedScope(parentBuilder, name, member,
13751382
_originScope.lookupLocalMember(name, setter: false),
13761383
setter: false);
13771384
});
13781385
scope.forEachLocalSetter((String name, Builder member) {
1386+
// In case of duplicates we use the first declaration.
1387+
while (member.isDuplicate) {
1388+
member = member.next!;
1389+
}
13791390
_addBuilderToMergedScope(parentBuilder, name, member,
13801391
_originScope.lookupLocalMember(name, setter: true),
13811392
setter: true);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"none": {
3+
"libraries": {
4+
"test": {
5+
"patches": [
6+
"patch_lib1.dart",
7+
"patch_lib2.dart"
8+
],
9+
"uri": "origin_lib.dart"
10+
}
11+
}
12+
}
13+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'dart:test';
6+
7+
main() {
8+
Class c = new Class();
9+
expect(42, c.method1());
10+
expect(87, c.method2());
11+
expect(123, c.method3());
12+
}
13+
14+
expect(expected, actual) {
15+
if (expected != actual) {
16+
throw 'Expected $expected, actual $actual';
17+
}
18+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import 'dart:test';
2+
3+
main() {}
4+
expect(expected, actual) {}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import 'dart:test';
2+
3+
expect(expected, actual) {}
4+
main() {}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
library /*isNonNullableByDefault*/;
2+
import self as self;
3+
import "dart:test" as test;
4+
import "dart:core" as core;
5+
6+
import "dart:test";
7+
8+
static method main() → dynamic {
9+
test::Class c = new test::Class::•();
10+
self::expect(42, c.{test::Class::method1}(){() → core::int});
11+
self::expect(87, c.{test::Class::method2}(){() → core::int});
12+
self::expect(123, c.{test::Class::method3}(){() → core::int});
13+
}
14+
static method expect(dynamic expected, dynamic actual) → dynamic {
15+
if(!(expected =={core::Object::==}{(core::Object) → core::bool} actual)) {
16+
throw "Expected ${expected}, actual ${actual}";
17+
}
18+
}
19+
20+
library /*isNonNullableByDefault*/;
21+
//
22+
// Problems in library:
23+
//
24+
// pkg/front_end/testcases/general/multiple_class_patches/patch_lib2.dart:9:7: Error: 'Class' is already declared in this scope.
25+
// class Class {
26+
// ^^^^^
27+
// pkg/front_end/testcases/general/multiple_class_patches/patch_lib1.dart:9:7: Context: Previous declaration of 'Class'.
28+
// class Class {
29+
// ^^^^^
30+
//
31+
import self as test;
32+
import "dart:_internal" as _in;
33+
import "dart:core" as core;
34+
35+
import "dart:_internal";
36+
import "dart:_internal";
37+
38+
@#C1
39+
class Class#1#1 extends core::Object { // from org-dartlang-testcase:///patch_lib2.dart
40+
synthetic constructor •() → test::Class#1#1
41+
: super core::Object::•()
42+
;
43+
@#C1
44+
method method2() → core::int
45+
return 87;
46+
@#C1
47+
method method3() → core::int
48+
return 123;
49+
}
50+
@#C1
51+
class Class extends core::Object {
52+
synthetic constructor •() → test::Class
53+
: super core::Object::•()
54+
;
55+
@#C1
56+
method /* from org-dartlang-testcase:///patch_lib1.dart */ method1() → core::int
57+
return 42;
58+
external method method2() → core::int;
59+
@#C1
60+
method /* from org-dartlang-testcase:///patch_lib1.dart */ method3() → core::int
61+
return 321;
62+
}
63+
64+
constants {
65+
#C1 = _in::_Patch {}
66+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
library /*isNonNullableByDefault*/;
2+
import self as self;
3+
import "dart:test" as test;
4+
import "dart:core" as core;
5+
6+
import "dart:test";
7+
8+
static method main() → dynamic {
9+
test::Class c = new test::Class::•();
10+
self::expect(42, c.{test::Class::method1}(){() → core::int});
11+
self::expect(87, c.{test::Class::method2}(){() → core::int});
12+
self::expect(123, c.{test::Class::method3}(){() → core::int});
13+
}
14+
static method expect(dynamic expected, dynamic actual) → dynamic {
15+
if(!(expected =={core::Object::==}{(core::Object) → core::bool} actual)) {
16+
throw "Expected ${expected}, actual ${actual}";
17+
}
18+
}
19+
20+
library /*isNonNullableByDefault*/;
21+
//
22+
// Problems in library:
23+
//
24+
// pkg/front_end/testcases/general/multiple_class_patches/patch_lib2.dart:9:7: Error: 'Class' is already declared in this scope.
25+
// class Class {
26+
// ^^^^^
27+
// pkg/front_end/testcases/general/multiple_class_patches/patch_lib1.dart:9:7: Context: Previous declaration of 'Class'.
28+
// class Class {
29+
// ^^^^^
30+
//
31+
import self as test;
32+
import "dart:_internal" as _in;
33+
import "dart:core" as core;
34+
35+
import "dart:_internal";
36+
import "dart:_internal";
37+
38+
@#C1
39+
class Class#1#1 extends core::Object { // from org-dartlang-testcase:///patch_lib2.dart
40+
synthetic constructor •() → test::Class#1#1
41+
: super core::Object::•()
42+
;
43+
@#C1
44+
method method2() → core::int
45+
return 87;
46+
@#C1
47+
method method3() → core::int
48+
return 123;
49+
}
50+
@#C1
51+
class Class extends core::Object {
52+
synthetic constructor •() → test::Class
53+
: super core::Object::•()
54+
;
55+
@#C1
56+
method /* from org-dartlang-testcase:///patch_lib1.dart */ method1() → core::int
57+
return 42;
58+
external method method2() → core::int;
59+
@#C1
60+
method /* from org-dartlang-testcase:///patch_lib1.dart */ method3() → core::int
61+
return 321;
62+
}
63+
64+
constants {
65+
#C1 = _in::_Patch {}
66+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
library /*isNonNullableByDefault*/;
2+
import self as self;
3+
4+
import "dart:test";
5+
6+
static method main() → dynamic
7+
;
8+
static method expect(dynamic expected, dynamic actual) → dynamic
9+
;
10+
11+
library /*isNonNullableByDefault*/;
12+
//
13+
// Problems in library:
14+
//
15+
// pkg/front_end/testcases/general/multiple_class_patches/patch_lib2.dart:9:7: Error: 'Class' is already declared in this scope.
16+
// class Class {
17+
// ^^^^^
18+
// pkg/front_end/testcases/general/multiple_class_patches/patch_lib1.dart:9:7: Context: Previous declaration of 'Class'.
19+
// class Class {
20+
// ^^^^^
21+
//
22+
import self as self2;
23+
import "dart:_internal" as _in;
24+
import "dart:core" as core;
25+
26+
import "dart:_internal";
27+
import "dart:_internal";
28+
29+
@_in::patch
30+
class Class#1#1 extends core::Object { // from org-dartlang-testcase:///patch_lib2.dart
31+
synthetic constructor •() → self2::Class#1#1
32+
;
33+
@_in::patch
34+
method method2() → core::int
35+
;
36+
@_in::patch
37+
method method3() → core::int
38+
;
39+
}
40+
@_in::patch
41+
class Class extends core::Object {
42+
synthetic constructor •() → self2::Class
43+
;
44+
@_in::patch
45+
external method method1() → core::int;
46+
external method method2() → core::int;
47+
@_in::patch
48+
external method method3() → core::int;
49+
}
50+
51+
52+
Extra constant evaluation status:
53+
Evaluated: StaticGet @ org-dartlang-testcase:///patch_lib2.dart:8:2 -> InstanceConstant(const _Patch{})
54+
Evaluated: StaticGet @ org-dartlang-testcase:///patch_lib2.dart:10:4 -> InstanceConstant(const _Patch{})
55+
Evaluated: StaticGet @ org-dartlang-testcase:///patch_lib2.dart:13:4 -> InstanceConstant(const _Patch{})
56+
Evaluated: StaticGet @ org-dartlang-testcase:///origin_lib.dart:7:23 -> InstanceConstant(const _Patch{})
57+
Evaluated: StaticGet @ org-dartlang-testcase:///origin_lib.dart:8:20 -> InstanceConstant(const _Patch{})
58+
Evaluated: StaticGet @ (unknown position in org-dartlang-testcase:///origin_lib.dart) -> InstanceConstant(const _Patch{})
59+
Extra constant evaluation: evaluated: 6, effectively constant: 6
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
library /*isNonNullableByDefault*/;
2+
import self as self;
3+
import "dart:test" as test;
4+
import "dart:core" as core;
5+
6+
import "dart:test";
7+
8+
static method main() → dynamic {
9+
test::Class c = new test::Class::•();
10+
self::expect(42, c.{test::Class::method1}(){() → core::int});
11+
self::expect(87, c.{test::Class::method2}(){() → core::int});
12+
self::expect(123, c.{test::Class::method3}(){() → core::int});
13+
}
14+
static method expect(dynamic expected, dynamic actual) → dynamic {
15+
if(!(expected =={core::Object::==}{(core::Object) → core::bool} actual)) {
16+
throw "Expected ${expected}, actual ${actual}";
17+
}
18+
}
19+
20+
library /*isNonNullableByDefault*/;
21+
//
22+
// Problems in library:
23+
//
24+
// pkg/front_end/testcases/general/multiple_class_patches/patch_lib2.dart:9:7: Error: 'Class' is already declared in this scope.
25+
// class Class {
26+
// ^^^^^
27+
// pkg/front_end/testcases/general/multiple_class_patches/patch_lib1.dart:9:7: Context: Previous declaration of 'Class'.
28+
// class Class {
29+
// ^^^^^
30+
//
31+
import self as test;
32+
import "dart:_internal" as _in;
33+
import "dart:core" as core;
34+
35+
import "dart:_internal";
36+
import "dart:_internal";
37+
38+
@#C1
39+
class Class#1#1 extends core::Object { // from org-dartlang-testcase:///patch_lib2.dart
40+
synthetic constructor •() → test::Class#1#1
41+
: super core::Object::•()
42+
;
43+
@#C1
44+
method method2() → core::int
45+
return 87;
46+
@#C1
47+
method method3() → core::int
48+
return 123;
49+
}
50+
@#C1
51+
class Class extends core::Object {
52+
synthetic constructor •() → test::Class
53+
: super core::Object::•()
54+
;
55+
@#C1
56+
method /* from org-dartlang-testcase:///patch_lib1.dart */ method1() → core::int
57+
return 42;
58+
external method method2() → core::int;
59+
@#C1
60+
method /* from org-dartlang-testcase:///patch_lib1.dart */ method3() → core::int
61+
return 321;
62+
}
63+
64+
constants {
65+
#C1 = _in::_Patch {}
66+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
class Class {
6+
external int method1();
7+
external int method2();
8+
external int method3();
9+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// ignore: import_internal_library
6+
import 'dart:_internal';
7+
8+
@patch
9+
class Class {
10+
@patch
11+
int method1() => 42;
12+
13+
@patch
14+
int method3() => 321;
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// ignore: import_internal_library
6+
import 'dart:_internal';
7+
8+
@patch
9+
class Class {
10+
@patch
11+
int method2() => 87;
12+
13+
@patch
14+
int method3() => 123;
15+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import augment 'duplicate_augment_lib.dart';
6+
7+
void augmentedTopLevelMethod() {}
8+
9+
class AugmentedClass {
10+
void augmentedInstanceMethod() {}
11+
static void augmentedStaticMethod() {}
12+
}

0 commit comments

Comments
 (0)