Version 3.2.0-1.0.dev
Merge ba005169c5147693134d0d46598038d252231873 into dev
diff --git a/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml b/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml
index a005a14..4903050 100644
--- a/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml
+++ b/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml
@@ -2400,10 +2400,7 @@
LintCode.unnecessary_to_list_in_spreads:
status: hasFix
LintCode.unreachable_from_main:
- status: noFix
- notes: |-
- Theoretically we could remove the unreachable declaration, but that seems
- like a dangerous option to provide.
+ status: hasFix
LintCode.unrelated_type_equality_checks_expression:
status: needsEvaluation
LintCode.unrelated_type_equality_checks_pattern:
diff --git a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
index 7ee896f..683275f 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
@@ -781,6 +781,9 @@
LintNames.unnecessary_this: [
RemoveThisExpression.new,
],
+ LintNames.unreachable_from_main: [
+ RemoveUnusedElement.new,
+ ],
LintNames.use_decorated_box: [
ReplaceWithDecoratedBox.new,
],
diff --git a/pkg/analysis_server/lib/src/services/linter/lint_names.dart b/pkg/analysis_server/lib/src/services/linter/lint_names.dart
index e2ce6ed..99595bb 100644
--- a/pkg/analysis_server/lib/src/services/linter/lint_names.dart
+++ b/pkg/analysis_server/lib/src/services/linter/lint_names.dart
@@ -184,6 +184,7 @@
static const String unnecessary_to_list_in_spreads =
'unnecessary_to_list_in_spreads';
static const String unnecessary_this = 'unnecessary_this';
+ static const String unreachable_from_main = 'unreachable_from_main';
static const String use_decorated_box = 'use_decorated_box';
static const String use_enums = 'use_enums';
static const String use_full_hex_values_for_flutter_colors =
diff --git a/pkg/analysis_server/test/src/services/correction/fix/remove_unused_element_test.dart b/pkg/analysis_server/test/src/services/correction/fix/remove_unused_element_test.dart
index 5711cbd..406fd6e 100644
--- a/pkg/analysis_server/test/src/services/correction/fix/remove_unused_element_test.dart
+++ b/pkg/analysis_server/test/src/services/correction/fix/remove_unused_element_test.dart
@@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
import 'package:analysis_server/src/services/correction/fix.dart';
+import 'package:analysis_server/src/services/linter/lint_names.dart';
import 'package:analyzer/error/error.dart';
import 'package:analyzer/src/error/codes.dart';
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
@@ -12,11 +13,49 @@
void main() {
defineReflectiveSuite(() {
+ defineReflectiveTests(RemoveUnreachableFromMainTest);
defineReflectiveTests(RemoveUnusedElementTest);
});
}
@reflectiveTest
+class RemoveUnreachableFromMainTest extends FixProcessorLintTest {
+ @override
+ FixKind get kind => DartFixKind.REMOVE_UNUSED_ELEMENT;
+
+ @override
+ String get lintCode => LintNames.unreachable_from_main;
+
+ Future<void> test_class() async {
+ await resolveTestCode(r'''
+void main() {}
+class C {}
+''');
+ await assertHasFix(r'''
+void main() {}
+''');
+ }
+
+ Future<void> test_method() async {
+ await resolveTestCode(r'''
+void main() {
+ C();
+}
+class C {
+ void m() {}
+}
+''');
+ await assertHasFix(r'''
+void main() {
+ C();
+}
+class C {
+}
+''');
+ }
+}
+
+@reflectiveTest
class RemoveUnusedElementTest extends FixProcessorTest {
@override
FixKind get kind => DartFixKind.REMOVE_UNUSED_ELEMENT;
@@ -87,8 +126,7 @@
await resolveTestCode(r'''
class _A {}
void f(p) {
- if (p is _A) {
- }
+ if (p is _A) {}
}
''');
// We don't know what to do with the reference.
@@ -97,8 +135,7 @@
Future<void> test_class_notUsed_noReference() async {
await resolveTestCode(r'''
-class _A {
-}
+class _A {}
''');
await assertHasFix(r'''
''');
@@ -161,24 +198,20 @@
Future<void> test_functionTop_notUsed_noReference() async {
await resolveTestCode(r'''
_f() {}
-void f() {
-}
+void f() {}
''');
await assertHasFix(r'''
-void f() {
-}
+void f() {}
''');
}
Future<void> test_functionTypeAlias_notUsed_noReference() async {
await resolveTestCode(r'''
typedef _F(a, b);
-void f() {
-}
+void f() {}
''');
await assertHasFix(r'''
-void f() {
-}
+void f() {}
''');
}
diff --git a/pkg/analyzer/lib/src/dart/constant/evaluation.dart b/pkg/analyzer/lib/src/dart/constant/evaluation.dart
index bf4f367..540b751 100644
--- a/pkg/analyzer/lib/src/dart/constant/evaluation.dart
+++ b/pkg/analyzer/lib/src/dart/constant/evaluation.dart
@@ -22,6 +22,7 @@
import 'package:analyzer/src/dart/constant/potentially_constant.dart';
import 'package:analyzer/src/dart/element/element.dart';
import 'package:analyzer/src/dart/element/member.dart';
+import 'package:analyzer/src/dart/element/type.dart';
import 'package:analyzer/src/dart/element/type_algebra.dart';
import 'package:analyzer/src/dart/element/type_system.dart' show TypeSystemImpl;
import 'package:analyzer/src/error/codes.dart';
@@ -192,7 +193,7 @@
);
ConstantVisitor constantVisitor =
ConstantVisitor(this, library, errorReporter);
- var result = evaluateConstructorCall(
+ final result = evaluateConstructorCall(
library,
constNode,
element.returnType2.ifTypeOrNull<InterfaceType>()?.typeArguments,
@@ -200,8 +201,11 @@
element,
constantVisitor,
errorReporter);
+ // TODO(kallentu): Report the InvalidConstant returned from the
+ // constructor call.
+ final evaluationConstant = result is DartObjectImpl ? result : null;
constant.evaluationResult =
- EvaluationResultImpl(result, errorListener.errors);
+ EvaluationResultImpl(evaluationConstant, errorListener.errors);
} else {
// This may happen for invalid code (e.g. failing to pass arguments
// to an annotation which references a const constructor). The error
@@ -339,7 +343,7 @@
}
}
- DartObjectImpl? evaluateConstructorCall(
+ Constant evaluateConstructorCall(
LibraryElementImpl library,
AstNode node,
List<DartType>? typeArguments,
@@ -451,6 +455,19 @@
NullState.NULL_STATE,
);
}
+
+ /// Returns the representation of a constant expression which has an
+ /// [InvalidType], with the given [defaultType].
+ static DartObjectImpl _unresolvedObject(
+ LibraryElementImpl library, DartType defaultType) {
+ // TODO(kallentu): Use a better representation of an unresolved object that
+ // doesn't need to rely on NullState.
+ return DartObjectImpl(
+ library.typeSystem,
+ defaultType,
+ NullState(isInvalid: true),
+ );
+ }
}
/// Interface for [AnalysisTarget]s for which constant evaluation can be
@@ -874,18 +891,19 @@
}
@override
- Constant? visitInstanceCreationExpression(InstanceCreationExpression node) {
+ Constant visitInstanceCreationExpression(InstanceCreationExpression node) {
if (!node.isConst) {
// TODO(https://github.com/dart-lang/sdk/issues/47061): Use a specific
// error code.
_error(node, null);
- return null;
+ return InvalidConstant(node, CompileTimeErrorCode.INVALID_CONSTANT);
}
var constructor = node.constructorName.staticElement;
if (constructor == null) {
// Couldn't resolve the constructor so we can't compute a value. No
// problem - the error has already been reported.
- return null;
+ // TODO(kallentu): Use a better error code for this.
+ return InvalidConstant(node, CompileTimeErrorCode.INVALID_CONSTANT);
}
return evaluationEngine.evaluateConstructorCall(
@@ -1011,6 +1029,18 @@
}
}
}
+
+ // Some methods aren't resolved by the time we are evaluating it. We'll mark
+ // it and return immediately.
+ if (node.staticType is InvalidType) {
+ // TODO(kallentu): This error reporting retains the same behaviour as
+ // before. Move this error reporting elsewhere.
+ _errorReporter.reportErrorForNode(
+ CompileTimeErrorCode.INVALID_CONSTANT, node);
+ return InvalidConstant(node, CompileTimeErrorCode.INVALID_CONSTANT,
+ isUnresolved: true);
+ }
+
// TODO(kallentu): Don't report error here.
_errorReporter.reportErrorForNode(
CompileTimeErrorCode.CONST_EVAL_METHOD_INVOCATION, node);
@@ -1534,7 +1564,7 @@
/// [UnifyingAstVisitor] allows it. If we encounter an unexpected `null`
/// value, we will return an [InvalidConstant] instead.
Constant _getConstant(AstNode node) {
- var result = node.accept(this);
+ final result = node.accept(this);
if (result == null) {
// Should never reach this.
return InvalidConstant(node, CompileTimeErrorCode.INVALID_CONSTANT);
@@ -1556,8 +1586,9 @@
required Element? element,
DartType? givenType,
}) {
+ final errorNode2 = evaluationEngine.configuration.errorNode(errorNode);
element = element?.declaration;
- var variableElement =
+ final variableElement =
element is PropertyAccessorElement ? element.variable : element;
// TODO(srawlins): Remove this check when [FunctionReference]s are inserted
@@ -1576,13 +1607,32 @@
// and errors for other constant expressions. In either case we have
// already computed values of all dependencies first (or detect a cycle),
// so the value has already been computed and we can just return it.
- var result = variableElement.evaluationResult;
- if (variableElement.isConst && result != null) {
- var value = result.value;
- if (value == null || identifier == null) {
+ final result = variableElement.evaluationResult;
+ final isConstField = variableElement is FieldElement &&
+ (variableElement.isConst || variableElement.isFinal);
+ if (isConstField || variableElement.isConst) {
+ // The constant value isn't computed yet, or there is an error while
+ // computing. We will mark it and determine whether or not to continue
+ // the evaluation upstream.
+ if (result == null) {
+ _error(errorNode2, null);
+ return InvalidConstant(
+ errorNode, CompileTimeErrorCode.INVALID_CONSTANT,
+ isUnresolved: true);
+ }
+
+ final value = result.value;
+ if (value == null) {
+ // TODO(kallentu): Investigate and fix the test failures that occur if
+ // we report errors here.
+ return InvalidConstant(
+ errorNode, CompileTimeErrorCode.INVALID_CONSTANT,
+ isUnresolved: true);
+ } else if (identifier == null) {
return InvalidConstant(
errorNode, CompileTimeErrorCode.INVALID_CONSTANT);
}
+
return _instantiateFunctionTypeForSimpleIdentifier(identifier, value);
}
} else if (variableElement is ConstructorElementImpl &&
@@ -1658,9 +1708,18 @@
}
}
+ // The expression is unresolved by the time we are evaluating it. We'll mark
+ // it and return immediately.
+ if (expression != null && expression.staticType is InvalidType) {
+ // TODO(kallentu): This error reporting retains the same behaviour as
+ // before. Move this error reporting elsewhere.
+ _error(errorNode2, null);
+ return InvalidConstant(errorNode, CompileTimeErrorCode.INVALID_CONSTANT,
+ isUnresolved: true);
+ }
+
// TODO(https://github.com/dart-lang/sdk/issues/47061): Use a specific
// error code.
- final errorNode2 = evaluationEngine.configuration.errorNode(errorNode);
_error(errorNode2, null);
return InvalidConstant(errorNode2, CompileTimeErrorCode.INVALID_CONSTANT);
}
@@ -1807,14 +1866,17 @@
notPotentiallyConstants.first, CompileTimeErrorCode.INVALID_CONSTANT);
}
- /// Return the value of the given [expression], or a representation of 'null'
- /// if the expression cannot be evaluated.
- DartObjectImpl _valueOf(Expression expression) {
- var expressionValue = expression.accept(this);
- if (expressionValue is DartObjectImpl) {
- return expressionValue;
+ /// Return the value of the given [expression], or a representation of a fake
+ /// constant to continue the evaluation if the expression is unresolved.
+ Constant _valueOf(Expression expression, DartType defaultType) {
+ final expressionValue = _getConstant(expression);
+ switch (expressionValue) {
+ case InvalidConstant(isUnresolved: true):
+ return ConstantEvaluationEngine._unresolvedObject(
+ _library, defaultType);
+ case Constant():
+ return expressionValue;
}
- return ConstantEvaluationEngine._nullObject(_library);
}
}
@@ -2267,15 +2329,17 @@
/// The result of evaluation the initializers declared on a const constructor.
class _InitializersEvaluationResult {
- /// The result of a const evaluation of an initializer, if one was performed,
- /// otherwise `null`.
+ /// The result of a const evaluation of an initializer.
+ ///
+ /// If the evaluation of the const instance creation expression is incomplete,
+ /// then [result] will be `null`.
///
/// If a redirecting initializer which redirects to a const constructor was
/// encountered, [result] is the result of evaluating that call.
///
/// If an assert initializer is encountered, and the evaluation of this assert
- /// results in an error or a `false` value, [result] is `null`.
- final DartObjectImpl? result;
+ /// results in an error or a `false` value, [result] is an [InvalidConstant].
+ final Constant? result;
/// Whether evaluation of the const instance creation expression which led to
/// evaluating constructor initializers is complete.
@@ -2416,19 +2480,21 @@
TypeSystemImpl get typeSystem => _library.typeSystem;
/// Evaluates this constructor call as a factory constructor call.
- DartObjectImpl? evaluateFactoryConstructorCall(
+ Constant evaluateFactoryConstructorCall(
List<Expression> arguments, {
required bool isNullSafe,
}) {
final definingClass = _constructor.enclosingElement2;
- var argumentCount = arguments.length;
+ final argumentCount = arguments.length;
final definingType = this.definingType;
if (definingType is InterfaceType &&
_constructor.name == "fromEnvironment") {
if (!_checkFromEnvironmentArguments(arguments, definingType)) {
+ // TODO(kallentu): Don't report error here.
_errorReporter.reportErrorForNode(
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, _errorNode);
- return null;
+ return InvalidConstant(
+ _errorNode, CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION);
}
String? variableName =
argumentCount < 1 ? null : firstArgument?.toStringValue();
@@ -2452,16 +2518,18 @@
}
} else if (_constructor.name == 'hasEnvironment' &&
definingClass == typeProvider.boolElement) {
- var name = argumentCount < 1 ? null : firstArgument?.toStringValue();
+ final name = argumentCount < 1 ? null : firstArgument?.toStringValue();
return FromEnvironmentEvaluator(typeSystem, _declaredVariables)
.hasEnvironment(name);
} else if (_constructor.name == "" &&
definingClass == typeProvider.symbolElement &&
argumentCount == 1) {
if (!_checkSymbolArguments(arguments, isNullSafe: isNullSafe)) {
+ // TODO(kallentu): Don't report error here.
_errorReporter.reportErrorForNode(
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, _errorNode);
- return null;
+ return InvalidConstant(
+ _errorNode, CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION);
}
return DartObjectImpl(
typeSystem,
@@ -2479,24 +2547,40 @@
return DartObjectImpl.validWithUnknownValue(typeSystem, definingType);
}
- DartObjectImpl? evaluateGenerativeConstructorCall(
- List<Expression> arguments) {
+ Constant evaluateGenerativeConstructorCall(List<Expression> arguments) {
+ InvalidConstant? error;
+
// Start with final fields that are initialized at their declaration site.
- _checkFields();
+ error = _checkFields();
+ if (error != null) {
+ return error;
+ }
_checkTypeParameters();
- _checkParameters(arguments);
- var evaluationResult = _checkInitializers();
- if (evaluationResult.evaluationIsComplete) {
- return evaluationResult.result;
+
+ error = _checkParameters(arguments);
+ if (error != null) {
+ return error;
}
- _checkSuperConstructorCall(
+
+ final evaluationResult = _checkInitializers();
+ final result = evaluationResult.result;
+ if (result != null && evaluationResult.evaluationIsComplete) {
+ return result;
+ }
+
+ error = _checkSuperConstructorCall(
superName: evaluationResult.superName,
superArguments: evaluationResult.superArguments);
- if (_externalErrorListener.errorReported) {
+ if (error != null) {
+ // TODO(kallentu): Report a better error here with context from the other
+ // error reported.
_errorReporter.reportErrorForNode(
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, _errorNode);
+ return InvalidConstant(
+ _errorNode, CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION);
}
+
return DartObjectImpl(
typeSystem,
definingType,
@@ -2532,13 +2616,16 @@
}
}
- void _checkFields() {
- var fields = _constructor.enclosingElement2.fields;
- for (var field in fields) {
+ /// Checks for any errors in the fields of [_constructor].
+ ///
+ /// Returns an [InvalidConstant] if one is found, or `null` otherwise.
+ InvalidConstant? _checkFields() {
+ final fields = _constructor.enclosingElement2.fields;
+ for (final field in fields) {
if ((field.isFinal || field.isConst) &&
!field.isStatic &&
field is ConstFieldElementImpl) {
- var fieldValue = field.evaluationResult?.value;
+ final fieldValue = field.evaluationResult?.value;
// It is possible that the evaluation result is null.
// This happens for example when we have duplicate fields.
@@ -2547,16 +2634,21 @@
continue;
}
// Match the value and the type.
- var fieldType = FieldMember.from(field, definingType).type;
+ final fieldType = FieldMember.from(field, definingType).type;
if (!typeSystem.runtimeTypeMatch(fieldValue, fieldType)) {
+ // TODO(kallentu): Don't report error here.
_errorReporter.reportErrorForNode(
CompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH,
_errorNode,
[fieldValue.type, field.name, fieldType]);
+ return InvalidConstant(_errorNode,
+ CompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH,
+ arguments: [fieldValue.type, field.name, fieldType]);
}
_fieldMap[field.name] = fieldValue;
}
}
+ return null;
}
/// Check that the arguments to a call to `fromEnvironment()` are correct.
@@ -2599,45 +2691,77 @@
return true;
}
+ /// Checks for any errors in the constant initializers of [_constructor].
+ ///
+ /// Returns an [_InitializersEvaluationResult] which contain a result from a
+ /// redirecting constructor invocation, an [InvalidConstant], or an
+ /// incomplete state for further evaluation.
_InitializersEvaluationResult _checkInitializers() {
final definingType = this.definingType;
if (definingType is! InterfaceType) {
- return _InitializersEvaluationResult(null, evaluationIsComplete: true);
+ return _InitializersEvaluationResult(
+ InvalidConstant(
+ _errorNode, CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION),
+ evaluationIsComplete: true);
}
- var constructorBase = _constructor.declaration as ConstructorElementImpl;
+ final constructorBase = _constructor.declaration as ConstructorElementImpl;
// If we encounter a superinitializer, store the name of the constructor,
// and the arguments.
String? superName;
List<Expression>? superArguments;
- for (var initializer in constructorBase.constantInitializers) {
+ for (final initializer in constructorBase.constantInitializers) {
if (initializer is ConstructorFieldInitializer) {
- var initializerExpression = initializer.expression;
- var evaluationResult =
- initializerExpression.accept(_initializerVisitor);
- if (evaluationResult is DartObjectImpl) {
- var fieldName = initializer.fieldName.name;
- if (_fieldMap.containsKey(fieldName)) {
+ final initializerExpression = initializer.expression;
+ final evaluationResult =
+ _initializerVisitor._getConstant(initializerExpression);
+ switch (evaluationResult) {
+ case DartObjectImpl():
+ final fieldName = initializer.fieldName.name;
+ if (_fieldMap.containsKey(fieldName)) {
+ // TODO(kallentu): Don't report error here.
+ _errorReporter.reportErrorForNode(
+ CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, _errorNode);
+ return _InitializersEvaluationResult(
+ InvalidConstant(_errorNode,
+ CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION),
+ evaluationIsComplete: true);
+ }
+ _fieldMap[fieldName] = evaluationResult;
+ final getter = definingType.getGetter(fieldName);
+ if (getter != null) {
+ final field = getter.variable;
+ if (!typeSystem.runtimeTypeMatch(evaluationResult, field.type)) {
+ // TODO(kallentu): Don't report error here.
+ _errorReporter.reportErrorForNode(
+ CompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH,
+ _errorNode,
+ [evaluationResult.type, fieldName, field.type]);
+ return _InitializersEvaluationResult(
+ InvalidConstant(
+ _errorNode,
+ CompileTimeErrorCode
+ .CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH,
+ arguments: [
+ evaluationResult.type,
+ fieldName,
+ field.type
+ ]),
+ evaluationIsComplete: true);
+ }
+ }
+ case InvalidConstant():
+ // TODO(kallentu): Report the specific error we got with context of
+ // the current constructor instead of this broad error code.
_errorReporter.reportErrorForNode(
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, _errorNode);
- }
- _fieldMap[fieldName] = evaluationResult;
- var getter = definingType.getGetter(fieldName);
- if (getter != null) {
- var field = getter.variable;
- if (!typeSystem.runtimeTypeMatch(evaluationResult, field.type)) {
- _errorReporter.reportErrorForNode(
- CompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH,
- _errorNode,
- [evaluationResult.type, fieldName, field.type]);
- }
- }
- } else {
- _errorReporter.reportErrorForNode(
- CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, _errorNode);
+ return _InitializersEvaluationResult(
+ InvalidConstant(_errorNode,
+ CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION),
+ evaluationIsComplete: true);
}
} else if (initializer is SuperConstructorInvocation) {
- var name = initializer.constructorName;
+ final name = initializer.constructorName;
if (name != null) {
superName = name.name;
}
@@ -2659,26 +2783,38 @@
_initializerVisitor,
_externalErrorReporter,
invocation: _invocation);
- if (_externalErrorListener.errorReported) {
+ if (result is InvalidConstant) {
+ // TODO(kallentu): Report a better error here with context from the
+ // other error reported.
_errorReporter.reportErrorForNode(
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, _errorNode);
+ result = InvalidConstant(
+ _errorNode, CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION);
}
return _InitializersEvaluationResult(result,
evaluationIsComplete: true);
}
} else if (initializer is AssertInitializer) {
- var condition = initializer.condition;
- // TODO(kallentu): Rewrite this to handle the constant unwrapping.
- var evaluationConstant = condition.accept(_initializerVisitor);
- var evaluationResult =
- evaluationConstant is DartObjectImpl ? evaluationConstant : null;
- if (evaluationResult == null ||
- !evaluationResult.isBool ||
- evaluationResult.toBoolValue() == false) {
- _errorReporter.reportErrorForNode(
- CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, _errorNode);
- return _InitializersEvaluationResult(null,
- evaluationIsComplete: true);
+ final condition = initializer.condition;
+ final evaluationConstant = _initializerVisitor._getConstant(condition);
+ switch (evaluationConstant) {
+ case DartObjectImpl():
+ if (!evaluationConstant.isBool ||
+ evaluationConstant.toBoolValue() == false) {
+ // TODO(kallentu): Report a better error here.
+ _errorReporter.reportErrorForNode(
+ CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, _errorNode);
+ return _InitializersEvaluationResult(
+ InvalidConstant(_errorNode,
+ CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION),
+ evaluationIsComplete: true);
+ }
+ case InvalidConstant():
+ // TODO(kallentu): Don't report error here.
+ _errorReporter.reportErrorForNode(
+ CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, _errorNode);
+ return _InitializersEvaluationResult(evaluationConstant,
+ evaluationIsComplete: true);
}
}
}
@@ -2694,13 +2830,16 @@
superArguments: superArguments);
}
- void _checkParameters(List<Expression> arguments) {
- var parameters = _constructor.parameters;
- var parameterCount = parameters.length;
+ /// Checks for any errors in the parameters of [_constructor].
+ ///
+ /// Returns an [InvalidConstant] if one is found, or `null` otherwise.
+ InvalidConstant? _checkParameters(List<Expression> arguments) {
+ final parameters = _constructor.parameters;
+ final parameterCount = parameters.length;
for (var i = 0; i < parameterCount; i++) {
- var parameter = parameters[i];
- var baseParameter = parameter.declaration;
+ final parameter = parameters[i];
+ final baseParameter = parameter.declaration;
DartObjectImpl? argumentValue;
AstNode? errorTarget;
if (baseParameter.isNamed) {
@@ -2714,10 +2853,12 @@
// are handling an optional parameter that wasn't specified. So just
// direct error messages to the constructor call.
errorTarget ??= _errorNode;
- if (argumentValue == null && baseParameter is ParameterElementImpl) {
+ if (argumentValue == null &&
+ baseParameter is ParameterElementImpl &&
+ baseParameter.isOptional) {
// The parameter is an optional positional parameter for which no value
// was provided, so use the default value.
- var evaluationResult = baseParameter.evaluationResult;
+ final evaluationResult = baseParameter.evaluationResult;
if (evaluationResult == null) {
// No default was provided, so the default value is null.
argumentValue = ConstantEvaluationEngine._nullObject(_library);
@@ -2726,33 +2867,44 @@
}
}
if (argumentValue != null) {
- if (!typeSystem.runtimeTypeMatch(argumentValue, parameter.type)) {
+ if (!argumentValue.isInvalid &&
+ !typeSystem.runtimeTypeMatch(argumentValue, parameter.type)) {
_errorReporter.reportErrorForNode(
CompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH,
errorTarget,
[argumentValue.type, parameter.type],
);
+ return InvalidConstant(errorTarget,
+ CompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH,
+ arguments: [argumentValue.type, parameter.type]);
}
if (baseParameter.isInitializingFormal) {
- var field = (parameter as FieldFormalParameterElement).field;
+ final field = (parameter as FieldFormalParameterElement).field;
if (field != null) {
- var fieldType = field.type;
+ final fieldType = field.type;
if (fieldType != parameter.type) {
// We've already checked that the argument can be assigned to the
// parameter; we also need to check that it can be assigned to
// the field.
- if (!typeSystem.runtimeTypeMatch(argumentValue, fieldType)) {
+ if (!argumentValue.isInvalid &&
+ !typeSystem.runtimeTypeMatch(argumentValue, fieldType)) {
_errorReporter.reportErrorForNode(
CompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH,
errorTarget,
[argumentValue.type, fieldType],
);
+ return InvalidConstant(errorTarget,
+ CompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH,
+ arguments: [argumentValue.type, fieldType]);
}
}
- var fieldName = field.name;
+ final fieldName = field.name;
if (_fieldMap.containsKey(fieldName)) {
+ // TODO(kallentu): Don't report errors here.
_errorReporter.reportErrorForNode(
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, _errorNode);
+ return InvalidConstant(
+ _errorNode, CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION);
}
_fieldMap[fieldName] = argumentValue;
}
@@ -2760,38 +2912,41 @@
_parameterMap[baseParameter.name] = argumentValue;
}
}
+ return null;
}
- /// Checks an explicit or implicit call to `super()`.
+ /// Checks for errors in an explicit or implicit call to `super()`
+ ///
+ /// Returns an [InvalidConstant] if an error is found, or `null` otherwise.
///
/// If a superinitializer was declared on the constructor declaration,
/// [superName] and [superArguments] are the name of the super constructor
/// referenced therein, and the arguments passed to the super constructor.
/// Otherwise these parameters are `null`.
- void _checkSuperConstructorCall({
+ InvalidConstant? _checkSuperConstructorCall({
required String? superName,
required List<Expression>? superArguments,
}) {
final definingType = this.definingType;
if (definingType is! InterfaceType) {
- return;
+ return null;
}
- var superclass = definingType.superclass;
+ final superclass = definingType.superclass;
if (superclass != null && !superclass.isDartCoreObject) {
var superConstructor =
superclass.lookUpConstructor(superName, _constructor.library);
if (superConstructor == null) {
- return;
+ return null;
}
- var constructor = _constructor;
+ final constructor = _constructor;
if (constructor is ConstructorMember && constructor.isLegacy) {
superConstructor =
Member.legacy(superConstructor) as ConstructorElement;
}
if (superConstructor.isConst) {
- var evaluationResult = _evaluationEngine.evaluateConstructorCall(
+ final evaluationResult = _evaluationEngine.evaluateConstructorCall(
_library,
_errorNode,
superclass.typeArguments,
@@ -2800,11 +2955,15 @@
_initializerVisitor,
_externalErrorReporter,
);
- if (evaluationResult != null) {
- _fieldMap[GenericState.SUPERCLASS_FIELD] = evaluationResult;
+ switch (evaluationResult) {
+ case DartObjectImpl():
+ _fieldMap[GenericState.SUPERCLASS_FIELD] = evaluationResult;
+ case InvalidConstant():
+ return evaluationResult;
}
}
}
+ return null;
}
/// Checks that the arguments to a call to [Symbol.new] are correct.
@@ -2835,21 +2994,21 @@
}
void _checkTypeParameters() {
- var typeParameters = _constructor.enclosingElement2.typeParameters;
- var typeArguments = _typeArguments;
+ final typeParameters = _constructor.enclosingElement2.typeParameters;
+ final typeArguments = _typeArguments;
if (typeParameters.isNotEmpty &&
typeArguments != null &&
typeParameters.length == typeArguments.length) {
for (int i = 0; i < typeParameters.length; i++) {
- var typeParameter = typeParameters[i];
- var typeArgument = typeArguments[i];
+ final typeParameter = typeParameters[i];
+ final typeArgument = typeArguments[i];
_typeParameterMap[typeParameter] = typeArgument;
}
}
}
/// Evaluates [node] as an instance creation expression using [constructor].
- static DartObjectImpl? evaluate(
+ static Constant evaluate(
ConstantEvaluationEngine evaluationEngine,
DeclaredVariables declaredVariables,
ErrorReporter errorReporter,
@@ -2863,6 +3022,7 @@
ConstructorInvocation? invocation,
}) {
if (!constructor.isConst) {
+ // TODO(kallentu): Retain token error information in InvalidConstant.
if (node is InstanceCreationExpression && node.keyword != null) {
errorReporter.reportErrorForToken(
CompileTimeErrorCode.CONST_WITH_NON_CONST, node.keyword!);
@@ -2870,7 +3030,7 @@
errorReporter.reportErrorForNode(
CompileTimeErrorCode.CONST_WITH_NON_CONST, node);
}
- return null;
+ return InvalidConstant(node, CompileTimeErrorCode.CONST_WITH_NON_CONST);
}
if (!(constructor.declaration as ConstructorElementImpl).isCycleFree) {
@@ -2884,18 +3044,38 @@
);
}
- var argumentCount = arguments.length;
- var argumentValues = <DartObjectImpl>[];
- var namedNodes = <String, NamedExpression>{};
- var namedValues = <String, DartObjectImpl>{};
- for (var i = 0; i < argumentCount; i++) {
- var argument = arguments[i];
+ final argumentValues = <DartObjectImpl>[];
+ final namedNodes = <String, NamedExpression>{};
+ final namedValues = <String, DartObjectImpl>{};
+ for (var i = 0; i < arguments.length; i++) {
+ final argument = arguments[i];
+
+ // Use the corresponding parameter type as the default value if
+ // an unresolved expression is evaluated. We do this to continue the
+ // rest of the evaluation without producing unrelated errors.
if (argument is NamedExpression) {
- var name = argument.name.label.name;
+ final parameterType =
+ argument.element?.type ?? InvalidTypeImpl.instance;
+ final argumentConstant =
+ constantVisitor._valueOf(argument.expression, parameterType);
+ if (argumentConstant is! DartObjectImpl) {
+ return argumentConstant;
+ }
+
+ final name = argument.name.label.name;
namedNodes[name] = argument;
- namedValues[name] = constantVisitor._valueOf(argument.expression);
+ namedValues[name] = argumentConstant;
} else {
- argumentValues.add(constantVisitor._valueOf(argument));
+ final parameterType = i < constructor.parameters.length
+ ? constructor.parameters[i].type
+ : InvalidTypeImpl.instance;
+ final argumentConstant =
+ constantVisitor._valueOf(argument, parameterType);
+ if (argumentConstant is! DartObjectImpl) {
+ return argumentConstant;
+ }
+
+ argumentValues.add(argumentConstant);
}
}
@@ -2907,7 +3087,7 @@
constructor = _followConstantRedirectionChain(constructor);
- var evaluator = _InstanceCreationEvaluator._(
+ final evaluator = _InstanceCreationEvaluator._(
evaluationEngine,
declaredVariables,
errorReporter,
diff --git a/pkg/analyzer/lib/src/dart/constant/value.dart b/pkg/analyzer/lib/src/dart/constant/value.dart
index b767d76..04dc548 100644
--- a/pkg/analyzer/lib/src/dart/constant/value.dart
+++ b/pkg/analyzer/lib/src/dart/constant/value.dart
@@ -227,6 +227,10 @@
/// Return `true` if this object represents an object whose type is 'int'.
bool get isInt => state.isInt;
+ /// Return `true` if this object represents an object whose type is an invalid
+ /// type.
+ bool get isInvalid => state.isInvalid;
+
@override
bool get isNull => state is NullState;
@@ -1532,6 +1536,10 @@
/// Return `true` if this object represents an object whose type is 'int'.
bool get isInt => false;
+ /// Return `true` if this object represents an object whose type is an invalid
+ /// type.
+ bool get isInvalid => false;
+
/// Return `true` if this object represents the value 'null'.
bool get isNull => false;
@@ -2339,14 +2347,20 @@
/// The error code that is reported at the location of the [node].
final ErrorCode errorCode;
+ /// The arguments required to complete the message.
+ final List<Object>? arguments;
+
/// Additional context messages for the error, including stack trace
/// information if the error occurs within a constructor.
final List<DiagnosticMessage> contextMessages;
- InvalidConstant(this.node, this.errorCode) : contextMessages = [];
+ /// Return `true` if the constant evaluation encounters an unresolved
+ /// expression.
+ final bool isUnresolved;
- InvalidConstant.withContextMessages(
- this.node, this.errorCode, this.contextMessages);
+ InvalidConstant(this.node, this.errorCode,
+ {this.arguments, this.isUnresolved = false})
+ : contextMessages = [];
}
/// The state of an object representing a list.
@@ -2511,6 +2525,13 @@
static NullState NULL_STATE = NullState();
@override
+ final bool isInvalid;
+
+ NullState({
+ this.isInvalid = false,
+ });
+
+ @override
int get hashCode => 0;
@override
diff --git a/pkg/analyzer/test/generated/non_error_resolver_test.dart b/pkg/analyzer/test/generated/non_error_resolver_test.dart
index d1eb8b4..841bc48 100644
--- a/pkg/analyzer/test/generated/non_error_resolver_test.dart
+++ b/pkg/analyzer/test/generated/non_error_resolver_test.dart
@@ -2830,8 +2830,8 @@
const B.named7({this.bounded: bounded3}) : unbounded = null;
const B.named8({this.bounded: bounded4}) : unbounded = null;
- final Unbounded unbounded;
- final Bounded bounded;
+ final Unbounded? unbounded;
+ final Bounded? bounded;
}
''');
await assertNoErrorsInCode(r'''
diff --git a/pkg/analyzer/test/src/dart/constant/evaluation_test.dart b/pkg/analyzer/test/src/dart/constant/evaluation_test.dart
index 0669218..27848b4 100644
--- a/pkg/analyzer/test/src/dart/constant/evaluation_test.dart
+++ b/pkg/analyzer/test/src/dart/constant/evaluation_test.dart
@@ -703,16 +703,12 @@
const A(int _);
}
''', [
- error(CompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, 63, 14),
error(CompileTimeErrorCode.INVALID_CONSTANT, 76, 1),
error(CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE, 76,
1),
]);
final result = _topLevelVar('x');
- assertDartObjectText(result, r'''
-A
- variable: self::@variable::x
-''');
+ _assertNull(result);
}
test_visitConditionalExpression_unknownCondition_undefinedIdentifier() async {
@@ -2823,7 +2819,7 @@
}
test_visitPropertyAccess_fromExtension() async {
- await resolveTestCode('''
+ await assertErrorsInCode('''
extension ExtObject on Object {
int get length => 4;
}
@@ -2834,10 +2830,8 @@
}
const b = B('');
-''');
- _evaluateConstant('b', errorCodes: [
- CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
- CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION
+''', [
+ error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 128, 5),
]);
}
@@ -3343,10 +3337,7 @@
error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 77, 14),
]);
final result = _topLevelVar('a');
- assertDartObjectText(result, '''
-A<int>
- variable: self::@variable::a
-''');
+ _assertNull(result);
}
test_fieldInitializer_visitAsExpression_potentialConstType() async {
diff --git a/pkg/analyzer/test/src/dart/parser/extension_type_test.dart b/pkg/analyzer/test/src/dart/parser/extension_type_test.dart
index 3515c7d..44be2d3 100644
--- a/pkg/analyzer/test/src/dart/parser/extension_type_test.dart
+++ b/pkg/analyzer/test/src/dart/parser/extension_type_test.dart
@@ -65,6 +65,34 @@
''');
}
+ test_field_metadata() {
+ final parseResult = parseStringWithErrors(r'''
+extension type A(@foo int it) {}
+''');
+ parseResult.assertNoErrors();
+
+ final node = parseResult.findNode.singleExtensionTypeDeclaration;
+ assertParsedNodeText(node, r'''
+ExtensionTypeDeclaration
+ extensionKeyword: extension
+ typeKeyword: type
+ name: A
+ representation: RepresentationDeclaration
+ leftParenthesis: (
+ fieldMetadata
+ Annotation
+ atSign: @
+ name: SimpleIdentifier
+ token: foo
+ fieldType: NamedType
+ name: int
+ fieldName: it
+ rightParenthesis: )
+ leftBracket: {
+ rightBracket: }
+''');
+ }
+
test_members_constructor() {
final parseResult = parseStringWithErrors(r'''
extension type A(int it) {
@@ -294,6 +322,35 @@
''');
}
+ test_metadata() {
+ final parseResult = parseStringWithErrors(r'''
+@foo
+extension type A(int it) {}
+''');
+ parseResult.assertNoErrors();
+
+ final node = parseResult.findNode.singleExtensionTypeDeclaration;
+ assertParsedNodeText(node, r'''
+ExtensionTypeDeclaration
+ metadata
+ Annotation
+ atSign: @
+ name: SimpleIdentifier
+ token: foo
+ extensionKeyword: extension
+ typeKeyword: type
+ name: A
+ representation: RepresentationDeclaration
+ leftParenthesis: (
+ fieldType: NamedType
+ name: int
+ fieldName: it
+ rightParenthesis: )
+ leftBracket: {
+ rightBracket: }
+''');
+ }
+
test_named() {
final parseResult = parseStringWithErrors(r'''
extension type A.named(int it) {}
diff --git a/pkg/analyzer/test/src/diagnostics/const_constructor_param_type_mismatch_test.dart b/pkg/analyzer/test/src/diagnostics/const_constructor_param_type_mismatch_test.dart
index 6a50c49..b1e0150 100644
--- a/pkg/analyzer/test/src/diagnostics/const_constructor_param_type_mismatch_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/const_constructor_param_type_mismatch_test.dart
@@ -356,38 +356,6 @@
const b = const B();
''');
}
-
- test_unknown_conditionalExpression_unknownCondition() async {
- await assertNoErrorsInCode(r'''
-const bool kIsWeb = identical(0, 0.0);
-
-void f() {
- const A(kIsWeb ? 0 : 1);
-}
-
-class A {
- const A(int _);
-}
-''');
- }
-
- test_unknown_conditionalExpression_unknownCondition_errorInBranch() async {
- await assertErrorsInCode(r'''
-const bool kIsWeb = identical(0, 0.0);
-
-void f() {
- var x = 2;
- const A(kIsWeb ? 0 : x);
-}
-
-class A {
- const A(int _);
-}
-''', [
- error(CompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, 74, 14),
- error(CompileTimeErrorCode.INVALID_CONSTANT, 87, 1),
- ]);
- }
}
@reflectiveTest
diff --git a/pkg/analyzer/test/src/diagnostics/invalid_constant_test.dart b/pkg/analyzer/test/src/diagnostics/invalid_constant_test.dart
index a6df4c8..2d48165 100644
--- a/pkg/analyzer/test/src/diagnostics/invalid_constant_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/invalid_constant_test.dart
@@ -17,6 +17,37 @@
@reflectiveTest
class InvalidConstantTest extends PubPackageResolutionTest
with InvalidConstantTestCases {
+ test_conditionalExpression_unknownCondition() async {
+ await assertNoErrorsInCode('''
+const bool kIsWeb = identical(0, 0.0);
+
+void f() {
+ const A(kIsWeb ? 0 : 1);
+}
+
+class A {
+ const A(int _);
+}
+''');
+ }
+
+ test_conditionalExpression_unknownCondition_errorInBranch() async {
+ await assertErrorsInCode('''
+const bool kIsWeb = identical(0, 0.0);
+
+void f() {
+ var x = 2;
+ const A(kIsWeb ? 0 : x);
+}
+
+class A {
+ const A(int _);
+}
+''', [
+ error(CompileTimeErrorCode.INVALID_CONSTANT, 87, 1),
+ ]);
+ }
+
test_in_initializer_field_as() async {
await assertNoErrorsInCode('''
class C<T> {
diff --git a/pkg/analyzer/test/src/diagnostics/missing_required_param_test.dart b/pkg/analyzer/test/src/diagnostics/missing_required_param_test.dart
index 6b3eb54..cd42847 100644
--- a/pkg/analyzer/test/src/diagnostics/missing_required_param_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/missing_required_param_test.dart
@@ -184,7 +184,6 @@
}
''', [
error(CompileTimeErrorCode.MISSING_REQUIRED_ARGUMENT, 11, 1),
- error(CompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, 11, 3),
]);
}
@@ -196,7 +195,6 @@
}
''', [
error(CompileTimeErrorCode.MISSING_REQUIRED_ARGUMENT, 11, 1),
- error(CompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, 11, 1),
]);
}
diff --git a/pkg/analyzer/test/src/diagnostics/not_enough_positional_arguments_test.dart b/pkg/analyzer/test/src/diagnostics/not_enough_positional_arguments_test.dart
index eaec2c8..96fcd17 100644
--- a/pkg/analyzer/test/src/diagnostics/not_enough_positional_arguments_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/not_enough_positional_arguments_test.dart
@@ -55,7 +55,6 @@
void f() {
}
''', [
- error(CompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, 40, 3),
error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_NAME_SINGULAR,
42, 1,
messageContains: ["expected by 'A.new'"]),
@@ -69,7 +68,6 @@
const E(int a);
}
''', [
- error(CompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, 11, 3),
error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_NAME_SINGULAR,
13, 1,
messageContains: ["expected by 'E'"]),
@@ -83,7 +81,6 @@
const E(int a);
}
''', [
- error(CompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, 11, 1),
error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_NAME_SINGULAR,
11, 1,
messageContains: ["expected by 'E'"]),
@@ -131,7 +128,6 @@
const A();
}
''', [
- error(CompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, 41, 9),
error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_NAME_SINGULAR,
49, 1,
messageContains: ["expected by 'A.new'"]),
@@ -147,7 +143,6 @@
const A(p: 0);
}
''', [
- error(CompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, 41, 13),
error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_NAME_SINGULAR,
49, 1),
error(CompileTimeErrorCode.UNDEFINED_NAMED_PARAMETER, 49, 1),
diff --git a/tests/language/compile_time_constant/p_test.dart b/tests/language/compile_time_constant/p_test.dart
index 23426eb..e4c84a8 100644
--- a/tests/language/compile_time_constant/p_test.dart
+++ b/tests/language/compile_time_constant/p_test.dart
@@ -22,8 +22,6 @@
}
var b = const B();
-// ^^^^^^^^^
-// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
main() {
Expect.equals(null, b.x);
diff --git a/tests/language/compile_time_constant/static2_test.dart b/tests/language/compile_time_constant/static2_test.dart
index 70ae5c5..5222a1a 100644
--- a/tests/language/compile_time_constant/static2_test.dart
+++ b/tests/language/compile_time_constant/static2_test.dart
@@ -7,9 +7,8 @@
const A.a1() : x = 'foo';
// ^^^^^
// [analyzer] COMPILE_TIME_ERROR.FIELD_INITIALIZER_NOT_ASSIGNABLE
- // [cfe] A value of type 'String' can't be assigned to a variable of type 'int'.
- // ^^^^^
// [analyzer] COMPILE_TIME_ERROR.FIELD_INITIALIZER_NOT_ASSIGNABLE
+ // [cfe] A value of type 'String' can't be assigned to a variable of type 'int'.
const A.a2(this.x);
const A.a3([this.x = 'foo']);
// ^^^^^
@@ -23,9 +22,8 @@
const A.a5(String x) : this.x = x;
// ^
// [analyzer] COMPILE_TIME_ERROR.FIELD_INITIALIZER_NOT_ASSIGNABLE
- // [cfe] A value of type 'String' can't be assigned to a variable of type 'int'.
- // ^
// [analyzer] COMPILE_TIME_ERROR.FIELD_INITIALIZER_NOT_ASSIGNABLE
+ // [cfe] A value of type 'String' can't be assigned to a variable of type 'int'.
const A.a6(int x) : this.x = x;
}
@@ -34,10 +32,9 @@
// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH
const a2 = const A.a2('foo');
// ^^^^^
+// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH
// [cfe] The argument type 'String' can't be assigned to the parameter type 'int'.
-// ^^^^^
-// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
const a3 = const A.a3();
// ^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH
@@ -48,13 +45,10 @@
// ^^^^^^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH
const a6 = const A.a6('foo');
-// ^^^^^^^^^^^^^^^^^
-// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH
-// ^^^^^
-// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH
-// [cfe] The argument type 'String' can't be assigned to the parameter type 'int'.
// ^^^^^
// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
+// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH
+// [cfe] The argument type 'String' can't be assigned to the parameter type 'int'.
main() {
print(a1);
diff --git a/tests/language/compile_time_constant/static3_test.dart b/tests/language/compile_time_constant/static3_test.dart
index eb101ac..6179815 100644
--- a/tests/language/compile_time_constant/static3_test.dart
+++ b/tests/language/compile_time_constant/static3_test.dart
@@ -7,9 +7,8 @@
const A.a1() : x = 'foo';
// ^^^^^
// [analyzer] COMPILE_TIME_ERROR.FIELD_INITIALIZER_NOT_ASSIGNABLE
- // [cfe] A value of type 'String' can't be assigned to a variable of type 'int'.
- // ^^^^^
// [analyzer] COMPILE_TIME_ERROR.FIELD_INITIALIZER_NOT_ASSIGNABLE
+ // [cfe] A value of type 'String' can't be assigned to a variable of type 'int'.
const A.a2(this.x);
const A.a3([this.x = 'foo']);
// ^^^^^
@@ -23,9 +22,8 @@
const A.a5(String x) : this.x = x;
// ^
// [analyzer] COMPILE_TIME_ERROR.FIELD_INITIALIZER_NOT_ASSIGNABLE
- // [cfe] A value of type 'String' can't be assigned to a variable of type 'int'.
- // ^
// [analyzer] COMPILE_TIME_ERROR.FIELD_INITIALIZER_NOT_ASSIGNABLE
+ // [cfe] A value of type 'String' can't be assigned to a variable of type 'int'.
const A.a6(int x) : this.x = x;
}
@@ -34,10 +32,9 @@
// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH
var a2 = const A.a2('foo');
// ^^^^^
+// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH
// [cfe] The argument type 'String' can't be assigned to the parameter type 'int'.
-// ^^^^^
-// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
var a3 = const A.a3();
// ^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH
@@ -48,13 +45,10 @@
// ^^^^^^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH
var a6 = const A.a6('foo');
-// ^^^^^^^^^^^^^^^^^
-// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH
-// ^^^^^
-// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH
-// [cfe] The argument type 'String' can't be assigned to the parameter type 'int'.
// ^^^^^
// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
+// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH
+// [cfe] The argument type 'String' can't be assigned to the parameter type 'int'.
main() {
print(a1);
diff --git a/tests/language/constructor/bodyless_wrong_arg_test.dart b/tests/language/constructor/bodyless_wrong_arg_test.dart
index b3560d2..7c00b3b 100644
--- a/tests/language/constructor/bodyless_wrong_arg_test.dart
+++ b/tests/language/constructor/bodyless_wrong_arg_test.dart
@@ -11,14 +11,12 @@
const C(String s)
// Call super constructor with wrong argument count.
: super();
+ // ^
+ // [cfe] Too few positional arguments: 1 required, 0 given.
// ^
// [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS
- // ^^
- // [cfe] Too few positional arguments: 1 required, 0 given.
}
main() {
const C("str");
-//^^^^^^^^^^^^^^
-// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
}
diff --git a/tests/language/final/initializer_instance_reference_test.dart b/tests/language/final/initializer_instance_reference_test.dart
index be6ea47..e0bf3f2 100644
--- a/tests/language/final/initializer_instance_reference_test.dart
+++ b/tests/language/final/initializer_instance_reference_test.dart
@@ -7,8 +7,6 @@
class C {
const C();
-//^^^^^
-// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_WITH_FIELD_INITIALIZED_BY_NON_CONST
final x = 1;
final y = x;
diff --git a/tests/language/named_arguments_anywhere/order_side_effects_error_test.dart b/tests/language/named_arguments_anywhere/order_side_effects_error_test.dart
index e8a4745..cfc7ca8 100644
--- a/tests/language/named_arguments_anywhere/order_side_effects_error_test.dart
+++ b/tests/language/named_arguments_anywhere/order_side_effects_error_test.dart
@@ -27,19 +27,13 @@
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
// ^
// [cfe] Constant evaluation error:
- // ^^^^^^^^^^^^^^^^^^
- // [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
// ^^^^^^^^^
- // [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH
// [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONSTANT_ARGUMENT
// [cfe] New expression is not a constant expression.
// ^
// [cfe] New expression is not a constant expression.
foo(y: const B(new A(42)), const B(const A(0)));
- // ^^^^^^^^^^^^^^^^^^
- // [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
// ^^^^^^^^^
- // [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH
// [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONSTANT_ARGUMENT
// [cfe] New expression is not a constant expression.
// ^
diff --git a/tests/language/string/interpolation1_test.dart b/tests/language/string/interpolation1_test.dart
index d5eaea9..9cf9206 100644
--- a/tests/language/string/interpolation1_test.dart
+++ b/tests/language/string/interpolation1_test.dart
@@ -12,15 +12,11 @@
class StringInterpolation1NegativeTest {
// Dollar not followed by "{" or identifier.
static const DOLLAR = const A("$");
- // [error line 14, column 33, length 3]
- // [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH
- // [error line 14, column 35, length 0]
- // [analyzer] COMPILE_TIME_ERROR.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE
- // [cfe] A '$' has special meaning inside a string, and must be followed by an identifier or an expression in curly braces ({}).
- // [error line 14, column 35, length 0]
- // [analyzer] COMPILE_TIME_ERROR.INVALID_CONSTANT
// ^
// [analyzer] SYNTACTIC_ERROR.MISSING_IDENTIFIER
+ // [analyzer] COMPILE_TIME_ERROR.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE
+ // [analyzer] COMPILE_TIME_ERROR.INVALID_CONSTANT
+ // [cfe] A '$' has special meaning inside a string, and must be followed by an identifier or an expression in curly braces ({}).
static testMain() {
print(DOLLAR);
}
diff --git a/tests/language_2/compile_time_constant/p_test.dart b/tests/language_2/compile_time_constant/p_test.dart
index da05ab5..ccf7f83 100644
--- a/tests/language_2/compile_time_constant/p_test.dart
+++ b/tests/language_2/compile_time_constant/p_test.dart
@@ -12,7 +12,6 @@
// ^
// [analyzer] COMPILE_TIME_ERROR.FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCTOR
// [cfe] 'x' is a final instance variable that was initialized at the declaration.
- // ^
// [cfe] Cannot invoke a non-'const' constructor where a const expression is expected.
);
final x = null;
@@ -26,8 +25,6 @@
}
var b = const B();
-// ^^^^^^^^^
-// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
main() {
Expect.equals(null, b.x);
diff --git a/tests/language_2/compile_time_constant/static2_test.dart b/tests/language_2/compile_time_constant/static2_test.dart
index 8b4885a..7fdf6199 100644
--- a/tests/language_2/compile_time_constant/static2_test.dart
+++ b/tests/language_2/compile_time_constant/static2_test.dart
@@ -9,9 +9,8 @@
const A.a1() : x = 'foo';
// ^^^^^
// [analyzer] COMPILE_TIME_ERROR.FIELD_INITIALIZER_NOT_ASSIGNABLE
- // [cfe] A value of type 'String' can't be assigned to a variable of type 'int'.
- // ^^^^^
// [analyzer] COMPILE_TIME_ERROR.FIELD_INITIALIZER_NOT_ASSIGNABLE
+ // [cfe] A value of type 'String' can't be assigned to a variable of type 'int'.
const A.a2(this.x);
const A.a3([this.x = 'foo']);
// ^^^^^
@@ -25,9 +24,8 @@
const A.a5(String x) : this.x = x;
// ^
// [analyzer] COMPILE_TIME_ERROR.FIELD_INITIALIZER_NOT_ASSIGNABLE
- // [cfe] A value of type 'String' can't be assigned to a variable of type 'int'.
- // ^
// [analyzer] COMPILE_TIME_ERROR.FIELD_INITIALIZER_NOT_ASSIGNABLE
+ // [cfe] A value of type 'String' can't be assigned to a variable of type 'int'.
const A.a6(int x) : this.x = x;
}
@@ -36,10 +34,9 @@
// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH
const a2 = const A.a2('foo');
// ^^^^^
+// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH
// [cfe] The argument type 'String' can't be assigned to the parameter type 'int'.
-// ^^^^^
-// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
const a3 = const A.a3();
// ^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH
@@ -50,13 +47,10 @@
// ^^^^^^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH
const a6 = const A.a6('foo');
-// ^^^^^^^^^^^^^^^^^
-// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH
-// ^^^^^
-// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH
-// [cfe] The argument type 'String' can't be assigned to the parameter type 'int'.
// ^^^^^
// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
+// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH
+// [cfe] The argument type 'String' can't be assigned to the parameter type 'int'.
main() {
print(a1);
diff --git a/tests/language_2/compile_time_constant/static3_test.dart b/tests/language_2/compile_time_constant/static3_test.dart
index 1030a1e..a8a4599 100644
--- a/tests/language_2/compile_time_constant/static3_test.dart
+++ b/tests/language_2/compile_time_constant/static3_test.dart
@@ -9,9 +9,8 @@
const A.a1() : x = 'foo';
// ^^^^^
// [analyzer] COMPILE_TIME_ERROR.FIELD_INITIALIZER_NOT_ASSIGNABLE
- // [cfe] A value of type 'String' can't be assigned to a variable of type 'int'.
- // ^^^^^
// [analyzer] COMPILE_TIME_ERROR.FIELD_INITIALIZER_NOT_ASSIGNABLE
+ // [cfe] A value of type 'String' can't be assigned to a variable of type 'int'.
const A.a2(this.x);
const A.a3([this.x = 'foo']);
// ^^^^^
@@ -25,9 +24,8 @@
const A.a5(String x) : this.x = x;
// ^
// [analyzer] COMPILE_TIME_ERROR.FIELD_INITIALIZER_NOT_ASSIGNABLE
- // [cfe] A value of type 'String' can't be assigned to a variable of type 'int'.
- // ^
// [analyzer] COMPILE_TIME_ERROR.FIELD_INITIALIZER_NOT_ASSIGNABLE
+ // [cfe] A value of type 'String' can't be assigned to a variable of type 'int'.
const A.a6(int x) : this.x = x;
}
@@ -36,10 +34,9 @@
// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH
var a2 = const A.a2('foo');
// ^^^^^
+// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH
// [cfe] The argument type 'String' can't be assigned to the parameter type 'int'.
-// ^^^^^
-// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
var a3 = const A.a3();
// ^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH
@@ -50,13 +47,10 @@
// ^^^^^^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH
var a6 = const A.a6('foo');
-// ^^^^^^^^^^^^^^^^^
-// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH
-// ^^^^^
-// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH
-// [cfe] The argument type 'String' can't be assigned to the parameter type 'int'.
// ^^^^^
// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
+// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH
+// [cfe] The argument type 'String' can't be assigned to the parameter type 'int'.
main() {
print(a1);
diff --git a/tests/language_2/final/initializer_instance_reference_test.dart b/tests/language_2/final/initializer_instance_reference_test.dart
index be02d1e..8edb007 100644
--- a/tests/language_2/final/initializer_instance_reference_test.dart
+++ b/tests/language_2/final/initializer_instance_reference_test.dart
@@ -9,8 +9,6 @@
class C {
const C();
-//^^^^^
-// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_WITH_FIELD_INITIALIZED_BY_NON_CONST
final x = 1;
final y = x;
diff --git a/tools/VERSION b/tools/VERSION
index cdbf79e..ae556f8 100644
--- a/tools/VERSION
+++ b/tools/VERSION
@@ -27,5 +27,5 @@
MAJOR 3
MINOR 2
PATCH 0
-PRERELEASE 0
+PRERELEASE 1
PRERELEASE_PATCH 0