| Index: pkg/analyzer/lib/src/dart/element/element.dart
|
| diff --git a/pkg/analyzer/lib/src/dart/element/element.dart b/pkg/analyzer/lib/src/dart/element/element.dart
|
| index 362a70720d3982d4657067236374145ae9ad46ef..448dce5b15972e36d2b52dfb98494ba862e94d05 100644
|
| --- a/pkg/analyzer/lib/src/dart/element/element.dart
|
| +++ b/pkg/analyzer/lib/src/dart/element/element.dart
|
| @@ -417,6 +417,11 @@ class ClassElementImpl extends AbstractClassElementImpl
|
| */
|
| final kernel.Class _kernel;
|
|
|
| + /**
|
| + * If this class is resynthesized, whether it has a constant constructor.
|
| + */
|
| + bool _hasConstConstructorCached;
|
| +
|
| /**
|
| * The actual supertype extracted from desugared [_kernel].
|
| */
|
| @@ -1018,8 +1023,22 @@ class ClassElementImpl extends AbstractClassElementImpl
|
| return null;
|
| }
|
|
|
| - bool get _hasConstConstructorKernel =>
|
| - _kernel != null && _kernel.constructors.any((c) => c.isConst);
|
| + /**
|
| + * Return whether the class is resynthesized and has a constant constructor.
|
| + */
|
| + bool get _hasConstConstructor {
|
| + if (_hasConstConstructorCached == null) {
|
| + _hasConstConstructorCached = false;
|
| + if (_kernel != null) {
|
| + _hasConstConstructorCached = _kernel.constructors.any((c) => c.isConst);
|
| + }
|
| + if (_unlinkedClass != null) {
|
| + _hasConstConstructorCached = _unlinkedClass.executables.any(
|
| + (c) => c.kind == UnlinkedExecutableKind.constructor && c.isConst);
|
| + }
|
| + }
|
| + return _hasConstConstructorCached;
|
| + }
|
|
|
| @override
|
| void appendTo(StringBuffer buffer) {
|
| @@ -4552,7 +4571,9 @@ class FieldElementImpl extends PropertyInducingElementImpl
|
| factory FieldElementImpl.forKernelFactory(
|
| ClassElementImpl enclosingClass, kernel.Field kernel) {
|
| if (kernel.isConst ||
|
| - kernel.isFinal && enclosingClass._hasConstConstructorKernel) {
|
| + kernel.isFinal &&
|
| + !kernel.isStatic &&
|
| + enclosingClass._hasConstConstructor) {
|
| return new ConstFieldElementImpl.forKernel(enclosingClass, kernel);
|
| } else {
|
| return new FieldElementImpl.forKernel(enclosingClass, kernel);
|
| @@ -4578,7 +4599,9 @@ class FieldElementImpl extends PropertyInducingElementImpl
|
| UnlinkedVariable unlinkedVariable, ClassElementImpl enclosingClass) {
|
| if (unlinkedVariable.initializer?.bodyExpr != null &&
|
| (unlinkedVariable.isConst ||
|
| - unlinkedVariable.isFinal && !unlinkedVariable.isStatic)) {
|
| + unlinkedVariable.isFinal &&
|
| + !unlinkedVariable.isStatic &&
|
| + enclosingClass._hasConstConstructor)) {
|
| return new ConstFieldElementImpl.forSerialized(
|
| unlinkedVariable, enclosingClass);
|
| } else {
|
|
|