Skip to content

Commit d2b0a37

Browse files
chloestefantsovaCommit Bot
authored and
Commit Bot
committed
[cfe] Avoid synthesized locations for reporting conflict errors
Part of #47453 Change-Id: I51277f2c548b4632b9b9870b522f19a9e8c77498 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/239680 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Chloe Stefantsova <[email protected]>
1 parent ef413b9 commit d2b0a37

15 files changed

+319
-8
lines changed

pkg/_fe_analyzer_shared/lib/src/messages/codes_generated.dart

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5641,6 +5641,33 @@ Message _withArgumentsInputFileNotFound(Uri uri_) {
56415641
arguments: {'uri': uri_});
56425642
}
56435643

5644+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
5645+
const Template<
5646+
Message Function(
5647+
String
5648+
name)> templateInstanceAndSynthesizedStaticConflict = const Template<
5649+
Message Function(String name)>(
5650+
problemMessageTemplate:
5651+
r"""This instance member conflicts with the synthesized static member called '#name'.""",
5652+
withArguments: _withArgumentsInstanceAndSynthesizedStaticConflict);
5653+
5654+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
5655+
const Code<Message Function(String name)>
5656+
codeInstanceAndSynthesizedStaticConflict =
5657+
const Code<Message Function(String name)>(
5658+
"InstanceAndSynthesizedStaticConflict",
5659+
analyzerCodes: <String>["CONFLICTING_STATIC_AND_INSTANCE"]);
5660+
5661+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
5662+
Message _withArgumentsInstanceAndSynthesizedStaticConflict(String name) {
5663+
if (name.isEmpty) throw 'No name provided';
5664+
name = demangleMixinApplicationName(name);
5665+
return new Message(codeInstanceAndSynthesizedStaticConflict,
5666+
problemMessage:
5667+
"""This instance member conflicts with the synthesized static member called '${name}'.""",
5668+
arguments: {'name': name});
5669+
}
5670+
56445671
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
56455672
const Template<Message Function(int count, int count2)>
56465673
templateInstantiationTooFewArguments =

pkg/front_end/lib/src/fasta/kernel/hierarchy/members_node.dart

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import '../../messages.dart'
3737
templateCantInferTypeDueToNoCombinedSignature,
3838
templateDuplicatedDeclaration,
3939
templateDuplicatedDeclarationCause,
40+
templateInstanceAndSynthesizedStaticConflict,
4041
templateMissingImplementationCause,
4142
templateMissingImplementationNotAbstract;
4243
import '../../names.dart' show noSuchMethodName;
@@ -531,12 +532,23 @@ class ClassMembersNodeBuilder {
531532
staticMember = b;
532533
instanceMember = a;
533534
}
534-
classBuilder.libraryBuilder.addProblem(messageStaticAndInstanceConflict,
535-
staticMember.charOffset, name.length, staticMember.fileUri,
536-
context: <LocatedMessage>[
537-
messageStaticAndInstanceConflictCause.withLocation(
538-
instanceMember.fileUri, instanceMember.charOffset, name.length)
539-
]);
535+
if (!staticMember.isSynthesized) {
536+
classBuilder.libraryBuilder.addProblem(messageStaticAndInstanceConflict,
537+
staticMember.charOffset, name.length, staticMember.fileUri,
538+
context: <LocatedMessage>[
539+
messageStaticAndInstanceConflictCause.withLocation(
540+
instanceMember.fileUri,
541+
instanceMember.charOffset,
542+
name.length)
543+
]);
544+
} else {
545+
classBuilder.libraryBuilder.addProblem(
546+
templateInstanceAndSynthesizedStaticConflict
547+
.withArguments(staticMember.name.text),
548+
instanceMember.charOffset,
549+
name.length,
550+
instanceMember.fileUri);
551+
}
540552
} else {
541553
// This message can be reported twice (when merging localMembers with
542554
// classSetters, or localSetters with classMembers). By ensuring that

pkg/front_end/lib/src/fasta/source/source_enum_builder.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ class SourceEnumBuilder extends SourceClassBuilder {
284284
staticFieldNameScheme,
285285
fieldReference: valuesFieldReference,
286286
fieldGetterReference: valuesGetterReference,
287-
fieldSetterReference: valuesSetterReference);
287+
fieldSetterReference: valuesSetterReference,
288+
isSynthesized: true);
288289
members["values"] = valuesBuilder;
289290

