Skip to content

Commit b755ee7

Browse files
pqCommit Queue
authored andcommitted
[element model] migrate error_verifier (constructor verifications)
Change-Id: I6cd7761b8af63597d3fc69c231139c16f96c9dd6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/409563 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Phil Quitslund <[email protected]>
1 parent 0275121 commit b755ee7

File tree

1 file changed

+35
-34
lines changed

1 file changed

+35
-34
lines changed

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

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -602,8 +602,9 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
602602
void visitConstructorDeclaration(
603603
covariant ConstructorDeclarationImpl node,
604604
) {
605-
var element = node.declaredElement!;
606-
_withEnclosingExecutable(element, () {
605+
var fragment = node.declaredFragment!;
606+
var element = fragment.element;
607+
_withEnclosingExecutable2(element, () {
607608
_checkForNonConstGenerativeEnumConstructor(node);
608609
_checkForInvalidModifierOnBody(
609610
node.body, CompileTimeErrorCode.INVALID_MODIFIER_ON_CONSTRUCTOR);
@@ -620,7 +621,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
620621
_checkForReturnInGenerativeConstructor(node);
621622
_checkAugmentations(
622623
augmentKeyword: node.augmentKeyword,
623-
element: element,
624+
element: fragment,
624625
);
625626
super.visitConstructorDeclaration(node);
626627
});
@@ -631,11 +632,11 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
631632
_isInConstructorInitializer = true;
632633
try {
633634
SimpleIdentifier fieldName = node.fieldName;
634-
var staticElement = fieldName.staticElement;
635-
_checkForInvalidField(node, fieldName, staticElement);
636-
if (staticElement is FieldElement) {
635+
var element = fieldName.element;
636+
_checkForInvalidField(node, fieldName, element);
637+
if (element is FieldElement2) {
637638
_checkForAbstractOrExternalFieldConstructorInitializer(
638-
node.fieldName.token, staticElement);
639+
node.fieldName.token, element);
639640
}
640641
super.visitConstructorFieldInitializer(node);
641642
} finally {
@@ -914,13 +915,10 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
914915
_checkForPrivateOptionalParameter(node);
915916
_checkForFieldInitializingFormalRedirectingConstructor(node);
916917
_checkForTypeAnnotationDeferredClass(node.type);
917-
ParameterElement element = node.declaredElement!;
918-
if (element is FieldFormalParameterElement) {
919-
var fieldElement = element.field;
920-
if (fieldElement != null) {
921-
_checkForAbstractOrExternalFieldConstructorInitializer(
922-
node.name, fieldElement);
923-
}
918+
var fieldElement = node.declaredFragment?.element.field2;
919+
if (fieldElement != null) {
920+
_checkForAbstractOrExternalFieldConstructorInitializer(
921+
node.name, fieldElement);
924922
}
925923
super.visitFieldFormalParameter(node);
926924
}
@@ -1949,7 +1947,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
19491947
}
19501948

19511949
void _checkForAbstractOrExternalFieldConstructorInitializer(
1952-
Token identifier, FieldElement fieldElement) {
1950+
Token identifier, FieldElement2 fieldElement) {
19531951
if (fieldElement.isAbstract) {
19541952
errorReporter.atToken(
19551953
identifier,
@@ -2123,11 +2121,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
21232121
errorReporter.atNode(
21242122
directive.uri,
21252123
CompileTimeErrorCode.AMBIGUOUS_EXPORT,
2126-
arguments: [
2127-
name,
2128-
prevElement.library2!.firstFragment.source.uri,
2129-
element.library2!.firstFragment.source.uri
2130-
],
2124+
arguments: [name, prevElement.library2!.uri, element.library2!.uri],
21312125
);
21322126
return;
21332127
} else {
@@ -2920,16 +2914,16 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
29202914
/// constructor element.
29212915
void _checkForConstConstructorWithNonFinalField(
29222916
ConstructorDeclaration constructor,
2923-
ConstructorElement constructorElement) {
2917+
ConstructorElement2 constructorElement) {
29242918
if (!_enclosingExecutable.isConstConstructor) {
29252919
return;
29262920
}
29272921
if (!_enclosingExecutable.isGenerativeConstructor) {
29282922
return;
29292923
}
29302924
// check if there is non-final field
2931-
var classElement = constructorElement.enclosingElement3;
2932-
if (classElement is! ClassElement || !classElement.hasNonFinalField) {
2925+
var classElement = constructorElement.enclosingElement2;
2926+
if (classElement is! ClassElement2 || !classElement.hasNonFinalField) {
29332927
return;
29342928
}
29352929
errorReporter.atConstructorDeclaration(
@@ -3959,8 +3953,8 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
39593953
/// [ConstructorFieldInitializer]. The [staticElement] is the static element
39603954
/// from the name in the [ConstructorFieldInitializer].
39613955
void _checkForInvalidField(ConstructorFieldInitializer initializer,
3962-
SimpleIdentifier fieldName, Element? staticElement) {
3963-
if (staticElement is FieldElement) {
3956+
SimpleIdentifier fieldName, Element2? staticElement) {
3957+
if (staticElement is FieldElement2) {
39643958
if (staticElement.isSynthetic) {
39653959
errorReporter.atNode(
39663960
initializer,
@@ -5081,7 +5075,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
50815075
///
50825076
/// See [CompileTimeErrorCode.RECURSIVE_CONSTRUCTOR_REDIRECT].
50835077
void _checkForRecursiveConstructorRedirect(ConstructorDeclaration declaration,
5084-
ConstructorElement constructorElement) {
5078+
ConstructorElement2 constructorElement) {
50855079
// we check generative constructor here
50865080
if (declaration.factoryKeyword != null) {
50875081
return;
@@ -5107,7 +5101,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
51075101
///
51085102
/// See [CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT].
51095103
bool _checkForRecursiveFactoryRedirect(
5110-
ConstructorDeclaration declaration, ConstructorElement element) {
5104+
ConstructorDeclaration declaration, ConstructorElement2 element) {
51115105
// prepare redirected constructor
51125106
var redirectedConstructorNode = declaration.redirectedConstructor;
51135107
if (redirectedConstructorNode == null) {
@@ -6134,7 +6128,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
61346128
/// Checks the class for problems with the superclass, mixins, or implemented
61356129
/// interfaces.
61366130
void _checkMixinInheritance(
6137-
MixinElementImpl declarationElement,
6131+
MixinElementImpl declarationFragment,
61386132
MixinDeclaration node,
61396133
MixinOnClause? onClause,
61406134
ImplementsClause? implementsClause) {
@@ -6144,12 +6138,12 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
61446138
!_checkForImplementsClauseErrorCodes(implementsClause)) {
61456139
// _checkForImplicitDynamicType(superclass);
61466140
_checkForRepeatedType(
6147-
libraryContext.setOfOn(declarationElement.asElement2),
6141+
libraryContext.setOfOn(declarationFragment.asElement2),
61486142
onClause?.superclassConstraints,
61496143
CompileTimeErrorCode.ON_REPEATED,
61506144
);
61516145
_checkForRepeatedType(
6152-
libraryContext.setOfImplements(declarationElement.asElement2),
6146+
libraryContext.setOfImplements(declarationFragment.asElement2),
61536147
implementsClause?.interfaces,
61546148
CompileTimeErrorCode.IMPLEMENTS_REPEATED,
61556149
);
@@ -6372,15 +6366,15 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
63726366

63736367
/// Return `true` if the given [constructor] redirects to itself, directly or
63746368
/// indirectly.
6375-
bool _hasRedirectingFactoryConstructorCycle(ConstructorElement constructor) {
6376-
Set<ConstructorElement> constructors = HashSet<ConstructorElement>();
6377-
ConstructorElement? current = constructor;
6369+
bool _hasRedirectingFactoryConstructorCycle(ConstructorElement2 constructor) {
6370+
Set<ConstructorElement2> constructors = HashSet<ConstructorElement2>();
6371+
ConstructorElement2? current = constructor;
63786372
while (current != null) {
63796373
if (constructors.contains(current)) {
63806374
return identical(current, constructor);
63816375
}
63826376
constructors.add(current);
6383-
current = current.redirectedConstructor?.declaration;
6377+
current = current.redirectedConstructor2?.baseElement;
63846378
}
63856379
return false;
63866380
}
@@ -6495,6 +6489,13 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
64956489
}
64966490
}
64976491

6492+
void _withEnclosingExecutable2(
6493+
ExecutableElement2 element,
6494+
void Function() operation,
6495+
) {
6496+
_withEnclosingExecutable(element.asElement, operation);
6497+
}
6498+
64986499
void _withHiddenElements(List<Statement> statements, void Function() f) {
64996500
_hiddenElements = HiddenElements(_hiddenElements, statements);
65006501
try {

0 commit comments

Comments
 (0)