Skip to content

Commit 8c994b5

Browse files
johnniwintherCommit Queue
authored andcommitted
[cfe] Report error on conflict between setter and prefix
An error was never reported for conflict between a prefix and a setter declared in the same library. Tests added for both the simple case and cases for enhanced parts. Change-Id: I752d519840eac714be7f64307a610bb4db142ac4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/452120 Reviewed-by: Chloe Stefantsova <[email protected]> Commit-Queue: Johnni Winther <[email protected]>
1 parent e0a8637 commit 8c994b5

File tree

29 files changed

+1484
-2
lines changed

29 files changed

+1484
-2
lines changed

pkg/front_end/lib/src/source/source_compilation_unit.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,6 @@ class SourceCompilationUnitImpl implements SourceCompilationUnit {
14221422
int charOffset,
14231423
) {
14241424
Builder? existing = prefixNameSpace.lookup(name)?.getable;
1425-
existing ??= libraryBuilder.libraryNameSpace.lookup(name)?.getable;
14261425
if (existing is PrefixBuilder) {
14271426
assert(existing.next is! PrefixBuilder);
14281427
int? deferredFileOffset;
@@ -1449,7 +1448,11 @@ class SourceCompilationUnitImpl implements SourceCompilationUnit {
14491448
}
14501449
prefixFragment.builder = existing;
14511450
return false;
1452-
} else if (existing != null) {
1451+
}
1452+
1453+
LookupResult? result = libraryBuilder.libraryNameSpace.lookup(name);
1454+
if (result != null) {
1455+
NamedBuilder existing = result.getable ?? result.setable!;
14531456
String fullName = name;
14541457
_problemReporting.addProblem(
14551458
codeDuplicatedDeclaration.withArgumentsOld(fullName),
@@ -1467,6 +1470,7 @@ class SourceCompilationUnitImpl implements SourceCompilationUnit {
14671470
],
14681471
);
14691472
}
1473+
14701474
_prefixNameSpace.addLocalMember(
14711475
name,
14721476
prefixFragment.createPrefixBuilder(
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) 2025, 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+
part 'nested_part_declarations_part1.dart';
6+
part 'nested_part_declarations_part3.dart';
7+
8+
void declaredInMain() {
9+
declaredInMain();
10+
declaredInPart1();
11+
declaredInPart2();
12+
declaredInPart3();
13+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
library;
2+
import self as self;
3+
4+
part nested_part_declarations_part1.dart;
5+
part nested_part_declarations_part3.dart;
6+
part nested_part_declarations_part2.dart;
7+
static method declaredInMain() → void {
8+
self::declaredInMain();
9+
self::declaredInPart1();
10+
self::declaredInPart2();
11+
self::declaredInPart3();
12+
}
13+
static method /* from org-dartlang-testcase:///nested_part_declarations_part1.dart */ declaredInPart1() → void {
14+
self::declaredInMain();
15+
self::declaredInPart1();
16+
self::declaredInPart2();
17+
self::declaredInPart3();
18+
}
19+
static method /* from org-dartlang-testcase:///nested_part_declarations_part2.dart */ declaredInPart2() → void {
20+
self::declaredInMain();
21+
self::declaredInPart1();
22+
self::declaredInPart2();
23+
self::declaredInPart3();
24+
}
25+
static method /* from org-dartlang-testcase:///nested_part_declarations_part3.dart */ declaredInPart3() → void {
26+
self::declaredInMain();
27+
self::declaredInPart1();
28+
self::declaredInPart2();
29+
self::declaredInPart3();
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
library;
2+
import self as self;
3+
4+
part nested_part_declarations_part1.dart;
5+
part nested_part_declarations_part3.dart;
6+
part nested_part_declarations_part2.dart;
7+
static method declaredInMain() → void {
8+
self::declaredInMain();
9+
self::declaredInPart1();
10+
self::declaredInPart2();
11+
self::declaredInPart3();
12+
}
13+
static method /* from org-dartlang-testcase:///nested_part_declarations_part1.dart */ declaredInPart1() → void {
14+
self::declaredInMain();
15+
self::declaredInPart1();
16+
self::declaredInPart2();
17+
self::declaredInPart3();
18+
}
19+
static method /* from org-dartlang-testcase:///nested_part_declarations_part2.dart */ declaredInPart2() → void {
20+
self::declaredInMain();
21+
self::declaredInPart1();
22+
self::declaredInPart2();
23+
self::declaredInPart3();
24+
}
25+
static method /* from org-dartlang-testcase:///nested_part_declarations_part3.dart */ declaredInPart3() → void {
26+
self::declaredInMain();
27+
self::declaredInPart1();
28+
self::declaredInPart2();
29+
self::declaredInPart3();
30+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
library;
2+
import self as self;
3+
4+
part nested_part_declarations_part1.dart;
5+
part nested_part_declarations_part3.dart;
6+
part nested_part_declarations_part2.dart;
7+
static method declaredInMain() → void
8+
;
9+
static method /* from org-dartlang-testcase:///nested_part_declarations_part1.dart */ declaredInPart1() → void
10+
;
11+
static method /* from org-dartlang-testcase:///nested_part_declarations_part2.dart */ declaredInPart2() → void
12+
;
13+
static method /* from org-dartlang-testcase:///nested_part_declarations_part3.dart */ declaredInPart3() → void
14+
;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
library;
2+
import self as self;
3+
4+
part nested_part_declarations_part1.dart;
5+
part nested_part_declarations_part3.dart;
6+
part nested_part_declarations_part2.dart;
7+
static method declaredInMain() → void {
8+
self::declaredInMain();
9+
self::declaredInPart1();
10+
self::declaredInPart2();
11+
self::declaredInPart3();
12+
}
13+
static method /* from org-dartlang-testcase:///nested_part_declarations_part1.dart */ declaredInPart1() → void {
14+
self::declaredInMain();
15+
self::declaredInPart1();
16+
self::declaredInPart2();
17+
self::declaredInPart3();
18+
}
19+
static method /* from org-dartlang-testcase:///nested_part_declarations_part2.dart */ declaredInPart2() → void {
20+
self::declaredInMain();
21+
self::declaredInPart1();
22+
self::declaredInPart2();
23+
self::declaredInPart3();
24+
}
25+
static method /* from org-dartlang-testcase:///nested_part_declarations_part3.dart */ declaredInPart3() → void {
26+
self::declaredInMain();
27+
self::declaredInPart1();
28+
self::declaredInPart2();
29+
self::declaredInPart3();
30+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
part 'nested_part_declarations_part1.dart';
2+
3+
part 'nested_part_declarations_part3.dart';
4+
5+
void declaredInMain() {}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
part 'nested_part_declarations_part1.dart';
2+
3+
part 'nested_part_declarations_part3.dart';
4+
5+
void declaredInMain() {}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) 2025, 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+
part of 'nested_part_declarations.dart';
6+
7+
part 'nested_part_declarations_part2.dart';
8+
9+
void declaredInPart1() {
10+
declaredInMain();
11+
declaredInPart1();
12+
declaredInPart2();
13+
declaredInPart3();
14+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright (c) 2025, 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+
part of 'nested_part_declarations_part1.dart';
6+
7+
void declaredInPart2() {
8+
declaredInMain();
9+
declaredInPart1();
10+
declaredInPart2();
11+
declaredInPart3();
12+
}

0 commit comments

Comments
 (0)