Skip to content

Commit 1c8007d

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Migrate BlockScope.
Change-Id: I5f536b2622ce1a2a300e383c88487bdb527a8b8d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/411088 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 0b10797 commit 1c8007d

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

pkg/analyzer/lib/src/dart/resolver/scope.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import 'package:analyzer/src/utilities/extensions/element.dart';
2020
class BlockScope {
2121
/// Return the elements that are declared directly in the given [statements].
2222
/// This does not include elements declared in nested blocks.
23-
static Iterable<Element> elementsInStatements(
23+
static Iterable<Element2> elementsInStatements(
2424
List<Statement> statements,
2525
) sync* {
2626
int statementCount = statements.length;
@@ -31,16 +31,16 @@ class BlockScope {
3131
}
3232
if (statement is PatternVariableDeclarationStatementImpl) {
3333
for (var variable in statement.declaration.elements) {
34-
yield variable;
34+
yield variable.asElement2;
3535
}
3636
} else if (statement is VariableDeclarationStatement) {
3737
NodeList<VariableDeclaration> variables = statement.variables.variables;
3838
int variableCount = variables.length;
3939
for (int j = 0; j < variableCount; j++) {
40-
yield variables[j].declaredElement!;
40+
yield variables[j].declaredFragment!.element;
4141
}
4242
} else if (statement is FunctionDeclarationStatement) {
43-
yield statement.functionDeclaration.declaredElement!;
43+
yield statement.functionDeclaration.declaredFragment!.element;
4444
}
4545
}
4646
}

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -944,14 +944,14 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
944944

945945
@override
946946
void visitFunctionDeclaration(covariant FunctionDeclarationImpl node) {
947-
var fragment = node.declaredFragment!;
948-
var element = node.declaredElement!;
949-
if (element.enclosingElement3 is! CompilationUnitElement) {
947+
var fragment = node.declaredFragment!;
948+
var element = fragment.element;
949+
if (element.enclosingElement2 is! LibraryElement2) {
950950
_hiddenElements!.declare(element);
951951
}
952952

953953
_withEnclosingExecutable(
954-
element.asElement2,
954+
element,
955955
() {
956956
TypeAnnotation? returnType = node.returnType;
957957
if (node.isSetter) {
@@ -962,11 +962,11 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
962962
}
963963
_checkForTypeAnnotationDeferredClass(returnType);
964964
_returnTypeVerifier.verifyReturnType(returnType);
965-
_checkForMainFunction1(node.name, element);
965+
_checkForMainFunction1(node.name, fragment);
966966
_checkForMainFunction2(node);
967967
_checkAugmentations(
968968
augmentKeyword: node.augmentKeyword,
969-
element: element,
969+
element: fragment,
970970
);
971971
super.visitFunctionDeclaration(node);
972972
},
@@ -1326,7 +1326,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
13261326
) {
13271327
super.visitPatternVariableDeclarationStatement(node);
13281328
for (var variable in node.declaration.elements) {
1329-
_hiddenElements?.declare(variable);
1329+
_hiddenElements?.declare(variable.asElement2);
13301330
}
13311331
}
13321332

@@ -1642,7 +1642,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
16421642
AstNode grandparent = node.parent!.parent!;
16431643
if (grandparent is! TopLevelVariableDeclaration &&
16441644
grandparent is! FieldDeclaration) {
1645-
VariableElement element = node.declaredElement!;
1645+
var element = node.declaredFragment!.element;
16461646
// There is no hidden elements if we are outside of a function body,
16471647
// which will happen for variables declared in control flow elements.
16481648
_hiddenElements?.declare(element);
@@ -5194,7 +5194,8 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
51945194
}) {
51955195
if (element != null &&
51965196
_hiddenElements != null &&
5197-
_hiddenElements!.contains(element.asElement!)) {
5197+
_hiddenElements!.contains(element)) {
5198+
_hiddenElements!.contains(element);
51985199
errorReporter.reportError(
51995200
DiagnosticFactory().referencedBeforeDeclaration(
52005201
errorReporter.source,
@@ -6584,7 +6585,7 @@ class HiddenElements {
65846585

65856586
/// A set containing the elements that will be declared in this scope, but are
65866587
/// not yet declared.
6587-
final Set<Element> _elements = HashSet<Element>();
6588+
final Set<Element2> _elements = {};
65886589

65896590
/// Initialize a newly created set of hidden elements to include all of the
65906591
/// elements defined in the set of [outerElements] and all of the elements
@@ -6600,11 +6601,11 @@ class HiddenElements {
66006601
this.outerElements,
66016602
GuardedPatternImpl guardedPattern,
66026603
) {
6603-
_elements.addAll(guardedPattern.variables.values.map((e) => e.asElement!));
6604+
_elements.addAll(guardedPattern.variables.values);
66046605
}
66056606

66066607
/// Return `true` if this set of elements contains the given [element].
6607-
bool contains(Element element) {
6608+
bool contains(Element2 element) {
66086609
if (_elements.contains(element)) {
66096610
return true;
66106611
} else if (outerElements != null) {
@@ -6615,7 +6616,7 @@ class HiddenElements {
66156616

66166617
/// Record that the given [element] has been declared, so it is no longer
66176618
/// hidden.
6618-
void declare(Element element) {
6619+
void declare(Element2 element) {
66196620
_elements.remove(element);
66206621
}
66216622

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5500,8 +5500,8 @@ class ScopeResolverVisitor extends UnifyingAstVisitor<void> {
55005500
try {
55015501
var enclosedScope = LocalScope(nameScope);
55025502
for (var statement in BlockScope.elementsInStatements(statements)) {
5503-
if (!statement.isWildcardFunction) {
5504-
enclosedScope.add(statement.asElement2!);
5503+
if (!statement.asElement!.isWildcardFunction) {
5504+
enclosedScope.add(statement);
55055505
}
55065506
}
55075507

0 commit comments

Comments
 (0)