Improve the messaging around conflicting constructors
Fixes: https://github.com/dart-lang/sdk/issues/46803 Change-Id: I0435ea15cfb4c57dfb865f66d251afbe1d9459a6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/208921 Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
committed by
commit-bot@chromium.org
parent
86655608c0
commit
878cd3a3f8
@@ -95,7 +95,9 @@ const List<ErrorCode> errorCodeValues = [
|
||||
CompileTimeErrorCode.CAST_TO_NON_TYPE,
|
||||
CompileTimeErrorCode.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER,
|
||||
CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_AND_STATIC_FIELD,
|
||||
CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_AND_STATIC_GETTER,
|
||||
CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_AND_STATIC_METHOD,
|
||||
CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_AND_STATIC_SETTER,
|
||||
CompileTimeErrorCode.CONFLICTING_FIELD_AND_METHOD,
|
||||
CompileTimeErrorCode.CONFLICTING_GENERIC_INTERFACES,
|
||||
CompileTimeErrorCode.CONFLICTING_METHOD_AND_FIELD,
|
||||
|
||||
@@ -1565,7 +1565,7 @@ class CompileTimeErrorCode extends AnalyzerErrorCode {
|
||||
|
||||
/**
|
||||
* Parameters:
|
||||
* 0: the name of the field
|
||||
* 0: the name of the constructor and field
|
||||
*/
|
||||
// #### Description
|
||||
//
|
||||
@@ -1608,6 +1608,19 @@ class CompileTimeErrorCode extends AnalyzerErrorCode {
|
||||
hasPublishedDocs: true,
|
||||
uniqueName: 'CONFLICTING_CONSTRUCTOR_AND_STATIC_FIELD');
|
||||
|
||||
/**
|
||||
* Parameters:
|
||||
* 0: the name of the constructor and getter
|
||||
*/
|
||||
static const CompileTimeErrorCode CONFLICTING_CONSTRUCTOR_AND_STATIC_GETTER =
|
||||
CompileTimeErrorCode(
|
||||
'CONFLICTING_CONSTRUCTOR_AND_STATIC_MEMBER',
|
||||
"'{0}' can't be used to name both a constructor and a static getter "
|
||||
"in this class.",
|
||||
correction: "Try renaming either the constructor or the getter.",
|
||||
hasPublishedDocs: true,
|
||||
uniqueName: 'CONFLICTING_CONSTRUCTOR_AND_STATIC_GETTER');
|
||||
|
||||
/**
|
||||
* Parameters:
|
||||
* 0: the name of the constructor
|
||||
@@ -1621,6 +1634,19 @@ class CompileTimeErrorCode extends AnalyzerErrorCode {
|
||||
hasPublishedDocs: true,
|
||||
uniqueName: 'CONFLICTING_CONSTRUCTOR_AND_STATIC_METHOD');
|
||||
|
||||
/**
|
||||
* Parameters:
|
||||
* 0: the name of the constructor and setter
|
||||
*/
|
||||
static const CompileTimeErrorCode CONFLICTING_CONSTRUCTOR_AND_STATIC_SETTER =
|
||||
CompileTimeErrorCode(
|
||||
'CONFLICTING_CONSTRUCTOR_AND_STATIC_MEMBER',
|
||||
"'{0}' can't be used to name both a constructor and a static setter "
|
||||
"in this class.",
|
||||
correction: "Try renaming either the constructor or the setter.",
|
||||
hasPublishedDocs: true,
|
||||
uniqueName: 'CONFLICTING_CONSTRUCTOR_AND_STATIC_SETTER');
|
||||
|
||||
/**
|
||||
* 10.11 Class Member Conflicts: Let `C` be a class. It is a compile-time
|
||||
* error if `C` declares a getter or a setter with basename `n`, and has a
|
||||
|
||||
@@ -302,11 +302,18 @@ class DuplicateDefinitionVerifier {
|
||||
var staticMember = staticGetters[name] ?? staticSetters[name];
|
||||
if (staticMember != null) {
|
||||
if (staticMember is PropertyAccessorElement) {
|
||||
_errorReporter.reportErrorForNode(
|
||||
CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_AND_STATIC_FIELD,
|
||||
nameNode,
|
||||
[name],
|
||||
);
|
||||
CompileTimeErrorCode errorCode;
|
||||
if (staticMember.isSynthetic) {
|
||||
errorCode = CompileTimeErrorCode
|
||||
.CONFLICTING_CONSTRUCTOR_AND_STATIC_FIELD;
|
||||
} else if (staticMember.isGetter) {
|
||||
errorCode = CompileTimeErrorCode
|
||||
.CONFLICTING_CONSTRUCTOR_AND_STATIC_GETTER;
|
||||
} else {
|
||||
errorCode = CompileTimeErrorCode
|
||||
.CONFLICTING_CONSTRUCTOR_AND_STATIC_SETTER;
|
||||
}
|
||||
_errorReporter.reportErrorForNode(errorCode, nameNode, [name]);
|
||||
} else {
|
||||
_errorReporter.reportErrorForNode(
|
||||
CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_AND_STATIC_METHOD,
|
||||
|
||||
@@ -180,8 +180,8 @@ class C {
|
||||
static int get foo => 0;
|
||||
}
|
||||
''', [
|
||||
error(
|
||||
CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_AND_STATIC_FIELD, 14, 3),
|
||||
error(CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_AND_STATIC_GETTER, 14,
|
||||
3),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -212,8 +212,8 @@ class C {
|
||||
static void set foo(_) {}
|
||||
}
|
||||
''', [
|
||||
error(
|
||||
CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_AND_STATIC_FIELD, 14, 3),
|
||||
error(CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_AND_STATIC_SETTER, 14,
|
||||
3),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -1845,9 +1845,15 @@ abstract class C {
|
||||
_'{0}' can't be used to name both a constructor and a static field in this
|
||||
class._
|
||||
|
||||
_'{0}' can't be used to name both a constructor and a static getter in this
|
||||
class._
|
||||
|
||||
_'{0}' can't be used to name both a constructor and a static method in this
|
||||
class._
|
||||
|
||||
_'{0}' can't be used to name both a constructor and a static setter in this
|
||||
class._
|
||||
|
||||
#### Description
|
||||
|
||||
The analyzer produces this diagnostic when a named constructor and either a
|
||||
|
||||
Reference in New Issue
Block a user