Skip to content

Commit 2780020

Browse files
pqCommit Queue
authored andcommitted
[element model] migrate error_verifier (more checks)
Change-Id: I2f5e4a337d89df4c593b1ff1dcd408e8c0a25116 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/410920 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Phil Quitslund <[email protected]>
1 parent c9a3dd7 commit 2780020

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

pkg/analyzer/lib/src/generated/error_verifier.dart

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
11001100
void visitImportPrefixReference(ImportPrefixReference node) {
11011101
_checkForReferenceBeforeDeclaration(
11021102
nameToken: node.name,
1103-
element: node.element,
1103+
element: node.element2,
11041104
);
11051105
}
11061106

@@ -1448,7 +1448,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
14481448
);
14491449
_checkForReferenceBeforeDeclaration(
14501450
nameToken: node.token,
1451-
element: node.staticElement,
1451+
element: node.element,
14521452
);
14531453
_checkForInvalidInstanceMemberAccess(node);
14541454
_checkForTypeParameterReferencedByStatic(
@@ -1490,7 +1490,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
14901490
void visitSuperFormalParameter(SuperFormalParameter node) {
14911491
super.visitSuperFormalParameter(node);
14921492

1493-
if (_enclosingClass is ExtensionTypeElement) {
1493+
if (_enclosingClass2 is ExtensionTypeElement2) {
14941494
errorReporter.atToken(
14951495
node.superKeyword,
14961496
CompileTimeErrorCode
@@ -1509,8 +1509,9 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
15091509
return;
15101510
}
15111511

1512-
var element = node.declaredElement as SuperFormalParameterElementImpl;
1513-
var superParameter = element.superConstructorParameter;
1512+
var element =
1513+
node.declaredFragment?.element as SuperFormalParameterElementImpl2;
1514+
var superParameter = element.superConstructorParameter2;
15141515

15151516
if (superParameter == null) {
15161517
errorReporter.atToken(
@@ -5198,16 +5199,16 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
51985199

51995200
void _checkForReferenceBeforeDeclaration({
52005201
required Token nameToken,
5201-
required Element? element,
5202+
required Element2? element,
52025203
}) {
52035204
if (element != null &&
52045205
_hiddenElements != null &&
5205-
_hiddenElements!.contains(element)) {
5206+
_hiddenElements!.contains(element.asElement!)) {
52065207
errorReporter.reportError(
52075208
DiagnosticFactory().referencedBeforeDeclaration(
52085209
errorReporter.source,
52095210
nameToken: nameToken,
5210-
element2: element.asElement2!,
5211+
element2: element,
52115212
),
52125213
);
52135214
}
@@ -5424,13 +5425,13 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
54245425
///
54255426
/// See [CompileTimeErrorCode.TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND].
54265427
void _checkForTypeParameterBoundRecursion(List<TypeParameter> parameters) {
5427-
Map<TypeParameterElement, TypeParameter>? elementToNode;
5428+
Map<TypeParameterElement2, TypeParameter>? elementToNode;
54285429
for (var parameter in parameters) {
54295430
if (parameter.bound != null) {
54305431
if (elementToNode == null) {
54315432
elementToNode = {};
54325433
for (var parameter in parameters) {
5433-
elementToNode[parameter.declaredElement!] = parameter;
5434+
elementToNode[parameter.declaredFragment!.element] = parameter;
54345435
}
54355436
}
54365437

@@ -5440,12 +5441,12 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
54405441
if (boundNode is NamedType) {
54415442
var boundType = boundNode.typeOrThrow;
54425443
boundType = boundType.extensionTypeErasure;
5443-
current = elementToNode[boundType.element];
5444+
current = elementToNode[boundType.element3];
54445445
} else {
54455446
current = null;
54465447
}
54475448
if (step == parameters.length) {
5448-
var element = parameter.declaredElement!;
5449+
var element = parameter.declaredFragment!.element;
54495450
// This error can only occur if there is a bound, so we can safely
54505451
// assume `element.bound` is non-`null`.
54515452
errorReporter.atToken(
@@ -5716,31 +5717,31 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
57165717
/// [CompileTimeErrorCode.UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER].
57175718
void _checkForUnqualifiedReferenceToNonLocalStaticMember(
57185719
SimpleIdentifier name) {
5719-
var element = name.writeOrReadElement;
5720-
if (element == null || element is TypeParameterElement) {
5720+
var element = name.writeOrReadElement2;
5721+
if (element == null || element is TypeParameterElement2) {
57215722
return;
57225723
}
57235724

5724-
var enclosingElement = element.enclosingElement3;
5725+
var enclosingElement = element.enclosingElement2;
57255726
if (enclosingElement == null) {
57265727
return;
57275728
}
57285729

5729-
if (identical(enclosingElement.augmentedDeclaration, _enclosingClass)) {
5730+
if (identical(enclosingElement, _enclosingClass2)) {
57305731
return;
57315732
}
5732-
if (enclosingElement is! InterfaceElement) {
5733+
if (enclosingElement is! InterfaceElement2) {
57335734
return;
57345735
}
5735-
if (element is ExecutableElement && !element.isStatic) {
5736+
if (element is ExecutableElement2 && !element.isStatic) {
57365737
return;
57375738
}
5738-
if (element is MethodElement) {
5739+
if (element is MethodElement2) {
57395740
// Invalid methods are reported in
57405741
// [MethodInvocationResolver._resolveReceiverNull].
57415742
return;
57425743
}
5743-
if (_enclosingExtension != null) {
5744+
if (_enclosingExtension2 != null) {
57445745
errorReporter.atNode(
57455746
name,
57465747
CompileTimeErrorCode
@@ -5762,18 +5763,18 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
57625763
parent2?.parent is! ConstructorDeclaration) {
57635764
return;
57645765
}
5765-
ParameterElement element = parameter.declaredElement!;
5766-
if (element is FieldFormalParameterElement) {
5767-
var fieldElement = element.field;
5766+
var element = parameter.declaredFragment?.element;
5767+
if (element is FieldFormalParameterElement2) {
5768+
var fieldElement = element.field2;
57685769
if (fieldElement == null || fieldElement.isSynthetic) {
57695770
errorReporter.atNode(
57705771
parameter,
57715772
CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD,
57725773
arguments: [parameter.name.lexeme],
57735774
);
57745775
} else {
5775-
var parameterElement = parameter.declaredElement!;
5776-
if (parameterElement is FieldFormalParameterElementImpl) {
5776+
var parameterElement = parameter.declaredFragment?.element;
5777+
if (parameterElement is FieldFormalParameterElement2) {
57775778
DartType declaredType = parameterElement.type;
57785779
DartType fieldType = fieldElement.type;
57795780
if (fieldElement.isSynthetic) {

0 commit comments

Comments
 (0)