Augment. Use nullable PropertyAccessorElement.variable2
As much as I don't like the scale of changes, there is no valid variable in these cases. So, we express this explicitly, without trying to pretend that there is on. Or crashing as we did without this CL.
Change-Id: I74cef1d3d9d3cba6985d83b98be361cca09170f9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/355300
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analysis_server/lib/src/cider/rename.dart b/pkg/analysis_server/lib/src/cider/rename.dart
index d7816bc..ac9adb0 100644
--- a/pkg/analysis_server/lib/src/cider/rename.dart
+++ b/pkg/analysis_server/lib/src/cider/rename.dart
@@ -366,7 +366,10 @@
return null;
}
if (element is PropertyAccessorElement) {
- element = element.variable;
+ element = element.variable2;
+ if (element == null) {
+ return null;
+ }
}
if (!_canRenameElement(element)) {
return null;
diff --git a/pkg/analysis_server/lib/src/computer/computer_highlights.dart b/pkg/analysis_server/lib/src/computer/computer_highlights.dart
index b78a467..58b8a4e 100644
--- a/pkg/analysis_server/lib/src/computer/computer_highlights.dart
+++ b/pkg/analysis_server/lib/src/computer/computer_highlights.dart
@@ -283,7 +283,7 @@
}
if (element is PropertyAccessorElement) {
var accessor = element;
- var variable = accessor.variable;
+ var variable = accessor.variable2;
if (variable is TopLevelVariableElement) {
type = accessor.isGetter
? HighlightRegionType.TOP_LEVEL_GETTER_REFERENCE
diff --git a/pkg/analysis_server/lib/src/domains/analysis/occurrences_dart.dart b/pkg/analysis_server/lib/src/domains/analysis/occurrences_dart.dart
index 09c5353..4380acb 100644
--- a/pkg/analysis_server/lib/src/domains/analysis/occurrences_dart.dart
+++ b/pkg/analysis_server/lib/src/domains/analysis/occurrences_dart.dart
@@ -199,7 +199,7 @@
if (canonicalElement is FieldFormalParameterElement) {
canonicalElement = canonicalElement.field;
} else if (canonicalElement is PropertyAccessorElement) {
- canonicalElement = canonicalElement.variable;
+ canonicalElement = canonicalElement.variable2;
}
return canonicalElement?.declaration;
}
diff --git a/pkg/analysis_server/lib/src/handler/legacy/search_find_element_references.dart b/pkg/analysis_server/lib/src/handler/legacy/search_find_element_references.dart
index 453f5f1..ae66b2c 100644
--- a/pkg/analysis_server/lib/src/handler/legacy/search_find_element_references.dart
+++ b/pkg/analysis_server/lib/src/handler/legacy/search_find_element_references.dart
@@ -33,7 +33,7 @@
element = element.field;
}
if (element is PropertyAccessorElement) {
- element = element.variable;
+ element = element.variable2;
}
// respond
var searchId = (server.nextSearchId++).toString();
diff --git a/pkg/analysis_server/lib/src/lsp/handlers/handler_definition.dart b/pkg/analysis_server/lib/src/lsp/handlers/handler_definition.dart
index c0d5283..d114a17 100644
--- a/pkg/analysis_server/lib/src/lsp/handlers/handler_definition.dart
+++ b/pkg/analysis_server/lib/src/lsp/handlers/handler_definition.dart
@@ -174,11 +174,11 @@
/// Get the location of the code (excluding leading doc comments) for this element.
Future<protocol.Location?> _getCodeLocation(Element element) async {
- var codeElement = element;
+ Element? codeElement = element;
// For synthetic getters created for fields, we need to access the associated
// variable to get the codeOffset/codeLength.
- if (codeElement.isSynthetic && codeElement is PropertyAccessorElementImpl) {
- codeElement = codeElement.variable;
+ if (codeElement is PropertyAccessorElementImpl && codeElement.isSynthetic) {
+ codeElement = codeElement.variable2!;
}
// Read the main codeOffset from the element. This may include doc comments
diff --git a/pkg/analysis_server/lib/src/lsp/handlers/handler_document_color_presentation.dart b/pkg/analysis_server/lib/src/lsp/handlers/handler_document_color_presentation.dart
index 9c99e86..b25cb63 100644
--- a/pkg/analysis_server/lib/src/lsp/handlers/handler_document_color_presentation.dart
+++ b/pkg/analysis_server/lib/src/lsp/handlers/handler_document_color_presentation.dart
@@ -201,7 +201,7 @@
? parent.staticElement
: node.staticElement;
final target = staticElement is PropertyAccessorElement
- ? staticElement.variable
+ ? staticElement.variable2
: staticElement;
final existingIsConst = target is ConstVariableElement;
diff --git a/pkg/analysis_server/lib/src/lsp/handlers/handler_type_definition.dart b/pkg/analysis_server/lib/src/lsp/handlers/handler_type_definition.dart
index 099eb6a..0c43b8c 100644
--- a/pkg/analysis_server/lib/src/lsp/handlers/handler_type_definition.dart
+++ b/pkg/analysis_server/lib/src/lsp/handlers/handler_type_definition.dart
@@ -184,7 +184,7 @@
} else if (node.inSetterContext()) {
final writeElement = node.writeElement;
if (writeElement is PropertyAccessorElement) {
- return writeElement.variable.type;
+ return writeElement.variable2?.type;
}
}
}
diff --git a/pkg/analysis_server/lib/src/services/completion/dart/declaration_helper.dart b/pkg/analysis_server/lib/src/services/completion/dart/declaration_helper.dart
index 5a373ca..3ce86a0 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart/declaration_helper.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart/declaration_helper.dart
@@ -1656,5 +1656,12 @@
extension on PropertyAccessorElement {
/// Whether this accessor is an accessor for a constant variable.
- bool get isConst => isSynthetic && variable.isConst;
+ bool get isConst {
+ if (isSynthetic) {
+ if (variable2 case var variable?) {
+ return variable.isConst;
+ }
+ }
+ return false;
+ }
}
diff --git a/pkg/analysis_server/lib/src/services/completion/dart/feature_computer.dart b/pkg/analysis_server/lib/src/services/completion/dart/feature_computer.dart
index 2481447..fe71637 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart/feature_computer.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart/feature_computer.dart
@@ -199,7 +199,11 @@
} else if (element is FieldElement && element.isEnumConstant) {
return protocol.ElementKind.ENUM_CONSTANT;
} else if (element is PropertyAccessorElement) {
- element = element.variable;
+ var variable = element.variable2;
+ if (variable == null) {
+ return protocol.ElementKind.UNKNOWN;
+ }
+ element = variable;
}
var kind = element.kind;
if (kind == ElementKind.CONSTRUCTOR) {
@@ -314,11 +318,11 @@
return 1.0;
} else if (element is TopLevelVariableElement && element.isConst) {
return 1.0;
- } else if (element is PropertyAccessorElement &&
- element.isSynthetic &&
- element.variable.isStatic &&
- element.variable.isConst) {
- return 1.0;
+ } else if (element is PropertyAccessorElement && element.isSynthetic) {
+ var variable = element.variable2;
+ if (variable != null && variable.isStatic && variable.isConst) {
+ return 1.0;
+ }
}
return 0.0;
}
diff --git a/pkg/analysis_server/lib/src/services/completion/dart/local_library_contributor.dart b/pkg/analysis_server/lib/src/services/completion/dart/local_library_contributor.dart
index 67f8150..a3b70d6 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart/local_library_contributor.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart/local_library_contributor.dart
@@ -124,8 +124,11 @@
@override
void visitPropertyAccessorElement(PropertyAccessorElement element) {
+ var variable = element.variable2;
if (opType.includeReturnValueSuggestions ||
- (opType.includeAnnotationSuggestions && element.variable.isConst)) {
+ (opType.includeAnnotationSuggestions &&
+ variable != null &&
+ variable.isConst)) {
var parent = element.enclosingElement;
if (parent is InterfaceElement || parent is ExtensionElement) {
builder.suggestAccessor(element, inheritanceDistance: 0.0);
diff --git a/pkg/analysis_server/lib/src/services/completion/dart/suggestion_builder.dart b/pkg/analysis_server/lib/src/services/completion/dart/suggestion_builder.dart
index e992a49..47918c9 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart/suggestion_builder.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart/suggestion_builder.dart
@@ -89,7 +89,8 @@
{required PropertyAccessorElement accessor,
required double inheritanceDistance}) {
if (accessor.isAccessibleIn(request.libraryElement)) {
- var member = accessor.isSynthetic ? accessor.variable : accessor;
+ var member =
+ accessor.isSynthetic ? accessor.variable2 ?? accessor : accessor;
if (_shouldAddSuggestion(member)) {
builder.suggestAccessor(accessor,
inheritanceDistance: inheritanceDistance);
@@ -269,7 +270,7 @@
// non-final fields induce a setter, so we don't add a suggestion for a
// synthetic setter.
if (accessor.isGetter) {
- var variable = accessor.variable;
+ var variable = accessor.variable2;
if (variable is FieldElement) {
suggestField(variable, inheritanceDistance: inheritanceDistance);
}
@@ -1145,7 +1146,7 @@
// non-final fields induce a setter, so we don't add a suggestion for a
// synthetic setter.
if (accessor.isGetter) {
- var variable = accessor.variable;
+ var variable = accessor.variable2;
if (variable is TopLevelVariableElement) {
suggestTopLevelVariable(variable);
}
diff --git a/pkg/analysis_server/lib/src/services/correction/dart/add_late.dart b/pkg/analysis_server/lib/src/services/correction/dart/add_late.dart
index 334f271..315a3ae 100644
--- a/pkg/analysis_server/lib/src/services/correction/dart/add_late.dart
+++ b/pkg/analysis_server/lib/src/services/correction/dart/add_late.dart
@@ -30,7 +30,7 @@
await _insertAt(builder, variableList.variables[0].offset);
// TODO(brianwilkerson): Consider converting this into an assist and
// expand it to support converting `var` to `late` as well as
- // working anywhere a non-late local variable or field is selected.
+ // working anywhere a non-late local variableElement or field is selected.
// } else if (keyword.type == Keyword.VAR) {
// builder.addFileEdit(file, (builder) {
// builder.addSimpleReplacement(range.token(keyword), 'late');
@@ -56,26 +56,29 @@
if (getter is PropertyAccessorElement &&
getter.isGetter &&
getter.isSynthetic &&
- !getter.variable.isSynthetic &&
- !getter.variable.isLate &&
- getter.variable.setter == null &&
getter.enclosingElement is InterfaceElement) {
- var declarationResult =
- await sessionHelper.getElementDeclaration(getter.variable);
- if (declarationResult == null) {
- return;
- }
- var variable = declarationResult.node;
- var variableList = variable.parent;
- if (variable is VariableDeclaration &&
- variableList is VariableDeclarationList &&
- variableList.parent is FieldDeclaration) {
- var keywordToken = variableList.keyword;
- if (variableList.variables.length == 1 &&
- keywordToken != null &&
- keywordToken.keyword == Keyword.FINAL) {
- await _insertAt(builder, keywordToken.offset,
- source: declarationResult.element.source);
+ var variableElement = getter.variable2;
+ if (variableElement != null &&
+ !variableElement.isSynthetic &&
+ !variableElement.isLate &&
+ variableElement.setter == null) {
+ var declarationResult =
+ await sessionHelper.getElementDeclaration(variableElement);
+ if (declarationResult == null) {
+ return;
+ }
+ var variableNode = declarationResult.node;
+ var variableList = variableNode.parent;
+ if (variableNode is VariableDeclaration &&
+ variableList is VariableDeclarationList &&
+ variableList.parent is FieldDeclaration) {
+ var keywordToken = variableList.keyword;
+ if (variableList.variables.length == 1 &&
+ keywordToken != null &&
+ keywordToken.keyword == Keyword.FINAL) {
+ await _insertAt(builder, keywordToken.offset,
+ source: declarationResult.element.source);
+ }
}
}
}
diff --git a/pkg/analysis_server/lib/src/services/correction/dart/flutter_convert_to_stateful_widget.dart b/pkg/analysis_server/lib/src/services/correction/dart/flutter_convert_to_stateful_widget.dart
index 91f766c..67caa5c 100644
--- a/pkg/analysis_server/lib/src/services/correction/dart/flutter_convert_to_stateful_widget.dart
+++ b/pkg/analysis_server/lib/src/services/correction/dart/flutter_convert_to_stateful_widget.dart
@@ -286,7 +286,7 @@
if (node.inSetterContext()) {
var element = node.writeOrReadElement;
if (element is PropertyAccessorElement) {
- var field = element.variable;
+ var field = element.variable2;
if (field is FieldElement) {
fieldsAssignedInConstructors.add(field);
}
diff --git a/pkg/analysis_server/lib/src/services/correction/dart/flutter_convert_to_stateless_widget.dart b/pkg/analysis_server/lib/src/services/correction/dart/flutter_convert_to_stateless_widget.dart
index 4e7863d..57eaa84 100644
--- a/pkg/analysis_server/lib/src/services/correction/dart/flutter_convert_to_stateless_widget.dart
+++ b/pkg/analysis_server/lib/src/services/correction/dart/flutter_convert_to_stateless_widget.dart
@@ -286,7 +286,7 @@
if (node.inSetterContext()) {
var element = node.writeOrReadElement;
if (element is PropertyAccessorElement) {
- var field = element.variable;
+ var field = element.variable2;
if (field is FieldElement) {
fieldsAssignedInConstructors.add(field);
}
diff --git a/pkg/analysis_server/lib/src/services/correction/dart/import_library.dart b/pkg/analysis_server/lib/src/services/correction/dart/import_library.dart
index 6c42d6b..cfcbea1 100644
--- a/pkg/analysis_server/lib/src/services/correction/dart/import_library.dart
+++ b/pkg/analysis_server/lib/src/services/correction/dart/import_library.dart
@@ -259,7 +259,10 @@
continue;
}
if (element is PropertyAccessorElement) {
- element = element.variable;
+ element = element.variable2;
+ if (element == null) {
+ continue;
+ }
}
if (!kinds.contains(element.kind)) {
continue;
diff --git a/pkg/analysis_server/lib/src/services/correction/dart/make_field_not_final.dart b/pkg/analysis_server/lib/src/services/correction/dart/make_field_not_final.dart
index f3d05b9..41fe01a 100644
--- a/pkg/analysis_server/lib/src/services/correction/dart/make_field_not_final.dart
+++ b/pkg/analysis_server/lib/src/services/correction/dart/make_field_not_final.dart
@@ -39,7 +39,10 @@
}
// The variable must be not synthetic, and have no setter yet.
- var variable = getter.variable;
+ var variable = getter.variable2;
+ if (variable == null) {
+ return;
+ }
if (variable.isSynthetic || variable.setter != null) {
return;
}
diff --git a/pkg/analysis_server/lib/src/services/correction/dart/remove_unused.dart b/pkg/analysis_server/lib/src/services/correction/dart/remove_unused.dart
index b3f8b17..e6fde81 100644
--- a/pkg/analysis_server/lib/src/services/correction/dart/remove_unused.dart
+++ b/pkg/analysis_server/lib/src/services/correction/dart/remove_unused.dart
@@ -278,7 +278,7 @@
if (staticElement == element) {
references.add(node);
} else if (staticElement is PropertyAccessorElement) {
- if (staticElement.variable == element) {
+ if (staticElement.variable2 == element) {
references.add(node);
}
} else if (staticElement is FieldFormalParameterElement) {
diff --git a/pkg/analysis_server/lib/src/services/flutter/widget_descriptions.dart b/pkg/analysis_server/lib/src/services/flutter/widget_descriptions.dart
index 208e333..a708fc3 100644
--- a/pkg/analysis_server/lib/src/services/flutter/widget_descriptions.dart
+++ b/pkg/analysis_server/lib/src/services/flutter/widget_descriptions.dart
@@ -542,7 +542,7 @@
} else if (valueExpression is Identifier) {
var element = valueExpression.staticElement;
if (element is PropertyAccessorElement && element.isGetter) {
- var field = element.variable;
+ var field = element.variable2;
if (field is FieldElement && field.isStatic) {
var enclosingClass = field.enclosingElement as InterfaceElement;
if (field.isEnumConstant ||
diff --git a/pkg/analysis_server/lib/src/services/refactoring/legacy/convert_getter_to_method.dart b/pkg/analysis_server/lib/src/services/refactoring/legacy/convert_getter_to_method.dart
index 94442fc..3431857 100644
--- a/pkg/analysis_server/lib/src/services/refactoring/legacy/convert_getter_to_method.dart
+++ b/pkg/analysis_server/lib/src/services/refactoring/legacy/convert_getter_to_method.dart
@@ -54,7 +54,7 @@
await _updateElementReferences(element);
}
// method
- var field = element.variable;
+ var field = element.variable2;
if (field is FieldElement &&
(field.enclosingElement is InterfaceElement ||
field.enclosingElement is ExtensionElement)) {
diff --git a/pkg/analysis_server/lib/src/services/refactoring/legacy/extract_widget.dart b/pkg/analysis_server/lib/src/services/refactoring/legacy/extract_widget.dart
index 78a3b3c..2a629f0 100644
--- a/pkg/analysis_server/lib/src/services/refactoring/legacy/extract_widget.dart
+++ b/pkg/analysis_server/lib/src/services/refactoring/legacy/extract_widget.dart
@@ -629,7 +629,10 @@
}
}
} else if (element is PropertyAccessorElement) {
- var field = element.variable;
+ var field = element.variable2;
+ if (field == null) {
+ return;
+ }
if (_isMemberOfEnclosingClass(field)) {
if (node.inSetterContext()) {
status.addError("Write to '$elementName' cannot be extracted.");
diff --git a/pkg/analysis_server/lib/src/services/refactoring/legacy/refactoring.dart b/pkg/analysis_server/lib/src/services/refactoring/legacy/refactoring.dart
index c88de5e..f533741 100644
--- a/pkg/analysis_server/lib/src/services/refactoring/legacy/refactoring.dart
+++ b/pkg/analysis_server/lib/src/services/refactoring/legacy/refactoring.dart
@@ -416,7 +416,10 @@
var session = resolvedUnit.session;
var sessionHelper = AnalysisSessionHelper(session);
if (element is PropertyAccessorElement) {
- element = element.variable;
+ element = element.variable2;
+ if (element == null) {
+ return null;
+ }
}
var enclosingElement = element.enclosingElement;
if (enclosingElement is CompilationUnitElement) {
diff --git a/pkg/analysis_server/lib/src/services/search/hierarchy.dart b/pkg/analysis_server/lib/src/services/search/hierarchy.dart
index 186bf07..84c0e81 100644
--- a/pkg/analysis_server/lib/src/services/search/hierarchy.dart
+++ b/pkg/analysis_server/lib/src/services/search/hierarchy.dart
@@ -191,7 +191,7 @@
Element getSyntheticAccessorVariable(Element element) {
if (element is PropertyAccessorElement) {
if (element.isSynthetic) {
- return element.variable;
+ return element.variable2 ?? element;
}
}
return element;
diff --git a/pkg/analysis_server/lib/src/utilities/import_analyzer.dart b/pkg/analysis_server/lib/src/utilities/import_analyzer.dart
index 84acdc3..4461391 100644
--- a/pkg/analysis_server/lib/src/utilities/import_analyzer.dart
+++ b/pkg/analysis_server/lib/src/utilities/import_analyzer.dart
@@ -111,7 +111,11 @@
LibraryImportElement? import) {
if (referencedElement is PropertyAccessorElement &&
referencedElement.isSynthetic) {
- referencedElement = referencedElement.variable;
+ var variable = referencedElement.variable2;
+ if (variable == null) {
+ return;
+ }
+ referencedElement = variable;
}
if (_isBeingMoved(referenceOffset)) {
var imports =
diff --git a/pkg/analyzer/CHANGELOG.md b/pkg/analyzer/CHANGELOG.md
index b3cb0d7..e148c57 100644
--- a/pkg/analyzer/CHANGELOG.md
+++ b/pkg/analyzer/CHANGELOG.md
@@ -5,6 +5,10 @@
* Deprecated `InterfaceElement.lookUpGetter`, `InterfaceElement.lookUpMethod`,
and `InterfaceElement.lookUpSetter`.
* Fixed `GeneralizingAstVisitor.visitNamedType` to invoke `visitTypeAnnotation`.
+* Deprecated `PropertyInducingElement get variable` in `PropertyAccessorElement`,
+ use `PropertyInducingElement? get variable2` instead.
+ The reason for this is that when the property accessor is an augmentation
+ without the corresponding declaration, there is no corresponding variable.
## 6.4.1
* Patch for crash in ffi_verifier.
diff --git a/pkg/analyzer/lib/dart/element/element.dart b/pkg/analyzer/lib/dart/element/element.dart
index b3f608d..2651556 100644
--- a/pkg/analyzer/lib/dart/element/element.dart
+++ b/pkg/analyzer/lib/dart/element/element.dart
@@ -2341,7 +2341,17 @@
///
/// If this accessor was explicitly defined (is not synthetic) then the
/// variable associated with it will be synthetic.
+ @Deprecated('Use variable2')
PropertyInducingElement get variable;
+
+ /// The field or top-level variable associated with this accessor.
+ ///
+ /// If this accessor was explicitly defined (is not synthetic) then the
+ /// variable associated with it will be synthetic.
+ ///
+ /// If this accessor is an augmentation, and [augmentationTarget] is `null`,
+ /// the variable is `null`.
+ PropertyInducingElement? get variable2;
}
/// A variable that has an associated getter and possibly a setter. Note that
diff --git a/pkg/analyzer/lib/src/dart/analysis/index.dart b/pkg/analyzer/lib/src/dart/analysis/index.dart
index ec173e2..3a112ad 100644
--- a/pkg/analyzer/lib/src/dart/analysis/index.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/index.dart
@@ -164,7 +164,9 @@
kind = accessor.isGetter
? IndexSyntheticElementKind.getter
: IndexSyntheticElementKind.setter;
- element = accessor.variable;
+ if (accessor.variable2 case var variable?) {
+ element = variable;
+ }
}
} else if (element is MethodElement) {
Element enclosing = element.enclosingElement;
diff --git a/pkg/analyzer/lib/src/dart/constant/evaluation.dart b/pkg/analyzer/lib/src/dart/constant/evaluation.dart
index 5f33261..0a38e5b 100644
--- a/pkg/analyzer/lib/src/dart/constant/evaluation.dart
+++ b/pkg/analyzer/lib/src/dart/constant/evaluation.dart
@@ -166,10 +166,11 @@
if (element is PropertyAccessorElement) {
// The annotation is a reference to a compile-time constant variable.
// Just copy the evaluation result.
- VariableElementImpl variableElement =
- element.variable.declaration as VariableElementImpl;
- if (variableElement.evaluationResult != null) {
- constant.evaluationResult = variableElement.evaluationResult;
+ var variableElement =
+ element.variable2?.declaration as VariableElementImpl?;
+ var evaluationResult = variableElement?.evaluationResult;
+ if (evaluationResult != null) {
+ constant.evaluationResult = evaluationResult;
} else {
// This could happen in the event that the annotation refers to a
// non-constant. The error is detected elsewhere, so just silently
@@ -301,7 +302,9 @@
if (element is PropertyAccessorElement) {
// The annotation is a reference to a compile-time constant variable,
// so it depends on the variable.
- callback(element.variable.declaration);
+ if (element.variable2 case var variable?) {
+ callback(variable.declaration);
+ }
} else if (element is ConstructorElement) {
// The annotation is a constructor invocation, so it depends on the
// constructor.
@@ -1688,8 +1691,9 @@
}) {
var errorNode2 = evaluationEngine.configuration.errorNode(errorNode);
element = element?.declaration;
+
var variableElement =
- element is PropertyAccessorElement ? element.variable : element;
+ element is PropertyAccessorElement ? element.variable2 : element;
// TODO(srawlins): Remove this check when [FunctionReference]s are inserted
// for generic function instantiation for pre-constructor-references code.
@@ -2654,7 +2658,16 @@
_fieldMap[fieldName] = evaluationResult;
var getter = definingType.getGetter(fieldName);
if (getter != null) {
- var field = getter.variable;
+ var field = getter.variable2;
+ if (field == null) {
+ return _InitializersEvaluationResult(
+ InvalidConstant.forElement(
+ getter,
+ CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
+ ),
+ evaluationIsComplete: true,
+ );
+ }
if (!typeSystem.runtimeTypeMatch(evaluationResult, field.type)) {
// Mark the type mismatch error as a runtime exception if the
// initializer is statically assignable to the field.
diff --git a/pkg/analyzer/lib/src/dart/constant/potentially_constant.dart b/pkg/analyzer/lib/src/dart/constant/potentially_constant.dart
index d8990f4..cb9bf92 100644
--- a/pkg/analyzer/lib/src/dart/constant/potentially_constant.dart
+++ b/pkg/analyzer/lib/src/dart/constant/potentially_constant.dart
@@ -260,7 +260,10 @@
return;
}
if (element is PropertyAccessorElement && element.isGetter) {
- var variable = element.variable;
+ var variable = element.variable2;
+ if (variable == null) {
+ return;
+ }
if (!variable.isConst) {
nodes.add(node);
}
@@ -313,7 +316,10 @@
var element = node.propertyName.staticElement;
if (element is PropertyAccessorElement && element.isGetter) {
- var variable = element.variable;
+ var variable = element.variable2;
+ if (variable == null) {
+ return;
+ }
if (!variable.isConst) {
nodes.add(node.propertyName);
}
diff --git a/pkg/analyzer/lib/src/dart/constant/utilities.dart b/pkg/analyzer/lib/src/dart/constant/utilities.dart
index 4170110..9089f60 100644
--- a/pkg/analyzer/lib/src/dart/constant/utilities.dart
+++ b/pkg/analyzer/lib/src/dart/constant/utilities.dart
@@ -246,7 +246,7 @@
void visitSimpleIdentifier(SimpleIdentifier node) {
var staticElement = node.staticElement;
var element = staticElement is PropertyAccessorElement
- ? staticElement.variable
+ ? staticElement.variable2
: staticElement;
if (element is VariableElement && element.isConst) {
_callback(element);
diff --git a/pkg/analyzer/lib/src/dart/element/display_string_builder.dart b/pkg/analyzer/lib/src/dart/element/display_string_builder.dart
index 0efc398..19c95ea 100644
--- a/pkg/analyzer/lib/src/dart/element/display_string_builder.dart
+++ b/pkg/analyzer/lib/src/dart/element/display_string_builder.dart
@@ -95,6 +95,18 @@
_writeTypesIfNotEmpty(' implements ', element.interfaces);
}
+ // void writePropertyAccessor(PropertyAccessorElement element) {
+ // var variable = element.variable2;
+ // if (variable == null) {
+ // // builder.;
+ // }
+ //
+ // writeExecutableElement(
+ // element,
+ // (element.isGetter ? 'get ' : 'set ') + variable2.displayName,
+ // );
+ // }
+
void writeExecutableElement(ExecutableElement element, String name) {
if (element.isAugmentation) {
_write('augment ');
diff --git a/pkg/analyzer/lib/src/dart/element/element.dart b/pkg/analyzer/lib/src/dart/element/element.dart
index 871a04c..36c8077 100644
--- a/pkg/analyzer/lib/src/dart/element/element.dart
+++ b/pkg/analyzer/lib/src/dart/element/element.dart
@@ -5965,7 +5965,7 @@
ParameterElementImpl_ofImplicitSetter(this.setter)
: super(
- name: considerCanonicalizeString('_${setter.variable.name}'),
+ name: considerCanonicalizeString('_${setter.variable2.name}'),
nameOffset: -1,
parameterKind: ParameterKind.REQUIRED,
) {
@@ -5975,7 +5975,7 @@
@override
bool get inheritsCovariant {
- var variable = setter.variable;
+ var variable = setter.variable2;
if (variable is FieldElementImpl) {
return variable.inheritsCovariant;
}
@@ -5984,7 +5984,7 @@
@override
set inheritsCovariant(bool value) {
- var variable = setter.variable;
+ var variable = setter.variable2;
if (variable is FieldElementImpl) {
variable.inheritsCovariant = value;
}
@@ -6000,7 +6000,7 @@
@override
bool get isExplicitlyCovariant {
- var variable = setter.variable;
+ var variable = setter.variable2;
if (variable is FieldElementImpl) {
return variable.isCovariant;
}
@@ -6009,11 +6009,11 @@
@override
Element get nonSynthetic {
- return setter.variable;
+ return setter.variable2;
}
@override
- DartType get type => setter.variable.type;
+ DartType get type => setter.variable2.type;
@override
set type(DartType type) {
@@ -6166,7 +6166,7 @@
class PropertyAccessorElementImpl extends ExecutableElementImpl
with AugmentableElement<PropertyAccessorElementImpl>
implements PropertyAccessorElement {
- late PropertyInducingElementImpl _variable;
+ PropertyInducingElementImpl? _variable;
/// If this method is a synthetic element which is based on another method
/// with some modifications (such as making some parameters covariant),
@@ -6179,11 +6179,11 @@
/// Initialize a newly created synthetic property accessor element to be
/// associated with the given [variable].
- PropertyAccessorElementImpl.forVariable(this._variable,
+ PropertyAccessorElementImpl.forVariable(PropertyInducingElementImpl variable,
{Reference? reference})
- : super(_variable.name, -1, reference: reference) {
- isAbstract = variable is FieldElementImpl &&
- (variable as FieldElementImpl).isAbstract;
+ : _variable = variable,
+ super(variable.name, -1, reference: reference) {
+ isAbstract = variable is FieldElementImpl && variable.isAbstract;
isStatic = variable.isStatic;
isSynthetic = true;
}
@@ -6193,7 +6193,7 @@
if (isGetter) {
return null;
}
- return variable.getter;
+ return variable2?.getter;
}
@override
@@ -6201,7 +6201,7 @@
if (isSetter) {
return null;
}
- return variable.setter;
+ return variable2?.setter;
}
@override
@@ -6261,13 +6261,19 @@
return super.name;
}
+ @Deprecated('Use variable2')
@override
PropertyInducingElementImpl get variable {
+ return variable2!;
+ }
+
+ @override
+ PropertyInducingElementImpl? get variable2 {
linkedData?.read(this);
return _variable;
}
- set variable(PropertyInducingElementImpl value) {
+ set variable2(PropertyInducingElementImpl? value) {
_variable = value;
}
@@ -6279,7 +6285,7 @@
void appendTo(ElementDisplayStringBuilder builder) {
builder.writeExecutableElement(
this,
- (isGetter ? 'get ' : 'set ') + variable.displayName,
+ (isGetter ? 'get ' : 'set ') + displayName,
);
}
}
@@ -6297,26 +6303,25 @@
}
@override
- Element get enclosingElement => variable.enclosingElement;
+ Element get enclosingElement => variable2.enclosingElement;
@override
- bool get hasImplicitReturnType => variable.hasImplicitType;
+ bool get hasImplicitReturnType => variable2.hasImplicitType;
@override
bool get isGetter => true;
@override
Element get nonSynthetic {
- final variable = this.variable;
- if (!variable.isSynthetic) {
- return variable;
+ if (!variable2.isSynthetic) {
+ return variable2;
}
assert(enclosingElement is EnumElementImpl);
return enclosingElement;
}
@override
- DartType get returnType => variable.type;
+ DartType get returnType => variable2.type;
@override
set returnType(DartType returnType) {
@@ -6324,7 +6329,7 @@
}
@override
- Version? get sinceSdkVersion => variable.sinceSdkVersion;
+ Version? get sinceSdkVersion => variable2.sinceSdkVersion;
@override
FunctionType get type {
@@ -6340,6 +6345,9 @@
set type(FunctionType type) {
assert(false); // Should never be called.
}
+
+ @override
+ PropertyInducingElementImpl get variable2 => super.variable2!;
}
/// Implicit setter for a [PropertyInducingElementImpl].
@@ -6354,13 +6362,13 @@
}
@override
- Element get enclosingElement => variable.enclosingElement;
+ Element get enclosingElement => variable2.enclosingElement;
@override
bool get isSetter => true;
@override
- Element get nonSynthetic => variable;
+ Element get nonSynthetic => variable2;
@override
List<ParameterElement> get parameters {
@@ -6382,7 +6390,7 @@
}
@override
- Version? get sinceSdkVersion => variable.sinceSdkVersion;
+ Version? get sinceSdkVersion => variable2.sinceSdkVersion;
@override
FunctionType get type {
@@ -6398,6 +6406,9 @@
set type(FunctionType type) {
assert(false); // Should never be called.
}
+
+ @override
+ PropertyInducingElementImpl get variable2 => super.variable2!;
}
/// A concrete implementation of a [PropertyInducingElement].
diff --git a/pkg/analyzer/lib/src/dart/element/inheritance_manager3.dart b/pkg/analyzer/lib/src/dart/element/inheritance_manager3.dart
index 2d25de1..f69c82efc 100644
--- a/pkg/analyzer/lib/src/dart/element/inheritance_manager3.dart
+++ b/pkg/analyzer/lib/src/dart/element/inheritance_manager3.dart
@@ -969,13 +969,13 @@
result.prototype = executable;
result.returnType = executable.returnType;
- var field = executable.variable;
+ var field = executable.variable2!;
var resultField = FieldElementImpl(field.name, -1);
resultField.enclosingElement = class_;
resultField.getter = field.getter;
resultField.setter = executable;
resultField.type = executable.parameters[0].type;
- result.variable = resultField;
+ result.variable2 = resultField;
return result;
}
@@ -1049,7 +1049,7 @@
field.setter = result;
field.type = result.parameters[0].type;
}
- result.variable = field;
+ result.variable2 = field;
return result;
}
diff --git a/pkg/analyzer/lib/src/dart/element/member.dart b/pkg/analyzer/lib/src/dart/element/member.dart
index 4b72f12..585fc99 100644
--- a/pkg/analyzer/lib/src/dart/element/member.dart
+++ b/pkg/analyzer/lib/src/dart/element/member.dart
@@ -1036,8 +1036,13 @@
@override
PropertyInducingElement get variable {
+ return variable2!;
+ }
+
+ @override
+ PropertyInducingElement? get variable2 {
// TODO(scheglov): revisit
- PropertyInducingElement variable = declaration.variable;
+ var variable = declaration.variable2;
if (variable is FieldElement) {
return FieldMember(variable, augmentationSubstitution, _substitution);
} else if (variable is TopLevelVariableElement) {
diff --git a/pkg/analyzer/lib/src/dart/micro/utils.dart b/pkg/analyzer/lib/src/dart/micro/utils.dart
index 6b9b85e..c1cefd0 100644
--- a/pkg/analyzer/lib/src/dart/micro/utils.dart
+++ b/pkg/analyzer/lib/src/dart/micro/utils.dart
@@ -220,7 +220,7 @@
node.writeElement is PropertyAccessorElement) {
var kind = MatchKind.WRITE;
var property = node.writeElement as PropertyAccessorElement;
- if (property.variable == element || property == element) {
+ if (property.variable2 == element || property == element) {
if (node.leftHandSide is SimpleIdentifier) {
references.add(MatchInfo(
node.leftHandSide.offset, node.leftHandSide.length, kind));
@@ -238,7 +238,7 @@
if (node.readElement != null &&
node.readElement is PropertyAccessorElement) {
var property = node.readElement as PropertyAccessorElement;
- if (property.variable == element) {
+ if (property.variable2 == element) {
references.add(MatchInfo(node.rightHandSide.offset,
node.rightHandSide.length, MatchKind.READ));
}
@@ -378,7 +378,7 @@
var e = node.staticElement;
if (e == element) {
references.add(MatchInfo(node.offset, node.length, MatchKind.REFERENCE));
- } else if (e is PropertyAccessorElement && e.variable == element) {
+ } else if (e is PropertyAccessorElement && e.variable2 == element) {
bool inGetterContext = node.inGetterContext();
bool inSetterContext = node.inSetterContext();
MatchKind kind;
diff --git a/pkg/analyzer/lib/src/dart/resolver/annotation_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/annotation_resolver.dart
index 68a9d7b..60db645 100644
--- a/pkg/analyzer/lib/src/dart/resolver/annotation_resolver.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/annotation_resolver.dart
@@ -324,7 +324,11 @@
Annotation annotation, PropertyAccessorElement accessorElement) {
// The accessor should be synthetic, the variable should be constant, and
// there should be no arguments.
- VariableElement variableElement = accessorElement.variable;
+ var variableElement = accessorElement.variable2;
+ if (variableElement == null) {
+ return;
+ }
+
if (!accessorElement.isSynthetic ||
!variableElement.isConst ||
annotation.arguments != null) {
diff --git a/pkg/analyzer/lib/src/dart/resolver/flow_analysis_visitor.dart b/pkg/analyzer/lib/src/dart/resolver/flow_analysis_visitor.dart
index fae48ab..ad59744 100644
--- a/pkg/analyzer/lib/src/dart/resolver/flow_analysis_visitor.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/flow_analysis_visitor.dart
@@ -545,7 +545,7 @@
@override
bool isPropertyPromotable(Object property) {
if (property is! PropertyAccessorElement) return false;
- var field = property.variable;
+ var field = property.variable2;
if (field is! FieldElement) return false;
return field.isPromotable;
}
@@ -768,7 +768,7 @@
if (property is! PropertyAccessorElement) {
return PropertyNonPromotabilityReason.isNotField;
}
- var field = property.variable;
+ var field = property.variable2;
if (field is! FieldElement) {
return PropertyNonPromotabilityReason.isNotField;
}
diff --git a/pkg/analyzer/lib/src/dart/resolver/function_reference_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/function_reference_resolver.dart
index 3f42098..4bbf9879 100644
--- a/pkg/analyzer/lib/src/dart/resolver/function_reference_resolver.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/function_reference_resolver.dart
@@ -93,7 +93,11 @@
if (prefixElement is VariableElement) {
prefixType = prefixElement.type;
} else if (prefixElement is PropertyAccessorElement) {
- prefixType = prefixElement.variable.type;
+ var variable = prefixElement.variable2;
+ if (variable == null) {
+ return false;
+ }
+ prefixType = variable.type;
}
if (prefixType is DynamicType) {
@@ -512,7 +516,12 @@
if (targetElement is VariableElement) {
targetType = targetElement.type;
} else if (targetElement is PropertyAccessorElement) {
- targetType = targetElement.variable.type;
+ var variable = targetElement.variable2;
+ if (variable == null) {
+ node.staticType = InvalidTypeImpl.instance;
+ return;
+ }
+ targetType = variable.type;
} else {
// TODO(srawlins): Can we get here?
node.staticType = DynamicTypeImpl.instance;
@@ -688,7 +697,13 @@
if (method is PropertyAccessorElement) {
function.staticElement = method;
function.staticType = method.returnType;
- _resolve(node: node, rawType: method.variable.type);
+ var variable = method.variable2;
+ if (variable != null) {
+ _resolve(node: node, rawType: variable.type);
+ } else {
+ function.staticType = InvalidTypeImpl.instance;
+ node.staticType = InvalidTypeImpl.instance;
+ }
return;
}
@@ -745,8 +760,13 @@
return;
} else if (element is PropertyAccessorElement) {
function.staticElement = element;
- function.staticType = element.variable.type;
- var callMethod = _getCallMethod(node, element.variable.type);
+ var variable = element.variable2;
+ if (variable == null) {
+ function.staticType = InvalidTypeImpl.instance;
+ return;
+ }
+ function.staticType = variable.type;
+ var callMethod = _getCallMethod(node, variable.type);
if (callMethod is MethodElement) {
_resolveAsImplicitCallReference(node, callMethod);
return;
diff --git a/pkg/analyzer/lib/src/dart/resolver/simple_identifier_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/simple_identifier_resolver.dart
index 524dcfb..086cdac 100644
--- a/pkg/analyzer/lib/src/dart/resolver/simple_identifier_resolver.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/simple_identifier_resolver.dart
@@ -59,7 +59,7 @@
if (parameterTypes.isNotEmpty) {
return parameterTypes[0];
}
- var getter = accessor.variable.getter;
+ var getter = accessor.variable2?.getter;
if (getter != null) {
functionType = getter.type;
return functionType.returnType;
diff --git a/pkg/analyzer/lib/src/error/assignment_verifier.dart b/pkg/analyzer/lib/src/error/assignment_verifier.dart
index 75aad8b..c77e909 100644
--- a/pkg/analyzer/lib/src/error/assignment_verifier.dart
+++ b/pkg/analyzer/lib/src/error/assignment_verifier.dart
@@ -70,7 +70,10 @@
arguments: [recovery.name],
);
} else if (recovery is PropertyAccessorElement && recovery.isGetter) {
- var variable = recovery.variable;
+ var variable = recovery.variable2;
+ if (variable == null) {
+ return;
+ }
if (variable.isConst) {
_errorReporter.atNode(
node,
diff --git a/pkg/analyzer/lib/src/error/best_practices_verifier.dart b/pkg/analyzer/lib/src/error/best_practices_verifier.dart
index 76c3032..63b1153 100644
--- a/pkg/analyzer/lib/src/error/best_practices_verifier.dart
+++ b/pkg/analyzer/lib/src/error/best_practices_verifier.dart
@@ -1525,7 +1525,7 @@
}
}
if (element is PropertyAccessorElement && element.isSynthetic) {
- element = element.variable;
+ element = element.variable2;
}
if (element != null && element.hasOrInheritsDoNotStore) {
@@ -1587,7 +1587,10 @@
static bool _hasNonVirtualAnnotation(ExecutableElement element) {
if (element is PropertyAccessorElement && element.isSynthetic) {
- return element.variable.hasNonVirtual;
+ var variable = element.variable2;
+ if (variable != null && variable.hasNonVirtual) {
+ return true;
+ }
}
return element.hasNonVirtual;
}
@@ -1918,17 +1921,28 @@
if (element.hasInternal) {
return true;
}
- if (element is PropertyAccessorElement && element.variable.hasInternal) {
- return true;
+ if (element is PropertyAccessorElement) {
+ var variable = element.variable2;
+ if (variable == null) {
+ return false;
+ }
+ if (variable.hasInternal) {
+ return true;
+ }
}
return false;
}
bool _hasProtected(Element element) {
if (element is PropertyAccessorElement &&
- element.enclosingElement is InterfaceElement &&
- (element.hasProtected || element.variable.hasProtected)) {
- return true;
+ element.enclosingElement is InterfaceElement) {
+ if (element.hasProtected) {
+ return true;
+ }
+ var variable = element.variable2;
+ if (variable != null && variable.hasProtected) {
+ return true;
+ }
}
if (element is MethodElement &&
element.enclosingElement is InterfaceElement &&
@@ -1953,9 +1967,9 @@
return true;
}
- if (element is PropertyAccessorElement &&
- element.variable.hasVisibleForOverriding) {
- return true;
+ if (element is PropertyAccessorElement) {
+ var variable = element.variable2;
+ return variable != null && variable.hasVisibleForOverriding;
}
return false;
@@ -1968,9 +1982,11 @@
if (element.hasVisibleForTemplate) {
return true;
}
- if (element is PropertyAccessorElement &&
- element.variable.hasVisibleForTemplate) {
- return true;
+ if (element is PropertyAccessorElement) {
+ var variable = element.variable2;
+ if (variable != null && variable.hasVisibleForTemplate) {
+ return true;
+ }
}
final enclosingElement = element.enclosingElement;
if (_hasVisibleForTemplate(enclosingElement)) {
@@ -1983,9 +1999,9 @@
if (element.hasVisibleForTesting) {
return true;
}
- if (element is PropertyAccessorElement &&
- element.variable.hasVisibleForTesting) {
- return true;
+ if (element is PropertyAccessorElement) {
+ var variable = element.variable2;
+ return variable != null && variable.hasVisibleForTesting;
}
return false;
}
@@ -1994,9 +2010,11 @@
if (element.hasVisibleOutsideTemplate) {
return true;
}
- if (element is PropertyAccessorElement &&
- element.variable.hasVisibleOutsideTemplate) {
- return true;
+ if (element is PropertyAccessorElement) {
+ var variable = element.variable2;
+ if (variable != null && variable.hasVisibleOutsideTemplate) {
+ return true;
+ }
}
final enclosingElement = element.enclosingElement;
if (enclosingElement != null &&
diff --git a/pkg/analyzer/lib/src/error/deprecated_member_use_verifier.dart b/pkg/analyzer/lib/src/error/deprecated_member_use_verifier.dart
index cd6f32f..3da477a 100644
--- a/pkg/analyzer/lib/src/error/deprecated_member_use_verifier.dart
+++ b/pkg/analyzer/lib/src/error/deprecated_member_use_verifier.dart
@@ -239,7 +239,11 @@
{required bool strictCasts}) {
// Implicit getters/setters.
if (element.isSynthetic && element is PropertyAccessorElement) {
- element = element.variable;
+ var variable = element.variable2;
+ if (variable == null) {
+ return null;
+ }
+ element = variable;
}
var annotation = element.metadata.firstWhereOrNull((e) => e.isDeprecated);
if (annotation == null || annotation.element is PropertyAccessorElement) {
@@ -266,8 +270,8 @@
if (element is PropertyAccessorElement && element.isSynthetic) {
// TODO(brianwilkerson): Why isn't this the implementation for PropertyAccessorElement?
- Element variable = element.variable;
- return variable.hasDeprecated;
+ var variable = element.variable2;
+ return variable != null && variable.hasDeprecated;
}
return element.hasDeprecated;
}
diff --git a/pkg/analyzer/lib/src/error/imports_verifier.dart b/pkg/analyzer/lib/src/error/imports_verifier.dart
index 892a81f..a3fbc77 100644
--- a/pkg/analyzer/lib/src/error/imports_verifier.dart
+++ b/pkg/analyzer/lib/src/error/imports_verifier.dart
@@ -684,7 +684,8 @@
if (element is PropertyAccessorElement) {
// If the getter or setter of a variable is used, then the variable (the
// shown name) is used.
- if (hasElement(identifier, element.variable)) {
+ var variable = element.variable2;
+ if (variable != null && hasElement(identifier, variable)) {
identifiers.remove(identifier);
break;
}
diff --git a/pkg/analyzer/lib/src/error/inheritance_override.dart b/pkg/analyzer/lib/src/error/inheritance_override.dart
index a802a40..8a16b8d 100644
--- a/pkg/analyzer/lib/src/error/inheritance_override.dart
+++ b/pkg/analyzer/lib/src/error/inheritance_override.dart
@@ -920,7 +920,7 @@
continue;
}
if (accessor.hasMustBeOverridden ||
- accessor.variable.hasMustBeOverridden) {
+ (accessor.variable2?.hasMustBeOverridden ?? false)) {
final PropertyAccessorElement? accessorDeclaration;
if (accessor.isGetter) {
accessorDeclaration = classElement.getGetter(accessor.name);
diff --git a/pkg/analyzer/lib/src/error/unused_local_elements_verifier.dart b/pkg/analyzer/lib/src/error/unused_local_elements_verifier.dart
index d89cff6..22714e9 100644
--- a/pkg/analyzer/lib/src/error/unused_local_elements_verifier.dart
+++ b/pkg/analyzer/lib/src/error/unused_local_elements_verifier.dart
@@ -16,6 +16,7 @@
import 'package:analyzer/src/dart/element/inheritance_manager3.dart';
import 'package:analyzer/src/dart/element/member.dart' show ExecutableMember;
import 'package:analyzer/src/error/codes.dart';
+import 'package:analyzer/src/utilities/extensions/object.dart';
import 'package:collection/collection.dart';
/// An [AstVisitor] that fills [UsedLocalElements].
@@ -246,12 +247,13 @@
if (element is ExecutableMember) {
element = element.declaration;
}
+ var variable = element.ifTypeOrNull<PropertyAccessorElement>()?.variable2;
bool isIdentifierRead = _isReadIdentifier(node);
if (element is PropertyAccessorElement &&
isIdentifierRead &&
- element.variable is TopLevelVariableElement) {
+ variable is TopLevelVariableElement) {
if (element.isSynthetic) {
- usedElements.addElement(element.variable);
+ usedElements.addElement(variable);
} else {
usedElements.members.add(element);
_addMemberAndCorrespondingGetter(element);
diff --git a/pkg/analyzer/lib/src/error/use_result_verifier.dart b/pkg/analyzer/lib/src/error/use_result_verifier.dart
index a2c7a2e..a579acd 100644
--- a/pkg/analyzer/lib/src/error/use_result_verifier.dart
+++ b/pkg/analyzer/lib/src/error/use_result_verifier.dart
@@ -168,7 +168,11 @@
static ElementAnnotation? _getUseResultMetadata(Element element) {
// Implicit getters/setters.
if (element.isSynthetic && element is PropertyAccessorElement) {
- element = element.variable;
+ var variable = element.variable2;
+ if (variable == null) {
+ return null;
+ }
+ element = variable;
}
return element.metadata.firstWhereOrNull((e) => e.isUseResult);
}
diff --git a/pkg/analyzer/lib/src/generated/element_resolver.dart b/pkg/analyzer/lib/src/generated/element_resolver.dart
index 47db46b..12203d6 100644
--- a/pkg/analyzer/lib/src/generated/element_resolver.dart
+++ b/pkg/analyzer/lib/src/generated/element_resolver.dart
@@ -487,7 +487,7 @@
// Ensure that the name always resolves to a top-level variable
// rather than a getter or setter
if (element is PropertyAccessorElement) {
- name.staticElement = element.variable;
+ name.staticElement = element.variable2;
} else {
name.staticElement = element;
}
diff --git a/pkg/analyzer/lib/src/generated/error_verifier.dart b/pkg/analyzer/lib/src/generated/error_verifier.dart
index 1b49272..6cea649 100644
--- a/pkg/analyzer/lib/src/generated/error_verifier.dart
+++ b/pkg/analyzer/lib/src/generated/error_verifier.dart
@@ -1798,7 +1798,10 @@
);
}
} else if (element is PropertyAccessorElement && element.isGetter) {
- var variable = element.variable;
+ var variable = element.variable2;
+ if (variable == null) {
+ return;
+ }
if (variable.isConst) {
errorReporter.atNode(
expression,
diff --git a/pkg/analyzer/lib/src/generated/ffi_verifier.dart b/pkg/analyzer/lib/src/generated/ffi_verifier.dart
index 70d7454..447a3fa 100644
--- a/pkg/analyzer/lib/src/generated/ffi_verifier.dart
+++ b/pkg/analyzer/lib/src/generated/ffi_verifier.dart
@@ -489,7 +489,11 @@
} else if (declarationElement is TopLevelVariableElement) {
type = declarationElement.type;
} else if (declarationElement is PropertyAccessorElement) {
- type = declarationElement.variable.type;
+ var variable = declarationElement.variable2;
+ if (variable == null) {
+ return;
+ }
+ type = variable.type;
} else {
_errorReporter.atNode(
errorNode,
@@ -665,7 +669,7 @@
return true;
}
if (staticElm is PropertyAccessorElementImpl) {
- if (staticElm.variable is ConstVariableElement) {
+ if (staticElm.variable2 is ConstVariableElement) {
return true;
}
}
@@ -841,9 +845,12 @@
return staticElm.computeConstantValue()?.toBoolValue();
}
if (staticElm is PropertyAccessorElementImpl) {
- final v = staticElm.variable;
- if (v is ConstVariableElement) {
- return v.computeConstantValue()?.toBoolValue();
+ final variable = staticElm.variable2;
+ if (variable == null) {
+ return null;
+ }
+ if (variable is ConstVariableElement) {
+ return variable.computeConstantValue()?.toBoolValue();
}
}
}
diff --git a/pkg/analyzer/lib/src/generated/resolver.dart b/pkg/analyzer/lib/src/generated/resolver.dart
index 5518ec9..e491879 100644
--- a/pkg/analyzer/lib/src/generated/resolver.dart
+++ b/pkg/analyzer/lib/src/generated/resolver.dart
@@ -1657,7 +1657,10 @@
node is SimpleIdentifier) {
if (element is PropertyAccessorElement && element.isSetter) {
if (element.isSynthetic) {
- writeType = element.variable.type;
+ var variable = element.variable2;
+ if (variable != null) {
+ writeType = variable.type;
+ }
} else {
var parameters = element.parameters;
if (parameters.length == 1) {
@@ -5115,7 +5118,7 @@
if (caseConstant != null) {
var element = _referencedElement(caseConstant);
if (element is PropertyAccessorElement) {
- _enumConstants!.remove(element.variable);
+ _enumConstants!.remove(element.variable2);
}
if (caseConstant is NullLiteral) {
_isNullEnumValueCovered = true;
diff --git a/pkg/analyzer/lib/src/generated/testing/element_factory.dart b/pkg/analyzer/lib/src/generated/testing/element_factory.dart
index 03efd69..49b930d 100644
--- a/pkg/analyzer/lib/src/generated/testing/element_factory.dart
+++ b/pkg/analyzer/lib/src/generated/testing/element_factory.dart
@@ -193,7 +193,7 @@
PropertyAccessorElementImpl getter = PropertyAccessorElementImpl(name, 0);
getter.isSynthetic = false;
getter.isGetter = true;
- getter.variable = field;
+ getter.variable2 = field;
getter.returnType = type;
getter.isStatic = isStatic;
field.getter = getter;
@@ -331,14 +331,14 @@
field.type = type;
PropertyAccessorElementImpl getter = PropertyAccessorElementImpl(name, -1);
getter.isGetter = true;
- getter.variable = field;
+ getter.variable2 = field;
getter.returnType = type;
field.getter = getter;
ParameterElementImpl parameter = requiredParameter2("a", type);
PropertyAccessorElementImpl setter = PropertyAccessorElementImpl(name, -1);
setter.isSetter = true;
setter.isSynthetic = true;
- setter.variable = field;
+ setter.variable2 = field;
setter.parameters = <ParameterElement>[parameter];
setter.returnType = VoidTypeImpl.instance;
setter.isStatic = isStatic;
diff --git a/pkg/analyzer/lib/src/services/top_level_declarations.dart b/pkg/analyzer/lib/src/services/top_level_declarations.dart
index 44ce77f..5f1aee0 100644
--- a/pkg/analyzer/lib/src/services/top_level_declarations.dart
+++ b/pkg/analyzer/lib/src/services/top_level_declarations.dart
@@ -106,6 +106,12 @@
static Element? _findElement(LibraryElement libraryElement, String name) {
var element = libraryElement.exportNamespace.get(name) ??
libraryElement.exportNamespace.get('$name=');
- return element is PropertyAccessorElement ? element.variable : element;
+ if (element is PropertyAccessorElement) {
+ var variable = element.variable2;
+ if (variable != null) {
+ return variable;
+ }
+ }
+ return element;
}
}
diff --git a/pkg/analyzer/lib/src/summary2/bundle_reader.dart b/pkg/analyzer/lib/src/summary2/bundle_reader.dart
index a31a95f..89ae8c9 100644
--- a/pkg/analyzer/lib/src/summary2/bundle_reader.dart
+++ b/pkg/analyzer/lib/src/summary2/bundle_reader.dart
@@ -1593,7 +1593,7 @@
}
}
- accessor.variable = property;
+ accessor.variable2 = property;
if (isGetter) {
property.getter = accessor;
} else {
@@ -1910,7 +1910,7 @@
if (augmentationTarget is PropertyAccessorElementImpl) {
augmentationTarget.augmentation = element;
element.augmentationTarget = augmentationTarget;
- element.variable = augmentationTarget.variable;
+ element.variable2 = augmentationTarget.variable2;
}
applyConstantOffsets?.perform();
diff --git a/pkg/analyzer/lib/src/summary2/element_builder.dart b/pkg/analyzer/lib/src/summary2/element_builder.dart
index d75f077..5aa41a7 100644
--- a/pkg/analyzer/lib/src/summary2/element_builder.dart
+++ b/pkg/analyzer/lib/src/summary2/element_builder.dart
@@ -1353,7 +1353,7 @@
}
}
- accessorElement.variable = property;
+ accessorElement.variable2 = property;
if (accessorElement.isGetter) {
property.getter = accessorElement;
} else {
diff --git a/pkg/analyzer/lib/src/summary2/library_builder.dart b/pkg/analyzer/lib/src/summary2/library_builder.dart
index 6485a57..7b0d5c5 100644
--- a/pkg/analyzer/lib/src/summary2/library_builder.dart
+++ b/pkg/analyzer/lib/src/summary2/library_builder.dart
@@ -72,7 +72,7 @@
if (existing != null) {
existing.augmentation = element;
element.augmentationTarget = existing;
- element.variable = existing.variable;
+ element.variable2 = existing.variable2;
}
}
accessors[name] = element;
@@ -152,7 +152,7 @@
if (existing != null) {
existing.augmentation = element;
element.augmentationTarget = existing;
- element.variable = existing.variable;
+ element.variable2 = existing.variable2;
}
}
accessors[name] = element;
@@ -1451,7 +1451,8 @@
var nonPromotabilityReason = addGetter(classInfo, accessor, accessor.name,
isAbstract: accessor.isAbstract);
if (enabled && nonPromotabilityReason == null) {
- _potentiallyPromotableFields.add(accessor.variable as FieldElementImpl);
+ _potentiallyPromotableFields
+ .add(accessor.variable2 as FieldElementImpl);
}
}
}
diff --git a/pkg/analyzer/lib/src/summary2/macro_application.dart b/pkg/analyzer/lib/src/summary2/macro_application.dart
index 780ee6b..6b19a98 100644
--- a/pkg/analyzer/lib/src/summary2/macro_application.dart
+++ b/pkg/analyzer/lib/src/summary2/macro_application.dart
@@ -1240,7 +1240,7 @@
final lookup = libraryElement.scope.lookup(name);
var element = lookup.getter ?? lookup.setter;
if (element is PropertyAccessorElement && element.isSynthetic) {
- element = element.variable;
+ element = element.variable2;
}
if (element == null) {
throw macro.MacroImplementationExceptionImpl(
diff --git a/pkg/analyzer/lib/src/test_utilities/mock_sdk_elements.dart b/pkg/analyzer/lib/src/test_utilities/mock_sdk_elements.dart
index 12da463..ee8ca6d 100644
--- a/pkg/analyzer/lib/src/test_utilities/mock_sdk_elements.dart
+++ b/pkg/analyzer/lib/src/test_utilities/mock_sdk_elements.dart
@@ -1041,7 +1041,7 @@
getter.isStatic = isStatic;
getter.isSynthetic = false;
getter.returnType = type;
- getter.variable = field;
+ getter.variable2 = field;
field.getter = getter;
return getter;
@@ -1109,7 +1109,7 @@
) {
classElement.accessors = accessors;
classElement.fields = accessors
- .map((accessor) => accessor.variable)
+ .map((accessor) => accessor.variable2)
.cast<FieldElementImpl>()
.toList();
}
diff --git a/pkg/analyzer/test/generated/element_resolver_test.dart b/pkg/analyzer/test/generated/element_resolver_test.dart
index 2293b9b..a45ebc3f 100644
--- a/pkg/analyzer/test/generated/element_resolver_test.dart
+++ b/pkg/analyzer/test/generated/element_resolver_test.dart
@@ -366,7 +366,7 @@
.exportedLibrary!
.exportNamespace
.get('pi') as PropertyAccessorElement;
- expect(findNode.simple('pi').staticElement, pi.variable);
+ expect(findNode.simple('pi').staticElement, pi.variable2);
}
test_visitExportDirective_noCombinators() async {
@@ -399,7 +399,7 @@
.importedLibrary!
.exportNamespace
.get('pi') as PropertyAccessorElement;
- expect(findNode.simple('pi').staticElement, pi.variable);
+ expect(findNode.simple('pi').staticElement, pi.variable2);
}
test_visitImportDirective_combinators_prefix() async {
@@ -411,9 +411,9 @@
var mathNamespace =
findElement.import('dart:math').importedLibrary!.exportNamespace;
var pi = mathNamespace.get('pi') as PropertyAccessorElement;
- expect(findNode.simple('pi').staticElement, pi.variable);
+ expect(findNode.simple('pi').staticElement, pi.variable2);
var ln10 = mathNamespace.get('ln10') as PropertyAccessorElement;
- expect(findNode.simple('ln10').staticElement, ln10.variable);
+ expect(findNode.simple('ln10').staticElement, ln10.variable2);
}
test_visitImportDirective_noCombinators_noPrefix() async {
diff --git a/pkg/analyzer/test/id_tests/constant_test.dart b/pkg/analyzer/test/id_tests/constant_test.dart
index c39539e..7a376300 100644
--- a/pkg/analyzer/test/id_tests/constant_test.dart
+++ b/pkg/analyzer/test/id_tests/constant_test.dart
@@ -62,7 +62,7 @@
if (node is Identifier) {
var element = node.staticElement;
if (element is PropertyAccessorElement && element.isSynthetic) {
- var variable = element.variable;
+ var variable = element.variable2!;
if (!variable.isSynthetic && variable.isConst) {
var value = variable.computeConstantValue();
if (value != null) return _stringify(value);
diff --git a/pkg/analyzer/test/src/dart/element/element_test.dart b/pkg/analyzer/test/src/dart/element/element_test.dart
index 99d83b2..214cee6 100644
--- a/pkg/analyzer/test/src/dart/element/element_test.dart
+++ b/pkg/analyzer/test/src/dart/element/element_test.dart
@@ -2007,7 +2007,7 @@
''');
SimpleIdentifier argument = findNode.simple('C);');
var getter = argument.staticElement as PropertyAccessorElementImpl;
- var constant = getter.variable as TopLevelVariableElement;
+ var constant = getter.variable2 as TopLevelVariableElement;
DartObject value = constant.computeConstantValue()!;
expect(value, isNotNull);
diff --git a/pkg/analyzer/test/src/dart/element/inheritance_manager3_test.dart b/pkg/analyzer/test/src/dart/element/inheritance_manager3_test.dart
index a083b21..af2c828 100644
--- a/pkg/analyzer/test/src/dart/element/inheritance_manager3_test.dart
+++ b/pkg/analyzer/test/src/dart/element/inheritance_manager3_test.dart
@@ -2700,7 +2700,7 @@
expect(actual, expected);
if (element is PropertyAccessorElement) {
- var variable = element.variable;
+ var variable = element.variable2!;
expect(variable.enclosingElement, same(element.enclosingElement));
expect(variable.name, element.displayName);
if (element.isGetter) {
diff --git a/pkg/analyzer/test/src/dart/resolution/optional_const_test.dart b/pkg/analyzer/test/src/dart/resolution/optional_const_test.dart
index abb3692..7f0e68f 100644
--- a/pkg/analyzer/test/src/dart/resolution/optional_const_test.dart
+++ b/pkg/analyzer/test/src/dart/resolution/optional_const_test.dart
@@ -275,7 +275,7 @@
''');
var vg = findNode.simple('a;').staticElement as PropertyAccessorElement;
- var v = vg.variable as ConstVariableElement;
+ var v = vg.variable2 as ConstVariableElement;
var creation = v.constantInitializer as InstanceCreationExpression;
return creation;
diff --git a/pkg/analyzer/test/src/summary/element_text.dart b/pkg/analyzer/test/src/summary/element_text.dart
index a63d145..a501837 100644
--- a/pkg/analyzer/test/src/summary/element_text.dart
+++ b/pkg/analyzer/test/src/summary/element_text.dart
@@ -1146,14 +1146,17 @@
void _writePropertyAccessorElement(PropertyAccessorElement e) {
e as PropertyAccessorElementImpl;
- PropertyInducingElement variable = e.variable;
- expect(variable, isNotNull);
-
- var variableEnclosing = variable.enclosingElement;
- if (variableEnclosing is CompilationUnitElement) {
- expect(variableEnclosing.topLevelVariables, contains(variable));
- } else if (variableEnclosing is InterfaceElement) {
- expect(variableEnclosing.fields, contains(variable));
+ var variable = e.variable2;
+ if (variable != null) {
+ var variableEnclosing = variable.enclosingElement;
+ if (variableEnclosing is CompilationUnitElement) {
+ expect(variableEnclosing.topLevelVariables, contains(variable));
+ } else if (variableEnclosing is InterfaceElement) {
+ expect(variableEnclosing.fields, contains(variable));
+ }
+ } else {
+ expect(e.isAugmentation, isTrue);
+ expect(e.augmentationTarget, isNull);
}
if (e.isSynthetic) {
@@ -1183,7 +1186,9 @@
void writeLinking() {
if (configuration.withPropertyLinking) {
_sink.writelnWithIndent('id: ${_idMap[e]}');
- _sink.writelnWithIndent('variable: ${_idMap[e.variable]}');
+ if (e.variable2 case final variable?) {
+ _sink.writelnWithIndent('variable: ${_idMap[variable]}');
+ }
}
}
diff --git a/pkg/analyzer/test/src/summary/elements_test.dart b/pkg/analyzer/test/src/summary/elements_test.dart
index 6943c18..ab80bb0a 100644
--- a/pkg/analyzer/test/src/summary/elements_test.dart
+++ b/pkg/analyzer/test/src/summary/elements_test.dart
@@ -47669,7 +47669,7 @@
// requesting individual elements, not all accessors/variables at once.
var getter = _elementOfDefiningUnit(library, ['@getter', 'x'])
as PropertyAccessorElementImpl;
- var variable = getter.variable as TopLevelVariableElementImpl;
+ var variable = getter.variable2 as TopLevelVariableElementImpl;
expect(variable, isNotNull);
expect(variable.isFinal, isFalse);
expect(variable.getter, same(getter));
diff --git a/pkg/analyzer_plugin/lib/utilities/completion/type_member_contributor.dart b/pkg/analyzer_plugin/lib/utilities/completion/type_member_contributor.dart
index f5f024d..156236d 100644
--- a/pkg/analyzer_plugin/lib/utilities/completion/type_member_contributor.dart
+++ b/pkg/analyzer_plugin/lib/utilities/completion/type_member_contributor.dart
@@ -323,7 +323,9 @@
if (propertyAccessor.isSynthetic) {
// Avoid visiting a field twice
if (propertyAccessor.isGetter) {
- _addSuggestion(propertyAccessor.variable);
+ if (propertyAccessor.variable2 case var variable?) {
+ _addSuggestion(variable);
+ }
}
} else {
_addSuggestion(propertyAccessor);
diff --git a/pkg/linter/lib/src/ast.dart b/pkg/linter/lib/src/ast.dart
index c6b0816..35fe821 100644
--- a/pkg/linter/lib/src/ast.dart
+++ b/pkg/linter/lib/src/ast.dart
@@ -335,7 +335,10 @@
// Skipping library level getters, test that the enclosing element is
// the same
if (staticElement.enclosingElement == enclosingElement) {
- return staticElement.isSynthetic && staticElement.variable.isPrivate;
+ var variable = staticElement.variable2;
+ if (variable != null) {
+ return staticElement.isSynthetic && variable.isPrivate;
+ }
}
}
}
diff --git a/pkg/linter/lib/src/extensions.dart b/pkg/linter/lib/src/extensions.dart
index a0e4233..4321f82 100644
--- a/pkg/linter/lib/src/extensions.dart
+++ b/pkg/linter/lib/src/extensions.dart
@@ -286,7 +286,7 @@
Element get canonicalElement {
var self = this;
if (self is PropertyAccessorElement) {
- var variable = self.variable;
+ var variable = self.variable2;
if (variable is FieldMember) {
// A field element defined in a parameterized type where the values of
// the type parameters are known.
@@ -296,12 +296,11 @@
// equivalent to equivalent FieldMembers. See
// https://github.com/dart-lang/sdk/issues/35343.
return variable.declaration;
- } else {
+ } else if (variable != null) {
return variable;
}
- } else {
- return self;
}
+ return self;
}
}
diff --git a/pkg/linter/lib/src/rules/exhaustive_cases.dart b/pkg/linter/lib/src/rules/exhaustive_cases.dart
index 317dbd5..7528252 100644
--- a/pkg/linter/lib/src/rules/exhaustive_cases.dart
+++ b/pkg/linter/lib/src/rules/exhaustive_cases.dart
@@ -164,7 +164,12 @@
extension on Element? {
Element? get variableElement {
var self = this;
- if (self is PropertyAccessorElement) return self.variable;
+ if (self is PropertyAccessorElement) {
+ var variable = self.variable2;
+ if (variable != null) {
+ return variable;
+ }
+ }
return self;
}
}
diff --git a/pkg/linter/lib/src/rules/unnecessary_lambdas.dart b/pkg/linter/lib/src/rules/unnecessary_lambdas.dart
index 9a71fe2..9bac670 100644
--- a/pkg/linter/lib/src/rules/unnecessary_lambdas.dart
+++ b/pkg/linter/lib/src/rules/unnecessary_lambdas.dart
@@ -66,9 +66,11 @@
/// `late`.
bool isFinalElement(Element? element) {
if (element is PropertyAccessorElement) {
+ var variable = element.variable2;
return element.isSynthetic &&
- element.variable.isFinal &&
- !element.variable.isLate;
+ variable != null &&
+ variable.isFinal &&
+ !variable.isLate;
} else if (element is VariableElement) {
return element.isFinal && !element.isLate;
}
diff --git a/pkg/linter/lib/src/util/leak_detector_visitor.dart b/pkg/linter/lib/src/util/leak_detector_visitor.dart
index 7e7cfad..ae28c77 100644
--- a/pkg/linter/lib/src/util/leak_detector_visitor.dart
+++ b/pkg/linter/lib/src/util/leak_detector_visitor.dart
@@ -59,7 +59,7 @@
Element? propertyElement, VariableElement? variableElement) =>
propertyElement == variableElement ||
propertyElement is PropertyAccessorElement &&
- propertyElement.variable == variableElement;
+ propertyElement.variable2 == variableElement;
bool _isInvocationThroughCascadeExpression(
MethodInvocation invocation, VariableElement variableElement) {
@@ -71,7 +71,7 @@
if (identifier is SimpleIdentifier) {
var element = identifier.staticElement;
if (element is PropertyAccessorElement) {
- return element.variable == variableElement;
+ return element.variable2 == variableElement;
}
}
return false;