Skip to content

Commit bb1e9f0

Browse files
johnniwintherCommit Queue
authored andcommitted
[cfe] Don't report errors on use of duplicate declarations
If a declaration is a duplicate we report an error on the declaration. Therefore reporting an error also on the use of the duplicate declaration is just noise. Change-Id: Ia62eb5056d80f5b766b14c9540085d6b0ee880a0 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/438220 Reviewed-by: Erik Ernst <[email protected]> Commit-Queue: Johnni Winther <[email protected]> Reviewed-by: Chloe Stefantsova <[email protected]>
1 parent 7255c1d commit bb1e9f0

File tree

50 files changed

+16
-693
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+16
-693
lines changed

pkg/front_end/lib/src/kernel/body_builder.dart

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ class BodyBuilder extends StackListenerImpl
643643
return buildProblem(
644644
cfe.messageSuperAsExpression, node.fileOffset, noLength);
645645
} else if (node is ProblemBuilder) {
646-
return buildProblem(node.message, node.fileOffset, noLength);
646+
return node.toExpression(libraryBuilder);
647647
} else {
648648
return unhandled("${node.runtimeType}", "toValue", -1, uri);
649649
}
@@ -664,8 +664,7 @@ class BodyBuilder extends StackListenerImpl
664664
}
665665
// Coverage-ignore(suite): Not run.
666666
else if (node is ProblemBuilder) {
667-
Expression expression =
668-
buildProblem(node.message, node.fileOffset, noLength);
667+
Expression expression = node.toExpression(libraryBuilder);
669668
return forest.createConstantPattern(expression);
670669
} else {
671670
return unhandled("${node.runtimeType}", "toPattern", -1, uri);
@@ -2772,8 +2771,7 @@ class BodyBuilder extends StackListenerImpl
27722771
push(left.buildEqualsOperation(token, right, isNot: isNot));
27732772
} else {
27742773
if (left is ProblemBuilder) {
2775-
ProblemBuilder problem = left;
2776-
left = buildProblem(problem.message, problem.fileOffset, noLength);
2774+
left = left.toExpression(libraryBuilder);
27772775
}
27782776
assert(left is Expression);
27792777
push(forest.createEquals(fileOffset, left as Expression, right,
@@ -2793,8 +2791,7 @@ class BodyBuilder extends StackListenerImpl
27932791
push(left.buildBinaryOperation(token, name, right));
27942792
} else {
27952793
if (left is ProblemBuilder) {
2796-
ProblemBuilder problem = left;
2797-
left = buildProblem(problem.message, problem.fileOffset, noLength);
2794+
left = left.toExpression(libraryBuilder);
27982795
}
27992796
assert(left is Expression);
28002797
push(forest.createBinary(fileOffset, left as Expression, name, right));
@@ -5093,9 +5090,6 @@ class BodyBuilder extends StackListenerImpl
50935090
allowPotentiallyConstantType: allowPotentiallyConstantType,
50945091
performTypeCanonicalization: constantContext != ConstantContext.none);
50955092
} else if (name is ProblemBuilder) {
5096-
// TODO(ahe): Arguments could be passed here.
5097-
libraryBuilder.addProblem(
5098-
name.message, name.fileOffset, name.name.length, name.fileUri);
50995093
result = new NamedTypeBuilderImpl.forInvalidType(
51005094
name.name,
51015095
isMarkedAsNullable
@@ -10598,3 +10592,13 @@ extension on MemberKind {
1059810592
}
1059910593
}
1060010594
}
10595+
10596+
extension on ProblemBuilder {
10597+
Expression toExpression(SourceLibraryBuilder libraryBuilder) {
10598+
String text = libraryBuilder.loader.target.context
10599+
.format(
10600+
message.withLocation(fileUri, fileOffset, noLength), Severity.error)
10601+
.plain;
10602+
return new InvalidExpression(text)..fileOffset = fileOffset;
10603+
}
10604+
}

pkg/front_end/testcases/extensions/issue38745.dart.strong.expect

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ library;
4040
// property = 23;
4141
// ^^^^^^^^
4242
//
43-
// pkg/front_end/testcases/extensions/issue38745.dart:24:5: Error: Can't use 'property2' because it is declared more than once.
44-
// property2;
45-
// ^
46-
//
4743
// pkg/front_end/testcases/extensions/issue38745.dart:25:15: Error: Can't assign to this.
4844
// property2 = 23;
4945
// ^

pkg/front_end/testcases/extensions/issue38745.dart.strong.modular.expect

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ library;
4040
// property = 23;
4141
// ^^^^^^^^
4242
//
43-
// pkg/front_end/testcases/extensions/issue38745.dart:24:5: Error: Can't use 'property2' because it is declared more than once.
44-
// property2;
45-
// ^
46-
//
4743
// pkg/front_end/testcases/extensions/issue38745.dart:25:15: Error: Can't assign to this.
4844
// property2 = 23;
4945
// ^

pkg/front_end/testcases/extensions/issue38745.dart.strong.transformed.expect

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ library;
4040
// property = 23;
4141
// ^^^^^^^^
4242
//
43-
// pkg/front_end/testcases/extensions/issue38745.dart:24:5: Error: Can't use 'property2' because it is declared more than once.
44-
// property2;
45-
// ^
46-
//
4743
// pkg/front_end/testcases/extensions/issue38745.dart:25:15: Error: Can't assign to this.
4844
// property2 = 23;
4945
// ^

pkg/front_end/testcases/general/duplicated_declarations.dart.strong.expect

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -305,18 +305,6 @@ library;
305305
// String toString() => _enumToString();
306306
// ^^^^^^^^
307307
//
308-
// pkg/front_end/testcases/general/duplicated_declarations.dart:36:3: Error: Can't use 'main' because it is declared more than once.
309-
// main();
310-
// ^
311-
//
312-
// pkg/front_end/testcases/general/duplicated_declarations.dart:37:9: Error: Can't use 'field' because it is declared more than once.
313-
// print(field);
314-
// ^
315-
//
316-
// pkg/front_end/testcases/general/duplicated_declarations.dart:38:3: Error: Can't use 'C' because it is declared more than once.
317-
// C.s();
318-
// ^
319-
//
320308
// pkg/front_end/testcases/general/duplicated_declarations.dart:39:5: Error: Expected identifier, but got 'this'.
321309
// C.this();
322310
// ^^^^
@@ -334,10 +322,6 @@ library;
334322
// C.();
335323
// ^
336324
//
337-
// pkg/front_end/testcases/general/duplicated_declarations.dart:66:17: Error: Can't use 's' because it is declared more than once.
338-
// static f() => s;
339-
// ^
340-
//
341325
// pkg/front_end/testcases/general/duplicated_declarations.dart:70:16: Error: Too many positional arguments: 0 allowed, but 1 found.
342326
// Try removing the extra positional arguments.
343327
// Sub() : super(null);
@@ -351,10 +335,6 @@ library;
351335
// "AnotherEnum.values": AnotherEnum.values,
352336
// ^^^^^^
353337
//
354-
// pkg/front_end/testcases/general/duplicated_declarations_part.dart:64:17: Error: Can't use 's' because it is declared more than once.
355-
// static f() => s;
356-
// ^
357-
//
358338
import self as self;
359339
import "dart:core" as core;
360340

pkg/front_end/testcases/general/duplicated_declarations.dart.strong.modular.expect

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -305,18 +305,6 @@ library;
305305
// String toString() => _enumToString();
306306
// ^^^^^^^^
307307
//
308-
// pkg/front_end/testcases/general/duplicated_declarations.dart:36:3: Error: Can't use 'main' because it is declared more than once.
309-
// main();
310-
// ^
311-
//
312-
// pkg/front_end/testcases/general/duplicated_declarations.dart:37:9: Error: Can't use 'field' because it is declared more than once.
313-
// print(field);
314-
// ^
315-
//
316-
// pkg/front_end/testcases/general/duplicated_declarations.dart:38:3: Error: Can't use 'C' because it is declared more than once.
317-
// C.s();
318-
// ^
319-
//
320308
// pkg/front_end/testcases/general/duplicated_declarations.dart:39:5: Error: Expected identifier, but got 'this'.
321309
// C.this();
322310
// ^^^^
@@ -334,10 +322,6 @@ library;
334322
// C.();
335323
// ^
336324
//
337-
// pkg/front_end/testcases/general/duplicated_declarations.dart:66:17: Error: Can't use 's' because it is declared more than once.
338-
// static f() => s;
339-
// ^
340-
//
341325
// pkg/front_end/testcases/general/duplicated_declarations.dart:70:16: Error: Too many positional arguments: 0 allowed, but 1 found.
342326
// Try removing the extra positional arguments.
343327
// Sub() : super(null);
@@ -351,10 +335,6 @@ library;
351335
// "AnotherEnum.values": AnotherEnum.values,
352336
// ^^^^^^
353337
//
354-
// pkg/front_end/testcases/general/duplicated_declarations_part.dart:64:17: Error: Can't use 's' because it is declared more than once.
355-
// static f() => s;
356-
// ^
357-
//
358338
import self as self;
359339
import "dart:core" as core;
360340

pkg/front_end/testcases/general/duplicated_declarations.dart.strong.transformed.expect

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -305,18 +305,6 @@ library;
305305
// String toString() => _enumToString();
306306
// ^^^^^^^^
307307
//
308-
// pkg/front_end/testcases/general/duplicated_declarations.dart:36:3: Error: Can't use 'main' because it is declared more than once.
309-
// main();
310-
// ^
311-
//
312-
// pkg/front_end/testcases/general/duplicated_declarations.dart:37:9: Error: Can't use 'field' because it is declared more than once.
313-
// print(field);
314-
// ^
315-
//
316-
// pkg/front_end/testcases/general/duplicated_declarations.dart:38:3: Error: Can't use 'C' because it is declared more than once.
317-
// C.s();
318-
// ^
319-
//
320308
// pkg/front_end/testcases/general/duplicated_declarations.dart:39:5: Error: Expected identifier, but got 'this'.
321309
// C.this();
322310
// ^^^^
@@ -334,10 +322,6 @@ library;
334322
// C.();
335323
// ^
336324
//
337-
// pkg/front_end/testcases/general/duplicated_declarations.dart:66:17: Error: Can't use 's' because it is declared more than once.
338-
// static f() => s;
339-
// ^
340-
//
341325
// pkg/front_end/testcases/general/duplicated_declarations.dart:70:16: Error: Too many positional arguments: 0 allowed, but 1 found.
342326
// Try removing the extra positional arguments.
343327
// Sub() : super(null);
@@ -351,10 +335,6 @@ library;
351335
// "AnotherEnum.values": AnotherEnum.values,
352336
// ^^^^^^
353337
//
354-
// pkg/front_end/testcases/general/duplicated_declarations_part.dart:64:17: Error: Can't use 's' because it is declared more than once.
355-
// static f() => s;
356-
// ^
357-
//
358338
import self as self;
359339
import "dart:core" as core;
360340

pkg/front_end/testcases/general/error_recovery/class_header.dart.strong.expect

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2642,26 +2642,6 @@ library;
26422642
// enum E25 with C with { element }
26432643
// ^
26442644
//
2645-
// pkg/front_end/testcases/general/error_recovery/class_header.dart:38:27: Error: Can't use 'B' because it is declared more than once.
2646-
// class N5 = with C extends B implements D;
2647-
// ^
2648-
//
2649-
// pkg/front_end/testcases/general/error_recovery/class_header.dart:43:33: Error: Can't use 'C' because it is declared more than once.
2650-
// class N10 = B implements D with C implements D;
2651-
// ^
2652-
//
2653-
// pkg/front_end/testcases/general/error_recovery/class_header.dart:45:30: Error: Can't use 'C' because it is declared more than once.
2654-
// class N12 = B extends B with C implements D;
2655-
// ^
2656-
//
2657-
// pkg/front_end/testcases/general/error_recovery/class_header.dart:46:27: Error: Can't use 'C' because it is declared more than once.
2658-
// class N13 = B with C with C implements D;
2659-
// ^
2660-
//
2661-
// pkg/front_end/testcases/general/error_recovery/class_header.dart:73:35: Error: Can't use 'C' because it is declared more than once.
2662-
// enum E12 extends B extends B with C implements D { element }
2663-
// ^
2664-
//
26652645
// pkg/front_end/testcases/general/error_recovery/class_header.dart:73:52: Error: Expected ';' after this.
26662646
// enum E12 extends B extends B with C implements D { element }
26672647
// ^^^^^^^

pkg/front_end/testcases/general/error_recovery/class_header.dart.strong.modular.expect

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2642,26 +2642,6 @@ library;
26422642
// enum E25 with C with { element }
26432643
// ^
26442644
//
2645-
// pkg/front_end/testcases/general/error_recovery/class_header.dart:38:27: Error: Can't use 'B' because it is declared more than once.
2646-
// class N5 = with C extends B implements D;
2647-
// ^
2648-
//
2649-
// pkg/front_end/testcases/general/error_recovery/class_header.dart:43:33: Error: Can't use 'C' because it is declared more than once.
2650-
// class N10 = B implements D with C implements D;
2651-
// ^
2652-
//
2653-
// pkg/front_end/testcases/general/error_recovery/class_header.dart:45:30: Error: Can't use 'C' because it is declared more than once.
2654-
// class N12 = B extends B with C implements D;
2655-
// ^
2656-
//
2657-
// pkg/front_end/testcases/general/error_recovery/class_header.dart:46:27: Error: Can't use 'C' because it is declared more than once.
2658-
// class N13 = B with C with C implements D;
2659-
// ^
2660-
//
2661-
// pkg/front_end/testcases/general/error_recovery/class_header.dart:73:35: Error: Can't use 'C' because it is declared more than once.
2662-
// enum E12 extends B extends B with C implements D { element }
2663-
// ^
2664-
//
26652645
// pkg/front_end/testcases/general/error_recovery/class_header.dart:73:52: Error: Expected ';' after this.
26662646
// enum E12 extends B extends B with C implements D { element }
26672647
// ^^^^^^^

pkg/front_end/testcases/general/error_recovery/class_header.dart.strong.transformed.expect

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2642,26 +2642,6 @@ library;
26422642
// enum E25 with C with { element }
26432643
// ^
26442644
//
2645-
// pkg/front_end/testcases/general/error_recovery/class_header.dart:38:27: Error: Can't use 'B' because it is declared more than once.
2646-
// class N5 = with C extends B implements D;
2647-
// ^
2648-
//
2649-
// pkg/front_end/testcases/general/error_recovery/class_header.dart:43:33: Error: Can't use 'C' because it is declared more than once.
2650-
// class N10 = B implements D with C implements D;
2651-
// ^
2652-
//
2653-
// pkg/front_end/testcases/general/error_recovery/class_header.dart:45:30: Error: Can't use 'C' because it is declared more than once.
2654-
// class N12 = B extends B with C implements D;
2655-
// ^
2656-
//
2657-
// pkg/front_end/testcases/general/error_recovery/class_header.dart:46:27: Error: Can't use 'C' because it is declared more than once.
2658-
// class N13 = B with C with C implements D;
2659-
// ^
2660-
//
2661-
// pkg/front_end/testcases/general/error_recovery/class_header.dart:73:35: Error: Can't use 'C' because it is declared more than once.
2662-
// enum E12 extends B extends B with C implements D { element }
2663-
// ^
2664-
//
26652645
// pkg/front_end/testcases/general/error_recovery/class_header.dart:73:52: Error: Expected ';' after this.
26662646
// enum E12 extends B extends B with C implements D { element }
26672647
// ^^^^^^^

0 commit comments

Comments
 (0)