290291
DeclaredSourceConstructorBuilder? synthesizedDefaultConstructorBuilder;

pkg/front_end/lib/src/fasta/source/source_field_builder.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ class SourceFieldBuilder extends SourceMemberBuilderImpl
7070
@override
7171
final bool isTopLevel;
7272

73+
final bool isSynthesized;
74+
7375
SourceFieldBuilder(
7476
this.metadata,
7577
this.type,
@@ -88,7 +90,8 @@ class SourceFieldBuilder extends SourceMemberBuilderImpl
8890
Reference? lateIsSetSetterReference,
8991
Reference? lateGetterReference,
9092
Reference? lateSetterReference,
91-
Token? constInitializerToken})
93+
Token? constInitializerToken,
94+
this.isSynthesized = false})
9295
: _constInitializerToken = constInitializerToken,
9396
super(libraryBuilder, charOffset) {
9497
bool isInstanceMember = fieldNameScheme.isInstanceMember;
@@ -757,6 +760,9 @@ class SourceFieldMember extends BuilderClassMember {
757760
@override
758761
bool get isProperty => true;
759762

763+
@override
764+
bool get isSynthesized => memberBuilder.isSynthesized;
765+
760766
@override
761767
bool isSameDeclaration(ClassMember other) {
762768
return other is SourceFieldMember && memberBuilder == other.memberBuilder;

pkg/front_end/messages.status

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ InitializerForStaticField/example: Fail
475475
InitializerOutsideConstructor/example: Fail
476476
InputFileNotFound/analyzerCode: Fail
477477
InputFileNotFound/example: Fail
478+
InstanceAndSynthesizedStaticConflict/example: Fail
478479
InstantiationNonGenericFunctionType/analyzerCode: Fail
479480
InstantiationTooFewArguments/analyzerCode: Fail
480481
InstantiationTooManyArguments/analyzerCode: Fail

pkg/front_end/messages.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4597,6 +4597,10 @@ StaticAndInstanceConflictCause:
45974597
problemMessage: "This is the instance member."
45984598
severity: CONTEXT
45994599

4600+
InstanceAndSynthesizedStaticConflict:
4601+
problemMessage: "This instance member conflicts with the synthesized static member called '#name'."
4602+
analyzerCode: CONFLICTING_STATIC_AND_INSTANCE
4603+
46004604
FfiAbiSpecificIntegerInvalid:
46014605
# Used by dart:ffi
46024606
problemMessage: "Classes extending 'AbiSpecificInteger' must have exactly one const constructor, no other members, and no type arguments."
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+
enum E {
6+
e1,
7+
e2;
8+
9+
void set values(List<E> val) {} // Error.
10+
}
11+
12+
main() {}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
library /*isNonNullableByDefault*/;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/enhanced_enums/member_values_conflicts.dart:9:12: Error: This instance member conflicts with the synthesized static member called 'values'.
6+
// void set values(List<E> val) {} // Error.
7+
// ^^^^^^
8+
//
9+
import self as self;
10+
import "dart:core" as core;
11+
12+
class E extends core::_Enum /*isEnum*/ {
13+
static const field core::List<self::E> values = #C7;
14+
static const field self::E e1 = #C3;
15+
static const field self::E e2 = #C6;
16+
const constructor •(core::int index, core::String name) → self::E
17+
: super core::_Enum::•(index, name)
18+
;
19+
method toString() → core::String
20+
return "E.${this.{core::_Enum::_name}{core::String}}";
21+
set values(core::List<self::E> val) → void {}
22+
}
23+
static method main() → dynamic {}
24+
25+
constants {
26+
#C1 = 0
27+
#C2 = "e1"
28+
#C3 = self::E {index:#C1, _name:#C2}
29+
#C4 = 1
30+
#C5 = "e2"
31+
#C6 = self::E {index:#C4, _name:#C5}
32+
#C7 = <self::E>[#C3, #C6]
33+
}
34+
35+
36+
Constructor coverage from constants:
37+
org-dartlang-testcase:///member_values_conflicts.dart:
38+
- E. (from org-dartlang-testcase:///member_values_conflicts.dart:5:6)
39+
- _Enum. (from org-dartlang-sdk:///sdk/lib/core/enum.dart:103:9)
40+
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
library /*isNonNullableByDefault*/;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/enhanced_enums/member_values_conflicts.dart:9:12: Error: This instance member conflicts with the synthesized static member called 'values'.
6+
// void set values(List<E> val) {} // Error.
7+
// ^^^^^^
8+
//
9+
import self as self;
10+
import "dart:core" as core;
11+
12+
class E extends core::_Enum /*isEnum*/ {
13+
static const field core::List<self::E> values = #C7;
14+
static const field self::E e1 = #C3;
15+
static const field self::E e2 = #C6;
16+
const constructor •(core::int index, core::String name) → self::E
17+
: super core::_Enum::•(index, name)
18+
;
19+
method toString() → core::String
20+
return "E.${this.{core::_Enum::_name}{core::String}}";
21+
set values(core::List<self::E> val) → void {}
22+
}
23+
static method main() → dynamic {}
24+
25+
constants {
26+
#C1 = 0
27+
#C2 = "e1"
28+
#C3 = self::E {index:#C1, _name:#C2}
29+
#C4 = 1
30+
#C5 = "e2"
31+
#C6 = self::E {index:#C4, _name:#C5}
32+
#C7 = <self::E>[#C3, #C6]
33+
}
34+
35+
36+
Constructor coverage from constants:
37+
org-dartlang-testcase:///member_values_conflicts.dart:
38+
- E. (from org-dartlang-testcase:///member_values_conflicts.dart:5:6)
39+
- _Enum. (from org-dartlang-sdk:///sdk/lib/core/enum.dart:103:9)
40+
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
enum E {
2+
e1,
3+
e2;
4+
5+
void set values(List<E> val) {}
6+
}
7+
8+
main() {}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
enum E {
2+
e1,
3+
e2;
4+
5+
void set values(List<E> val) {}
6+
}
7+
8+
main() {}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
library /*isNonNullableByDefault*/;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/enhanced_enums/member_values_conflicts.dart:9:12: Error: This instance member conflicts with the synthesized static member called 'values'.
6+
// void set values(List<E> val) {} // Error.
7+
// ^^^^^^
8+
//
9+
import self as self;
10+
import "dart:core" as core;
11+
12+
class E extends core::_Enum /*isEnum*/ {
13+
static const field core::List<self::E> values = #C7;
14+
static const field self::E e1 = #C3;
15+
static const field self::E e2 = #C6;
16+
const constructor •(core::int index, core::String name) → self::E
17+
: super core::_Enum::•(index, name)
18+
;
19+
method toString() → core::String
20+
return "E.${this.{core::_Enum::_name}{core::String}}";
21+
set values(core::List<self::E> val) → void {}
22+
}
23+
static method main() → dynamic {}
24+
25+
constants {
26+
#C1 = 0
27+
#C2 = "e1"
28+
#C3 = self::E {index:#C1, _name:#C2}
29+
#C4 = 1
30+
#C5 = "e2"
31+
#C6 = self::E {index:#C4, _name:#C5}
32+
#C7 = <self::E*>[#C3, #C6]
33+
}
34+
35+
36+
Constructor coverage from constants:
37+
org-dartlang-testcase:///member_values_conflicts.dart:
38+
- E. (from org-dartlang-testcase:///member_values_conflicts.dart:5:6)
39+
- _Enum. (from org-dartlang-sdk:///sdk/lib/core/enum.dart:103:9)
40+
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
library /*isNonNullableByDefault*/;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/enhanced_enums/member_values_conflicts.dart:9:12: Error: This instance member conflicts with the synthesized static member called 'values'.
6+
// void set values(List<E> val) {} // Error.
7+
// ^^^^^^
8+
//
9+
import self as self;
10+
import "dart:core" as core;
11+
12+
class E extends core::_Enum /*isEnum*/ {
13+
static const field core::List<self::E> values = #C7;
14+
static const field self::E e1 = #C3;
15+
static const field self::E e2 = #C6;
16+
const constructor •(core::int index, core::String name) → self::E
17+
: super core::_Enum::•(index, name)
18+
;
19+
method toString() → core::String
20+
return "E.${this.{core::_Enum::_name}{core::String}}";
21+
set values(core::List<self::E> val) → void {}
22+
}
23+
static method main() → dynamic {}
24+
25+
constants {
26+
#C1 = 0
27+
#C2 = "e1"
28+
#C3 = self::E {index:#C1, _name:#C2}
29+
#C4 = 1
30+
#C5 = "e2"
31+
#C6 = self::E {index:#C4, _name:#C5}
32+
#C7 = <self::E*>[#C3, #C6]
33+
}
34+
35+
36+
Constructor coverage from constants:
37+
org-dartlang-testcase:///member_values_conflicts.dart:
38+
- E. (from org-dartlang-testcase:///member_values_conflicts.dart:5:6)
39+
- _Enum. (from org-dartlang-sdk:///sdk/lib/core/enum.dart:103:9)
40+
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
library /*isNonNullableByDefault*/;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/enhanced_enums/member_values_conflicts.dart:9:12: Error: This instance member conflicts with the synthesized static member called 'values'.
6+
// void set values(List<E> val) {} // Error.
7+
// ^^^^^^
8+
//
9+
import self as self;
10+
import "dart:core" as core;
11+
12+
class E extends core::_Enum /*isEnum*/ {
13+
static const field core::List<self::E> values = const <self::E>[self::E::e1, self::E::e2];
14+
static const field self::E e1 = const self::E::•(0, "e1");
15+
static const field self::E e2 = const self::E::•(1, "e2");
16+
const constructor •(core::int index, core::String name) → self::E
17+
: super core::_Enum::•(index, name)
18+
;
19+
method toString() → core::String
20+
return "E.${this.{core::_Enum::_name}{core::String}}";
21+
set values(core::List<self::E> val) → void
22+
;
23+
}
24+
static method main() → dynamic
25+
;
26+
27+
28+
Extra constant evaluation status:
29+
Evaluated: ListLiteral @ org-dartlang-testcase:///member_values_conflicts.dart:5:6 -> ListConstant(const <E*>[const E{_Enum.index: 0, _Enum._name: "e1"}, const E{_Enum.index: 1, _Enum._name: "e2"}])
30+
Evaluated: ConstructorInvocation @ org-dartlang-testcase:///member_values_conflicts.dart:6:3 -> InstanceConstant(const E{_Enum.index: 0, _Enum._name: "e1"})
31+
Evaluated: ConstructorInvocation @ org-dartlang-testcase:///member_values_conflicts.dart:7:3 -> InstanceConstant(const E{_Enum.index: 1, _Enum._name: "e2"})
32+
Extra constant evaluation: evaluated: 8, effectively constant: 3
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
library /*isNonNullableByDefault*/;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/enhanced_enums/member_values_conflicts.dart:9:12: Error: This instance member conflicts with the synthesized static member called 'values'.
6+
// void set values(List<E> val) {} // Error.
7+
// ^^^^^^
8+
//
9+
import self as self;
10+
import "dart:core" as core;
11+
12+
class E extends core::_Enum /*isEnum*/ {
13+
static const field core::List<self::E> values = #C7;
14+
static const field self::E e1 = #C3;
15+
static const field self::E e2 = #C6;
16+
const constructor •(core::int index, core::String name) → self::E
17+
: super core::_Enum::•(index, name)
18+
;
19+
method toString() → core::String
20+
return "E.${this.{core::_Enum::_name}{core::String}}";
21+
set values(core::List<self::E> val) → void {}
22+
}
23+
static method main() → dynamic {}
24+
25+
constants {
26+
#C1 = 0
27+
#C2 = "e1"
28+
#C3 = self::E {index:#C1, _name:#C2}
29+
#C4 = 1
30+
#C5 = "e2"
31+
#C6 = self::E {index:#C4, _name:#C5}
32+
#C7 = <self::E*>[#C3, #C6]
33+
}
34+
35+
36+
Constructor coverage from constants:
37+
org-dartlang-testcase:///member_values_conflicts.dart:
38+
- E. (from org-dartlang-testcase:///member_values_conflicts.dart:5:6)
39+
- _Enum. (from org-dartlang-sdk:///sdk/lib/core/enum.dart:103:9)
40+
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)

0 commit comments

Comments
 (0)