Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit fd27fda

Browse files
author
Dart CI
committed
Version 2.17.0-57.0.dev
Merge commit 'e3a2e59f18d667978c1ed65be6ad3f70e938a369' into 'dev'
2 parents ef3156b + e3a2e59 commit fd27fda

File tree

5 files changed

+37
-21
lines changed

5 files changed

+37
-21
lines changed

pkg/analysis_server/lib/src/services/completion/dart/not_imported_contributor.dart

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class NotImportedContributor extends DartCompletionContributor {
9292
}
9393

9494
extensionContributor.addExtensions(
95-
exportElements.whereType<ExtensionElement>().toList(),
95+
_extensions(exportElements),
9696
);
9797

9898
builder.isNotImportedLibrary = false;
@@ -109,4 +109,17 @@ class NotImportedContributor extends DartCompletionContributor {
109109
}
110110
}
111111
}
112+
113+
/// This function intentionally does not use `whereType` for performance.
114+
///
115+
/// https://github.com/dart-lang/sdk/issues/47680
116+
static List<ExtensionElement> _extensions(List<Element> elements) {
117+
var extensions = <ExtensionElement>[];
118+
for (var element in elements) {
119+
if (element is ExtensionElement) {
120+
extensions.add(element);
121+
}
122+
}
123+
return extensions;
124+
}
112125
}

pkg/analyzer/lib/src/dart/ast/extensions.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,21 @@ DartType? _writeType(AstNode node) {
7676
return null;
7777
}
7878

79+
extension AstNodeNullableExtension on AstNode? {
80+
List<ClassMember> get classMembers {
81+
final self = this;
82+
if (self is ClassOrMixinDeclaration) {
83+
return self.members;
84+
} else if (self is EnumDeclaration) {
85+
return self.members;
86+
} else if (self is ExtensionDeclaration) {
87+
return self.members;
88+
} else {
89+
throw UnimplementedError('(${self.runtimeType}) $self');
90+
}
91+
}
92+
}
93+
7994
extension ConstructorDeclarationExtension on ConstructorDeclaration {
8095
bool get isNonRedirectingGenerative {
8196
// Must be generative.

pkg/analyzer/lib/src/dart/constant/constant_verifier.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ class ConstantVerifier extends RecursiveAstVisitor<void> {
103103
if (constKeyword != null) {
104104
_validateConstructorInitializers(node);
105105
if (node.factoryKeyword == null) {
106-
_validateFieldInitializers(
107-
node.parent as ClassOrMixinDeclaration, constKeyword);
106+
_validateFieldInitializers(node.parent.classMembers, constKeyword);
108107
}
109108
}
110109
_validateDefaultValues(node.parameters);
@@ -545,12 +544,11 @@ class ConstantVerifier extends RecursiveAstVisitor<void> {
545544
}
546545

547546
/// Validates that the expressions of any field initializers in
548-
/// [classDeclaration] are all compile-time constants. Since this is only
547+
/// [members] are all compile-time constants. Since this is only
549548
/// required if the class has a constant constructor, the error is reported at
550549
/// [constKeyword], the const keyword on such a constant constructor.
551550
void _validateFieldInitializers(
552-
ClassOrMixinDeclaration classDeclaration, Token constKeyword) {
553-
NodeList<ClassMember> members = classDeclaration.members;
551+
List<ClassMember> members, Token constKeyword) {
554552
for (ClassMember member in members) {
555553
if (member is FieldDeclaration && !member.isStatic) {
556554
for (VariableDeclaration variableDeclaration

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

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
202202

203203
/// The class containing the AST nodes being visited, or `null` if we are not
204204
/// in the scope of a class.
205-
ClassElementImpl? _enclosingClass;
206-
207-
/// The enum containing the AST nodes being visited, or `null` if we are not
208-
/// in the scope of an enum.
209-
ClassElement? _enclosingEnum;
205+
ClassElement? _enclosingClass;
210206

211207
/// The element of the extension being visited, or `null` if we are not
212208
/// in the scope of an extension.
@@ -281,11 +277,8 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
281277
/// should not be modified in the middle of visiting a tree and requires an
282278
/// analyzer-provided Impl instance to work.
283279
set enclosingClass(ClassElement? classElement) {
284-
assert(classElement is ClassElementImpl);
285280
assert(_enclosingClass == null);
286-
assert(_enclosingEnum == null);
287281
assert(_enclosingExecutable.element == null);
288-
_enclosingClass = classElement as ClassElementImpl;
289282
}
290283

291284
/// The language team is thinking about adding abstract fields, or external
@@ -563,13 +556,13 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
563556

564557
@override
565558
void visitEnumDeclaration(EnumDeclaration node) {
566-
var outerEnum = _enclosingEnum;
559+
var outerClass = _enclosingClass;
567560
try {
568-
_enclosingEnum = node.declaredElement;
561+
_enclosingClass = node.declaredElement;
569562
_duplicateDefinitionVerifier.checkEnum(node);
570563
super.visitEnumDeclaration(node);
571564
} finally {
572-
_enclosingEnum = outerEnum;
565+
_enclosingClass = outerClass;
573566
}
574567
}
575568

@@ -4408,9 +4401,6 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
44084401
if (identical(enclosingElement, _enclosingClass)) {
44094402
return;
44104403
}
4411-
if (identical(enclosingElement, _enclosingEnum)) {
4412-
return;
4413-
}
44144404
if (enclosingElement is! ClassElement) {
44154405
return;
44164406
}

tools/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ CHANNEL dev
2727
MAJOR 2
2828
MINOR 17
2929
PATCH 0
30-
PRERELEASE 56
30+
PRERELEASE 57
3131
PRERELEASE_PATCH 0

0 commit comments

Comments
 (0)