Skip to content

Commit 9eb648a

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Compute class flags on ClassElementImpl
Move class-related flags off fragments and compute them directly on `ClassElementImpl`. This reduces coupling to fragments and avoids duplicated logic. Changes: - Compute `isConstructable` as `!isSealed && !isAbstract` instead of delegating to `_firstFragment`. - Compute `isExhaustive` as `isSealed`. - Remove `hasGenerativeConstConstructor`, `isConstructable`, and `isExhaustive` getters from `ClassFragmentImpl`. - In constant verifier, resolve the enclosing class via `container.declaredFragment!.element` and check `ClassElementImpl` rather than fragment types. Why: - Centralizes flag computation on the element, making semantics clearer. - Decreases fragment dependencies and maintenance surface. Change-Id: I4b7153a4a55037e6dc12e18a32161a3472902eeb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/446008 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 68ec39f commit 9eb648a

File tree

2 files changed

+4
-13
lines changed

2 files changed

+4
-13
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,8 +1661,8 @@ extension on Expression {
16611661
!declarationListParent.isStatic) {
16621662
var container = declarationListParent.parent;
16631663
if (container is ClassDeclaration) {
1664-
var enclosingClass = container.declaredFragment;
1665-
if (enclosingClass is ClassFragmentImpl) {
1664+
var enclosingClass = container.declaredFragment!.element;
1665+
if (enclosingClass is ClassElementImpl) {
16661666
// A field initializer of a class with at least one generative
16671667
// const constructor does not constitute a constant context, but
16681668
// must be a constant expression.

pkg/analyzer/lib/src/dart/element/element.dart

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ class ClassElementImpl extends InterfaceElementImpl implements ClassElement {
250250

251251
@override
252252
@trackedIncludedInId
253-
bool get isConstructable => _firstFragment.isConstructable;
253+
bool get isConstructable => !isSealed && !isAbstract;
254254

255255
@override
256256
@trackedIncludedInId
@@ -277,7 +277,7 @@ class ClassElementImpl extends InterfaceElementImpl implements ClassElement {
277277

278278
@override
279279
@trackedIncludedInId
280-
bool get isExhaustive => _firstFragment.isExhaustive;
280+
bool get isExhaustive => isSealed;
281281

282282
@override
283283
bool get isExtendableOutside => !isInterface && !isFinal && !isSealed;
@@ -559,15 +559,6 @@ class ClassFragmentImpl extends InterfaceFragmentImpl
559559
/// given [offset] in the file that contains the declaration of this element.
560560
ClassFragmentImpl({required super.name});
561561

562-
bool get hasGenerativeConstConstructor {
563-
_ClassFragmentImplModifiers.hasExtendsClause;
564-
return constructors.any((c) => !c.isFactory && c.isConst);
565-
}
566-
567-
bool get isConstructable => !isSealed && !isAbstract;
568-
569-
bool get isExhaustive => isSealed;
570-
571562
@override
572563
ClassFragmentImpl? get nextFragment {
573564
return super.nextFragment as ClassFragmentImpl?;

0 commit comments

Comments
 (0)