Skip to content

Commit

Permalink
Elements. Add PropertyInducingElement2.hasInitializer
Browse files Browse the repository at this point in the history
Change-Id: I236a8fc6748fef8f6fa8b7d18066778e157c9c68
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/395682
Reviewed-by: Brian Wilkerson <[email protected]>
Commit-Queue: Konstantin Shcheglov <[email protected]>
  • Loading branch information
scheglov authored and Commit Queue committed Nov 15, 2024
1 parent 9468f60 commit 016310d
Show file tree
Hide file tree
Showing 25 changed files with 1,910 additions and 1,897 deletions.
3 changes: 3 additions & 0 deletions pkg/analyzer/lib/dart/element/element2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2102,6 +2102,9 @@ abstract class PropertyInducingElement2
/// getter associated with it will be synthetic.
GetterElement? get getter2;

/// Whether any fragment of this variable has an initializer at declaration.
bool get hasInitializer;

/// The setter associated with this variable.
///
/// Returns `null` if the variable is effectively `final` and therefore does
Expand Down
17 changes: 12 additions & 5 deletions pkg/analyzer/lib/src/dart/element/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4172,8 +4172,8 @@ class FieldElementImpl extends PropertyInducingElementImpl

class FieldElementImpl2 extends PropertyInducingElementImpl2
with
FragmentedAnnotatableElementMixin<FieldFragment>,
FragmentedElementMixin<FieldFragment>
FragmentedAnnotatableElementMixin<FieldElementImpl>,
FragmentedElementMixin<FieldElementImpl>
implements FieldElement2 {
@override
final FieldElementImpl firstFragment;
Expand Down Expand Up @@ -9689,7 +9689,14 @@ abstract class PropertyInducingElementImpl
}

abstract class PropertyInducingElementImpl2 extends VariableElementImpl2
implements PropertyInducingElement2 {}
implements PropertyInducingElement2 {
@override
bool get hasInitializer {
return _fragments.any((f) => f.hasInitializer);
}

List<PropertyInducingElementImpl> get _fragments;
}

/// Instances of this class are set for fields and top-level variables
/// to perform top-level type inference during linking.
Expand Down Expand Up @@ -9967,8 +9974,8 @@ class TopLevelVariableElementImpl extends PropertyInducingElementImpl

class TopLevelVariableElementImpl2 extends PropertyInducingElementImpl2
with
FragmentedAnnotatableElementMixin<TopLevelVariableFragment>,
FragmentedElementMixin<TopLevelVariableFragment>
FragmentedAnnotatableElementMixin<TopLevelVariableElementImpl>,
FragmentedElementMixin<TopLevelVariableElementImpl>
implements TopLevelVariableElement2 {
@override
final Reference reference;
Expand Down
3 changes: 1 addition & 2 deletions pkg/analyzer/lib/src/error/constructor_fields_verifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ class ConstructorFieldsVerifier {
if (element is EnumElement2 && field.name3 == 'index') {
continue;
}
// TODO(scheglov): this is wrong
fieldMap[field] = field.firstFragment.hasInitializer
fieldMap[field] = field.hasInitializer
? _InitState.initInDeclaration
: _InitState.notInit;
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/analyzer/test/src/summary/element_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ class _Element2Writer extends _AbstractElementWriter {
_sink.writeIf(e.isConst, 'const ');
_sink.writeIf(e.isEnumConstant, 'enumConstant ');
_sink.writeIf(e.isPromotable, 'promotable ');
_sink.writeIf(e.hasInitializer, 'hasInitializer ');

_writeElementName(e);
});
Expand Down Expand Up @@ -550,6 +551,7 @@ class _Element2Writer extends _AbstractElementWriter {
_sink.writeIndentedLine(() {
_sink.writeIf(f.isAugmentation, 'augment ');
_sink.writeIf(f.isSynthetic, 'synthetic ');
_sink.writeIf(f.hasInitializer, 'hasInitializer ');

_writeFragmentName(f);
});
Expand Down Expand Up @@ -1808,6 +1810,7 @@ class _Element2Writer extends _AbstractElementWriter {
_sink.writeIf(e.isLate, 'late ');
_sink.writeIf(e.isFinal, 'final ');
_sink.writeIf(e.isConst, 'const ');
_sink.writeIf(e.hasInitializer, 'hasInitializer ');

_writeElementName(e);
});
Expand Down Expand Up @@ -1863,6 +1866,7 @@ class _Element2Writer extends _AbstractElementWriter {
_sink.writeIndentedLine(() {
_sink.writeIf(f.isAugmentation, 'augment ');
_sink.writeIf(f.isSynthetic, 'synthetic ');
_sink.writeIf(f.hasInitializer, 'hasInitializer ');

_writeFragmentName(f);
});
Expand Down
Loading

0 comments on commit 016310d

Please sign in to comment.