Report CONFLICTING_TYPE_VARIABLE_AND_MEMBER_CLASS for constructors.
Bug: https://github.com/dart-lang/sdk/issues/48053 Change-Id: I7ff88565e72db50d3ed25f4ce2907f5ff4f3a652 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/226284 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
committed by
Commit Bot
parent
57fdc16b7b
commit
0453a47fa2
@@ -1779,23 +1779,23 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
|
||||
}
|
||||
|
||||
/// Verify all conflicts between type variable and enclosing class.
|
||||
/// TODO(scheglov)
|
||||
void _checkForConflictingClassTypeVariableErrorCodes() {
|
||||
for (TypeParameterElement typeParameter
|
||||
in _enclosingClass!.typeParameters) {
|
||||
var enclosingClass = _enclosingClass!;
|
||||
for (TypeParameterElement typeParameter in enclosingClass.typeParameters) {
|
||||
String name = typeParameter.name;
|
||||
// name is same as the name of the enclosing class
|
||||
if (_enclosingClass!.name == name) {
|
||||
var code = _enclosingClass!.isMixin
|
||||
if (enclosingClass.name == name) {
|
||||
var code = enclosingClass.isMixin
|
||||
? CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MIXIN
|
||||
: CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_CLASS;
|
||||
errorReporter.reportErrorForElement(code, typeParameter, [name]);
|
||||
}
|
||||
// check members
|
||||
if (_enclosingClass!.getMethod(name) != null ||
|
||||
_enclosingClass!.getGetter(name) != null ||
|
||||
_enclosingClass!.getSetter(name) != null) {
|
||||
var code = _enclosingClass!.isMixin
|
||||
if (enclosingClass.getNamedConstructor(name) != null ||
|
||||
enclosingClass.getMethod(name) != null ||
|
||||
enclosingClass.getGetter(name) != null ||
|
||||
enclosingClass.getSetter(name) != null) {
|
||||
var code = enclosingClass.isMixin
|
||||
? CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER_MIXIN
|
||||
: CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER_CLASS;
|
||||
errorReporter.reportErrorForElement(code, typeParameter, [name]);
|
||||
|
||||
@@ -18,6 +18,17 @@ main() {
|
||||
@reflectiveTest
|
||||
class ConflictingTypeVariableAndMemberClassTest
|
||||
extends PubPackageResolutionTest {
|
||||
test_constructor() async {
|
||||
await assertErrorsInCode(r'''
|
||||
class A<T> {
|
||||
A.T();
|
||||
}
|
||||
''', [
|
||||
error(CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER_CLASS, 8,
|
||||
1),
|
||||
]);
|
||||
}
|
||||
|
||||
test_field() async {
|
||||
await assertErrorsInCode(r'''
|
||||
class A<T> {
|
||||
|
||||
Reference in New Issue
Block a user