mirror of
https://github.com/dart-lang/sdk
synced 2024-09-15 23:09:48 +00:00
[analyzer] Move all constructor error reporting to _InstanceCreationEvaluator.evaluate
Pull the error handling outwards to _InstanceCreationEvaluator.evaluate. All errors in const constructors should point to the location of the actual exception and provide more context. Change-Id: Iafcf46182fab698f5546c63780de6dd9a605a51b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/318802 Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Commit-Queue: Kallen Tu <kallentu@google.com>
This commit is contained in:
parent
155bfc973b
commit
1f88336597
|
@ -429,13 +429,13 @@ class AddConst_PreferConstConstructorsBulkTest extends BulkFixProcessorTest {
|
|||
writeTestPackageConfig(meta: true);
|
||||
await resolveTestCode(r'''
|
||||
class C {
|
||||
const C([C c]);
|
||||
const C([C? c]);
|
||||
}
|
||||
var c = C(C());
|
||||
''');
|
||||
await assertHasFix(r'''
|
||||
class C {
|
||||
const C([C c]);
|
||||
const C([C? c]);
|
||||
}
|
||||
var c = const C(C());
|
||||
''');
|
||||
|
|
|
@ -2354,8 +2354,6 @@ class _InstanceCreationEvaluator {
|
|||
|
||||
final LibraryElementImpl _library;
|
||||
|
||||
final ErrorReporter _errorReporter;
|
||||
|
||||
final BooleanErrorListener _externalErrorListener = BooleanErrorListener();
|
||||
|
||||
/// An error reporter for errors determined while computing values for field
|
||||
|
@ -2408,7 +2406,6 @@ class _InstanceCreationEvaluator {
|
|||
_InstanceCreationEvaluator._(
|
||||
this._evaluationEngine,
|
||||
this._declaredVariables,
|
||||
this._errorReporter,
|
||||
this._library,
|
||||
this._errorNode,
|
||||
this._constructor,
|
||||
|
@ -2439,9 +2436,6 @@ class _InstanceCreationEvaluator {
|
|||
var argumentCount = arguments.length;
|
||||
if (_constructor.name == "fromEnvironment") {
|
||||
if (!_checkFromEnvironmentArguments(arguments, definingType)) {
|
||||
// TODO(kallentu): Don't report error here.
|
||||
_errorReporter.reportErrorForNode(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, _errorNode);
|
||||
return InvalidConstant(
|
||||
_errorNode, CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION);
|
||||
}
|
||||
|
@ -2474,9 +2468,6 @@ class _InstanceCreationEvaluator {
|
|||
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 InvalidConstant(
|
||||
_errorNode, CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION);
|
||||
}
|
||||
|
@ -2522,24 +2513,6 @@ class _InstanceCreationEvaluator {
|
|||
superName: evaluationResult.superName,
|
||||
superArguments: evaluationResult.superArguments);
|
||||
if (error != null) {
|
||||
final formattedMessage =
|
||||
formatList(error.errorCode.problemMessage, error.arguments);
|
||||
final contextMessage = DiagnosticMessageImpl(
|
||||
filePath: _library.source.fullName,
|
||||
length: error.node.length,
|
||||
message: "The exception is '$formattedMessage' and occurs here.",
|
||||
offset: error.node.offset,
|
||||
url: null,
|
||||
);
|
||||
|
||||
// TODO(kallentu): When removing all on-site reporting, move this error
|
||||
// to [_InstanceCreationEvaluator.evaluate] and provide context for all
|
||||
// constructor related errors.
|
||||
_errorReporter.reportErrorForNode(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
_errorNode,
|
||||
[],
|
||||
[...error.contextMessages, contextMessage]);
|
||||
return error;
|
||||
}
|
||||
|
||||
|
@ -2598,11 +2571,6 @@ class _InstanceCreationEvaluator {
|
|||
// Match the value and the type.
|
||||
var fieldType = FieldMember.from(field, _constructor.returnType).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]);
|
||||
|
@ -2673,11 +2641,8 @@ class _InstanceCreationEvaluator {
|
|||
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,
|
||||
InvalidConstant(initializerExpression,
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION),
|
||||
evaluationIsComplete: true);
|
||||
}
|
||||
|
@ -2686,14 +2651,9 @@ class _InstanceCreationEvaluator {
|
|||
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,
|
||||
initializerExpression,
|
||||
CompileTimeErrorCode
|
||||
.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH,
|
||||
arguments: [
|
||||
|
@ -2705,13 +2665,7 @@ class _InstanceCreationEvaluator {
|
|||
}
|
||||
}
|
||||
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);
|
||||
return _InitializersEvaluationResult(
|
||||
InvalidConstant(_errorNode,
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION),
|
||||
return _InitializersEvaluationResult(evaluationResult,
|
||||
evaluationIsComplete: true);
|
||||
}
|
||||
} else if (initializer is SuperConstructorInvocation) {
|
||||
|
@ -2737,14 +2691,6 @@ class _InstanceCreationEvaluator {
|
|||
_initializerVisitor,
|
||||
_externalErrorReporter,
|
||||
invocation: _invocation);
|
||||
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);
|
||||
}
|
||||
|
@ -2755,18 +2701,12 @@ class _InstanceCreationEvaluator {
|
|||
case DartObjectImpl():
|
||||
if (!evaluationConstant.isBool ||
|
||||
evaluationConstant.toBoolValue() == false) {
|
||||
// TODO(kallentu): Don't report error here.
|
||||
_errorReporter.reportErrorForNode(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, _errorNode);
|
||||
return _InitializersEvaluationResult(
|
||||
InvalidConstant(initializer,
|
||||
CompileTimeErrorCode.CONST_EVAL_ASSERTION_FAILURE),
|
||||
evaluationIsComplete: true);
|
||||
}
|
||||
case InvalidConstant():
|
||||
// TODO(kallentu): Don't report error here.
|
||||
_errorReporter.reportErrorForNode(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, _errorNode);
|
||||
return _InitializersEvaluationResult(evaluationConstant,
|
||||
evaluationIsComplete: true);
|
||||
}
|
||||
|
@ -2823,11 +2763,6 @@ class _InstanceCreationEvaluator {
|
|||
if (argumentValue != null) {
|
||||
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]);
|
||||
|
@ -2842,11 +2777,6 @@ class _InstanceCreationEvaluator {
|
|||
// the field.
|
||||
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]);
|
||||
|
@ -2854,9 +2784,6 @@ class _InstanceCreationEvaluator {
|
|||
}
|
||||
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);
|
||||
}
|
||||
|
@ -3045,13 +2972,12 @@ class _InstanceCreationEvaluator {
|
|||
);
|
||||
|
||||
constructor = _followConstantRedirectionChain(constructor);
|
||||
|
||||
final errorNode = evaluationEngine.configuration.errorNode(node);
|
||||
final evaluator = _InstanceCreationEvaluator._(
|
||||
evaluationEngine,
|
||||
declaredVariables,
|
||||
errorReporter,
|
||||
library,
|
||||
evaluationEngine.configuration.errorNode(node),
|
||||
errorNode,
|
||||
constructor,
|
||||
typeArguments,
|
||||
namedNodes: namedNodes,
|
||||
|
@ -3060,15 +2986,34 @@ class _InstanceCreationEvaluator {
|
|||
invocation: invocation,
|
||||
);
|
||||
|
||||
Constant constant;
|
||||
if (constructor.isFactory) {
|
||||
// We couldn't find a non-factory constructor.
|
||||
// See if it's because we reached an external const factory constructor
|
||||
// that we can emulate.
|
||||
return evaluator.evaluateFactoryConstructorCall(arguments,
|
||||
constant = evaluator.evaluateFactoryConstructorCall(arguments,
|
||||
isNullSafe: isNullSafe);
|
||||
} else {
|
||||
return evaluator.evaluateGenerativeConstructorCall(arguments);
|
||||
constant = evaluator.evaluateGenerativeConstructorCall(arguments);
|
||||
}
|
||||
if (constant is InvalidConstant) {
|
||||
final formattedMessage =
|
||||
formatList(constant.errorCode.problemMessage, constant.arguments);
|
||||
final contextMessage = DiagnosticMessageImpl(
|
||||
filePath: library.source.fullName,
|
||||
length: constant.node.length,
|
||||
message: "The exception is '$formattedMessage' and occurs here.",
|
||||
offset: constant.node.offset,
|
||||
url: null,
|
||||
);
|
||||
errorReporter.reportErrorForNode(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
errorNode,
|
||||
[],
|
||||
[...constant.contextMessages, contextMessage],
|
||||
);
|
||||
}
|
||||
return constant;
|
||||
}
|
||||
|
||||
/// Attempt to follow the chain of factory redirections until a constructor is
|
||||
|
|
|
@ -2847,7 +2847,12 @@ class B {
|
|||
|
||||
const b = B('');
|
||||
''', [
|
||||
error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 128, 5),
|
||||
error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 128, 5,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 105, 8,
|
||||
text:
|
||||
"The exception is 'Invalid constant value.' and occurs here."),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -3156,7 +3161,16 @@ class A {
|
|||
const a = const A(null);
|
||||
''', [
|
||||
error(WarningCode.UNNECESSARY_TYPE_CHECK_FALSE, 31, 9),
|
||||
error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 56, 13),
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
56,
|
||||
13,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 24, 17,
|
||||
text:
|
||||
"The exception is 'The assertion in this constant expression failed.' and occurs here."),
|
||||
],
|
||||
),
|
||||
error(CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS, 64, 4),
|
||||
]);
|
||||
}
|
||||
|
@ -3169,7 +3183,16 @@ class A<T> {
|
|||
|
||||
const a = const A<int?>();
|
||||
''', [
|
||||
error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 60, 15),
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
60,
|
||||
15,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 27, 18,
|
||||
text:
|
||||
"The exception is 'The assertion in this constant expression failed.' and occurs here."),
|
||||
],
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -3198,7 +3221,16 @@ class A {
|
|||
}
|
||||
const c = const A(E.a);
|
||||
''', [
|
||||
error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 73, 12),
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
73,
|
||||
12,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 43, 16,
|
||||
text:
|
||||
"The exception is 'The assertion in this constant expression failed.' and occurs here."),
|
||||
],
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -3377,7 +3409,16 @@ class A<T> {
|
|||
const a = const A<int>();
|
||||
''', [
|
||||
error(CompileTimeErrorCode.INVALID_CONSTANT, 62, 1),
|
||||
error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 77, 14),
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
77,
|
||||
14,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 62, 1,
|
||||
text:
|
||||
"The exception is 'Invalid constant value.' and occurs here."),
|
||||
],
|
||||
),
|
||||
]);
|
||||
final result = _topLevelVar('a');
|
||||
_assertNull(result);
|
||||
|
@ -3510,7 +3551,16 @@ class A {
|
|||
}
|
||||
const a = const A(1);
|
||||
''', [
|
||||
error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 71, 10),
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
71,
|
||||
10,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 31, 26,
|
||||
text:
|
||||
"The exception is 'The assertion in this constant expression failed.' and occurs here."),
|
||||
],
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -3521,7 +3571,16 @@ class A {
|
|||
}
|
||||
const a = const A();
|
||||
''', [
|
||||
error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 56, 9),
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
56,
|
||||
9,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 23, 19,
|
||||
text:
|
||||
"The exception is 'The assertion in this constant expression failed.' and occurs here."),
|
||||
],
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -3558,7 +3617,16 @@ class A {
|
|||
}
|
||||
const a = const A(0);
|
||||
''', [
|
||||
error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 55, 10),
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
55,
|
||||
10,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 28, 13,
|
||||
text:
|
||||
"The exception is 'The assertion in this constant expression failed.' and occurs here."),
|
||||
],
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import 'package:analyzer/src/error/codes.dart';
|
|||
import 'package:test/test.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../../generated/test_support.dart';
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
|
||||
main() {
|
||||
|
@ -51,6 +52,28 @@ void f(A a, A? aq) {
|
|||
]);
|
||||
}
|
||||
|
||||
test_const() async {
|
||||
await assertErrorsInCode('''
|
||||
class A {
|
||||
const A(String p);
|
||||
}
|
||||
main() {
|
||||
const A(42);
|
||||
}''', [
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
44,
|
||||
11,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 52, 2,
|
||||
text:
|
||||
"The exception is 'A value of type 'int' can't be assigned to a parameter of type 'String' in a const constructor.' and occurs here."),
|
||||
],
|
||||
),
|
||||
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 52, 2),
|
||||
]);
|
||||
}
|
||||
|
||||
test_downcast() async {
|
||||
await assertErrorsInCode(r'''
|
||||
m() {
|
||||
|
@ -93,7 +116,16 @@ enum E {
|
|||
}
|
||||
''', [
|
||||
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 13, 1),
|
||||
error(CompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, 13, 1),
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
11,
|
||||
4,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 13, 1,
|
||||
text:
|
||||
"The exception is 'A value of type 'int' can't be assigned to a parameter of type 'String' in a const constructor.' and occurs here."),
|
||||
],
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -318,19 +350,6 @@ main() {
|
|||
]);
|
||||
}
|
||||
|
||||
test_const() async {
|
||||
await assertErrorsInCode('''
|
||||
class A {
|
||||
const A(String p);
|
||||
}
|
||||
main() {
|
||||
const A(42);
|
||||
}''', [
|
||||
error(CompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, 52, 2),
|
||||
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 52, 2),
|
||||
]);
|
||||
}
|
||||
|
||||
test_const_super() async {
|
||||
await assertErrorsInCode('''
|
||||
class A {
|
||||
|
|
|
@ -32,49 +32,6 @@ var v = const C<int>();
|
|||
);
|
||||
}
|
||||
|
||||
test_generic_string_int() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
class C<T> {
|
||||
final T x = y;
|
||||
const C();
|
||||
}
|
||||
const int y = 1;
|
||||
var v = const C<String>();
|
||||
''',
|
||||
[
|
||||
error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 27, 1),
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH, 70, 17),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
test_notGeneric_int_int() async {
|
||||
await assertErrorsInCode(r'''
|
||||
class A {
|
||||
const A(x) : y = x;
|
||||
final int y;
|
||||
}
|
||||
var v = const A('foo');
|
||||
''', [
|
||||
error(CompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH, 57, 14),
|
||||
]);
|
||||
}
|
||||
|
||||
test_notGeneric_int_null() async {
|
||||
var errors = expectedErrorsByNullability(nullable: [
|
||||
error(CompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH, 57, 13),
|
||||
], legacy: []);
|
||||
await assertErrorsInCode(r'''
|
||||
class A {
|
||||
const A(x) : y = x;
|
||||
final int y;
|
||||
}
|
||||
var v = const A(null);
|
||||
''', errors);
|
||||
}
|
||||
|
||||
test_notGeneric_null_forNonNullable_fromLegacy() async {
|
||||
noSoundNullSafety = false;
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
|
@ -90,19 +47,6 @@ const a = const C(null);
|
|||
''');
|
||||
}
|
||||
|
||||
test_notGeneric_null_forNonNullable_fromNullSafe() async {
|
||||
await assertErrorsInCode('''
|
||||
class C {
|
||||
final int f;
|
||||
const C(a) : f = a;
|
||||
}
|
||||
|
||||
const a = const C(null);
|
||||
''', [
|
||||
error(CompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH, 60, 13),
|
||||
]);
|
||||
}
|
||||
|
||||
test_notGeneric_unresolved_int() async {
|
||||
await assertErrorsInCode(r'''
|
||||
class A {
|
||||
|
|
|
@ -46,22 +46,6 @@ var v = const C(const B());
|
|||
''');
|
||||
}
|
||||
|
||||
test_assignable_fieldFormal_typedef() async {
|
||||
// foo has the type dynamic -> dynamic, so it is not assignable to A.f.
|
||||
await assertErrorsInCode(r'''
|
||||
typedef String Int2String(int x);
|
||||
class A {
|
||||
final Int2String f;
|
||||
const A(this.f);
|
||||
}
|
||||
foo(x) => 1;
|
||||
var v = const A(foo);
|
||||
''', [
|
||||
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 116, 3),
|
||||
error(CompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, 116, 3),
|
||||
]);
|
||||
}
|
||||
|
||||
test_assignable_fieldFormal_typeSubstitution() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
class A<T> {
|
||||
|
@ -104,32 +88,6 @@ var v = const A(null);
|
|||
]);
|
||||
}
|
||||
|
||||
test_enum_int_null() async {
|
||||
await assertErrorsInCode(r'''
|
||||
const dynamic a = null;
|
||||
|
||||
enum E {
|
||||
v(a);
|
||||
const E(int a);
|
||||
}
|
||||
''', [
|
||||
error(CompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, 38, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
test_enum_int_String() async {
|
||||
await assertErrorsInCode(r'''
|
||||
const dynamic a = '0';
|
||||
|
||||
enum E {
|
||||
v(a);
|
||||
const E(int a);
|
||||
}
|
||||
''', [
|
||||
error(CompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, 37, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
test_int_to_double_reference_from_other_library_other_file_after() async {
|
||||
newFile('$testPackageLibPath/other.dart', '''
|
||||
import 'test.dart';
|
||||
|
@ -215,70 +173,6 @@ const c = C();
|
|||
''');
|
||||
}
|
||||
|
||||
test_notAssignable_fieldFormal_optional() async {
|
||||
await assertErrorsInCode(r'''
|
||||
class A {
|
||||
final int x;
|
||||
const A([this.x = 'foo']);
|
||||
}
|
||||
var v = const A();
|
||||
''', [
|
||||
error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 45, 5),
|
||||
error(CompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, 64, 9),
|
||||
]);
|
||||
}
|
||||
|
||||
test_notAssignable_fieldFormal_supertype() async {
|
||||
await assertErrorsInCode(r'''
|
||||
class A {
|
||||
const A();
|
||||
}
|
||||
class B extends A {
|
||||
const B();
|
||||
}
|
||||
class C {
|
||||
final B b;
|
||||
const C(this.b);
|
||||
}
|
||||
const A u = const A();
|
||||
var v = const C(u);
|
||||
''', [
|
||||
// TODO(srawlins): It would be best to report only the first one.
|
||||
error(CompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, 143, 1),
|
||||
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 143, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
test_notAssignable_fieldFormal_typedef() async {
|
||||
// foo has type String -> int, so it is not assignable to A.f
|
||||
// (A.f requires it to be int -> String).
|
||||
await assertErrorsInCode(r'''
|
||||
typedef String Int2String(int x);
|
||||
class A {
|
||||
final Int2String f;
|
||||
const A(this.f);
|
||||
}
|
||||
int foo(String x) => 1;
|
||||
var v = const A(foo);
|
||||
''', [
|
||||
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 127, 3),
|
||||
error(CompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, 127, 3),
|
||||
]);
|
||||
}
|
||||
|
||||
test_notAssignable_fieldFormal_unrelated() async {
|
||||
await assertErrorsInCode(r'''
|
||||
class A {
|
||||
final int x;
|
||||
const A(this.x);
|
||||
}
|
||||
var v = const A('foo');
|
||||
''', [
|
||||
error(CompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, 62, 5),
|
||||
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 62, 5),
|
||||
]);
|
||||
}
|
||||
|
||||
test_notAssignable_fieldFormal_unresolved() async {
|
||||
await assertErrorsInCode(r'''
|
||||
class A {
|
||||
|
@ -291,30 +185,6 @@ var v = const A('foo');
|
|||
]);
|
||||
}
|
||||
|
||||
test_notAssignable_typeSubstitution() async {
|
||||
await assertErrorsInCode(r'''
|
||||
class A<T> {
|
||||
const A(T x);
|
||||
}
|
||||
var v = const A<int>('foo');
|
||||
''', [
|
||||
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 52, 5),
|
||||
error(CompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, 52, 5),
|
||||
]);
|
||||
}
|
||||
|
||||
test_notAssignable_unrelated() async {
|
||||
await assertErrorsInCode(r'''
|
||||
class A {
|
||||
const A(int x);
|
||||
}
|
||||
var v = const A('foo');
|
||||
''', [
|
||||
error(CompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, 46, 5),
|
||||
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 46, 5),
|
||||
]);
|
||||
}
|
||||
|
||||
test_superFormalParameter_explicit() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
class A {
|
||||
|
|
|
@ -11,11 +11,323 @@ import '../dart/resolution/context_collection_resolution.dart';
|
|||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(ConstConstructorFieldTypeMismatchContextTest);
|
||||
defineReflectiveTests(ConstConstructorParamTypeMismatchContextTest);
|
||||
defineReflectiveTests(ConstEvalThrowsExceptionTest);
|
||||
defineReflectiveTests(ConstEvalThrowsExceptionWithoutNullSafetyTest);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class ConstConstructorFieldTypeMismatchContextTest
|
||||
extends PubPackageResolutionTest {
|
||||
test_generic_string_int() async {
|
||||
await assertErrorsInCode(
|
||||
r'''
|
||||
class C<T> {
|
||||
final T x = y;
|
||||
const C();
|
||||
}
|
||||
const int y = 1;
|
||||
var v = const C<String>();
|
||||
''',
|
||||
[
|
||||
error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 27, 1),
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
70,
|
||||
17,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 70, 17,
|
||||
text:
|
||||
"The exception is 'In a const constructor, a value of type 'int' can't be assigned to the field 'x', which has type 'String'.' and occurs here."),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
test_notGeneric_int_int() async {
|
||||
await assertErrorsInCode(r'''
|
||||
class A {
|
||||
const A(x) : y = x;
|
||||
final int y;
|
||||
}
|
||||
var v = const A('foo');
|
||||
''', [
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
57,
|
||||
14,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 29, 1,
|
||||
text:
|
||||
"The exception is 'In a const constructor, a value of type 'String' can't be assigned to the field 'y', which has type 'int'.' and occurs here."),
|
||||
],
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
test_notGeneric_int_null() async {
|
||||
var errors = expectedErrorsByNullability(nullable: [
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
57,
|
||||
13,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 29, 1,
|
||||
text:
|
||||
"The exception is 'In a const constructor, a value of type 'Null' can't be assigned to the field 'y', which has type 'int'.' and occurs here."),
|
||||
],
|
||||
),
|
||||
], legacy: []);
|
||||
await assertErrorsInCode(r'''
|
||||
class A {
|
||||
const A(x) : y = x;
|
||||
final int y;
|
||||
}
|
||||
var v = const A(null);
|
||||
''', errors);
|
||||
}
|
||||
|
||||
test_notGeneric_null_forNonNullable_fromNullSafe() async {
|
||||
await assertErrorsInCode('''
|
||||
class C {
|
||||
final int f;
|
||||
const C(a) : f = a;
|
||||
}
|
||||
|
||||
const a = const C(null);
|
||||
''', [
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
60,
|
||||
13,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 44, 1,
|
||||
text:
|
||||
"The exception is 'In a const constructor, a value of type 'Null' can't be assigned to the field 'f', which has type 'int'.' and occurs here."),
|
||||
],
|
||||
),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class ConstConstructorParamTypeMismatchContextTest
|
||||
extends PubPackageResolutionTest {
|
||||
test_assignable_fieldFormal_typedef() async {
|
||||
// foo has the type dynamic -> dynamic, so it is not assignable to A.f.
|
||||
await assertErrorsInCode(r'''
|
||||
typedef String Int2String(int x);
|
||||
class A {
|
||||
final Int2String f;
|
||||
const A(this.f);
|
||||
}
|
||||
foo(x) => 1;
|
||||
var v = const A(foo);
|
||||
''', [
|
||||
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 116, 3),
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
108,
|
||||
12,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 116, 3,
|
||||
text:
|
||||
"The exception is 'A value of type 'dynamic Function(dynamic)' can't be assigned to a parameter of type 'String Function(int)' in a const constructor.' and occurs here."),
|
||||
],
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
test_enum_int_null() async {
|
||||
await assertErrorsInCode(r'''
|
||||
const dynamic a = null;
|
||||
|
||||
enum E {
|
||||
v(a);
|
||||
const E(int a);
|
||||
}
|
||||
''', [
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
36,
|
||||
4,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 38, 1,
|
||||
text:
|
||||
"The exception is 'A value of type 'Null' can't be assigned to a parameter of type 'int' in a const constructor.' and occurs here."),
|
||||
],
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
test_enum_int_String() async {
|
||||
await assertErrorsInCode(r'''
|
||||
const dynamic a = '0';
|
||||
|
||||
enum E {
|
||||
v(a);
|
||||
const E(int a);
|
||||
}
|
||||
''', [
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
35,
|
||||
4,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 37, 1,
|
||||
text:
|
||||
"The exception is 'A value of type 'String' can't be assigned to a parameter of type 'int' in a const constructor.' and occurs here."),
|
||||
],
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
test_notAssignable_fieldFormal_optional() async {
|
||||
await assertErrorsInCode(r'''
|
||||
class A {
|
||||
final int x;
|
||||
const A([this.x = 'foo']);
|
||||
}
|
||||
var v = const A();
|
||||
''', [
|
||||
error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 45, 5),
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
64,
|
||||
9,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 64, 9,
|
||||
text:
|
||||
"The exception is 'A value of type 'String' can't be assigned to a parameter of type 'int' in a const constructor.' and occurs here."),
|
||||
],
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
test_notAssignable_fieldFormal_supertype() async {
|
||||
await assertErrorsInCode(r'''
|
||||
class A {
|
||||
const A();
|
||||
}
|
||||
class B extends A {
|
||||
const B();
|
||||
}
|
||||
class C {
|
||||
final B b;
|
||||
const C(this.b);
|
||||
}
|
||||
const A u = const A();
|
||||
var v = const C(u);
|
||||
''', [
|
||||
// TODO(srawlins): It would be best to report only the first one.
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
135,
|
||||
10,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 143, 1,
|
||||
text:
|
||||
"The exception is 'A value of type 'A' can't be assigned to a parameter of type 'B' in a const constructor.' and occurs here."),
|
||||
],
|
||||
),
|
||||
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 143, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
test_notAssignable_fieldFormal_typedef() async {
|
||||
// foo has type String -> int, so it is not assignable to A.f
|
||||
// (A.f requires it to be int -> String).
|
||||
await assertErrorsInCode(r'''
|
||||
typedef String Int2String(int x);
|
||||
class A {
|
||||
final Int2String f;
|
||||
const A(this.f);
|
||||
}
|
||||
int foo(String x) => 1;
|
||||
var v = const A(foo);
|
||||
''', [
|
||||
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 127, 3),
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
119,
|
||||
12,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 127, 3,
|
||||
text:
|
||||
"The exception is 'A value of type 'int Function(String)' can't be assigned to a parameter of type 'String Function(int)' in a const constructor.' and occurs here."),
|
||||
],
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
test_notAssignable_fieldFormal_unrelated() async {
|
||||
await assertErrorsInCode(r'''
|
||||
class A {
|
||||
final int x;
|
||||
const A(this.x);
|
||||
}
|
||||
var v = const A('foo');
|
||||
''', [
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
54,
|
||||
14,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 62, 5,
|
||||
text:
|
||||
"The exception is 'A value of type 'String' can't be assigned to a parameter of type 'int' in a const constructor.' and occurs here."),
|
||||
],
|
||||
),
|
||||
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 62, 5),
|
||||
]);
|
||||
}
|
||||
|
||||
test_notAssignable_typeSubstitution() async {
|
||||
await assertErrorsInCode(r'''
|
||||
class A<T> {
|
||||
const A(T x);
|
||||
}
|
||||
var v = const A<int>('foo');
|
||||
''', [
|
||||
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 52, 5),
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
39,
|
||||
19,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 52, 5,
|
||||
text:
|
||||
"The exception is 'A value of type 'String' can't be assigned to a parameter of type 'int' in a const constructor.' and occurs here."),
|
||||
],
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
test_notAssignable_unrelated() async {
|
||||
await assertErrorsInCode(r'''
|
||||
class A {
|
||||
const A(int x);
|
||||
}
|
||||
var v = const A('foo');
|
||||
''', [
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
38,
|
||||
14,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 46, 5,
|
||||
text:
|
||||
"The exception is 'A value of type 'String' can't be assigned to a parameter of type 'int' in a const constructor.' and occurs here."),
|
||||
],
|
||||
),
|
||||
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 46, 5),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class ConstEvalThrowsExceptionTest extends PubPackageResolutionTest
|
||||
with ConstEvalThrowsExceptionTestCases {
|
||||
|
@ -32,8 +344,26 @@ main() {
|
|||
const C<int>(null);
|
||||
}
|
||||
''', [
|
||||
error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 92, 19),
|
||||
error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 115, 18),
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
92,
|
||||
19,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 51, 6,
|
||||
text:
|
||||
"The exception is 'Evaluation of this constant expression throws an exception.' and occurs here."),
|
||||
],
|
||||
),
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
115,
|
||||
18,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 51, 6,
|
||||
text:
|
||||
"The exception is 'Evaluation of this constant expression throws an exception.' and occurs here."),
|
||||
],
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -50,8 +380,26 @@ main() {
|
|||
const C<int>(null);
|
||||
}
|
||||
''', [
|
||||
error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 104, 21),
|
||||
error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 129, 18),
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
104,
|
||||
21,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 51, 12,
|
||||
text:
|
||||
"The exception is 'Evaluation of this constant expression throws an exception.' and occurs here."),
|
||||
],
|
||||
),
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
129,
|
||||
18,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 51, 12,
|
||||
text:
|
||||
"The exception is 'Evaluation of this constant expression throws an exception.' and occurs here."),
|
||||
],
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -63,7 +411,61 @@ enum E {
|
|||
const E({int? x}) : x = x as int;
|
||||
}
|
||||
''', [
|
||||
error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 11, 3),
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
11,
|
||||
3,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 57, 8,
|
||||
text:
|
||||
"The exception is 'Evaluation of this constant expression throws an exception.' and occurs here."),
|
||||
],
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
test_invalid_constructorFieldInitializer_fromSeparateLibrary() async {
|
||||
newFile('$testPackageLibPath/lib.dart', r'''
|
||||
class A<T> {
|
||||
final int f;
|
||||
const A() : f = T.foo;
|
||||
}
|
||||
''');
|
||||
await assertErrorsInCode(r'''
|
||||
import 'lib.dart';
|
||||
const a = const A();
|
||||
''', [
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
29,
|
||||
9,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 46, 5,
|
||||
text:
|
||||
"The exception is 'Invalid constant value.' and occurs here."),
|
||||
],
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
test_redirectingConstructor_paramTypeMismatch() async {
|
||||
await assertErrorsInCode(r'''
|
||||
class A {
|
||||
const A.a1(x) : this.a2(x);
|
||||
const A.a2(String x);
|
||||
}
|
||||
var v = const A.a1(0);
|
||||
''', [
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
74,
|
||||
13,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 36, 1,
|
||||
text:
|
||||
"The exception is 'A value of type 'int' can't be assigned to a parameter of type 'String' in a const constructor.' and occurs here."),
|
||||
],
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -104,7 +506,16 @@ class A {
|
|||
}
|
||||
var v = const A(3, 2);
|
||||
''', [
|
||||
error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 61, 13),
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
61,
|
||||
13,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 36, 13,
|
||||
text:
|
||||
"The exception is 'The assertion in this constant expression failed.' and occurs here."),
|
||||
],
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -243,7 +654,16 @@ var x = const C();
|
|||
CompileTimeErrorCode.FIELD_INITIALIZED_IN_INITIALIZER_AND_DECLARATION,
|
||||
39,
|
||||
1),
|
||||
error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 56, 9),
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
56,
|
||||
9,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 43, 1,
|
||||
text:
|
||||
"The exception is 'Evaluation of this constant expression throws an exception.' and occurs here."),
|
||||
],
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -264,7 +684,16 @@ var x = const C(2);
|
|||
CompileTimeErrorCode.FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCTOR,
|
||||
40,
|
||||
1),
|
||||
error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 54, 10),
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
54,
|
||||
10,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 54, 10,
|
||||
text:
|
||||
"The exception is 'Evaluation of this constant expression throws an exception.' and occurs here."),
|
||||
],
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -286,9 +715,27 @@ main() {
|
|||
var b1 = const bool.fromEnvironment(1);
|
||||
var b2 = const bool.fromEnvironment('x', defaultValue: 1);
|
||||
''', [
|
||||
error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 9, 29),
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
9,
|
||||
29,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 9, 29,
|
||||
text:
|
||||
"The exception is 'Evaluation of this constant expression throws an exception.' and occurs here."),
|
||||
],
|
||||
),
|
||||
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 36, 1),
|
||||
error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 49, 48),
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
49,
|
||||
48,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 49, 48,
|
||||
text:
|
||||
"The exception is 'Evaluation of this constant expression throws an exception.' and occurs here."),
|
||||
],
|
||||
),
|
||||
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 95, 1),
|
||||
]);
|
||||
}
|
||||
|
@ -300,7 +747,16 @@ var b2 = const bool.fromEnvironment('x', defaultValue: 1);
|
|||
await assertErrorsInCode('''
|
||||
var b = const bool.fromEnvironment('x', defaultValue: 1);
|
||||
''', [
|
||||
error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 8, 48),
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
8,
|
||||
48,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 8, 48,
|
||||
text:
|
||||
"The exception is 'Evaluation of this constant expression throws an exception.' and occurs here."),
|
||||
],
|
||||
),
|
||||
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 54, 1),
|
||||
]);
|
||||
}
|
||||
|
@ -319,45 +775,36 @@ const c = [if (0 < 1) 3 else nil + 1];
|
|||
''');
|
||||
}
|
||||
|
||||
test_invalid_constructorFieldInitializer_fromSeparateLibrary() async {
|
||||
newFile('$testPackageLibPath/lib.dart', r'''
|
||||
class A<T> {
|
||||
final int f;
|
||||
const A() : f = T.foo;
|
||||
}
|
||||
''');
|
||||
await assertErrorsInCode(r'''
|
||||
import 'lib.dart';
|
||||
const a = const A();
|
||||
''', [
|
||||
error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 29, 9),
|
||||
]);
|
||||
}
|
||||
|
||||
test_redirectingConstructor_paramTypeMismatch() async {
|
||||
await assertErrorsInCode(r'''
|
||||
class A {
|
||||
const A.a1(x) : this.a2(x);
|
||||
const A.a2(String x);
|
||||
}
|
||||
var v = const A.a1(0);
|
||||
''', [
|
||||
error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 74, 13),
|
||||
]);
|
||||
}
|
||||
|
||||
test_symbolConstructor_nonStringArgument() async {
|
||||
await assertErrorsInCode(r'''
|
||||
var s2 = const Symbol(3);
|
||||
''', [
|
||||
error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 9, 15),
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
9,
|
||||
15,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 9, 15,
|
||||
text:
|
||||
"The exception is 'Evaluation of this constant expression throws an exception.' and occurs here."),
|
||||
],
|
||||
),
|
||||
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 22, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
test_symbolConstructor_string_digit() async {
|
||||
var expectedErrors = expectedErrorsByNullability(nullable: [], legacy: [
|
||||
error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 8, 17),
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
8,
|
||||
17,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 8, 17,
|
||||
text:
|
||||
"The exception is 'Evaluation of this constant expression throws an exception.' and occurs here."),
|
||||
],
|
||||
),
|
||||
]);
|
||||
await assertErrorsInCode(r'''
|
||||
var s = const Symbol('3');
|
||||
|
@ -366,7 +813,16 @@ var s = const Symbol('3');
|
|||
|
||||
test_symbolConstructor_string_underscore() async {
|
||||
var expectedErrors = expectedErrorsByNullability(nullable: [], legacy: [
|
||||
error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 8, 17),
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
8,
|
||||
17,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 8, 17,
|
||||
text:
|
||||
"The exception is 'Evaluation of this constant expression throws an exception.' and occurs here."),
|
||||
],
|
||||
),
|
||||
]);
|
||||
await assertErrorsInCode(r'''
|
||||
var s = const Symbol('_');
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../../generated/test_support.dart';
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
|
||||
main() {
|
||||
|
@ -84,7 +85,16 @@ enum E {
|
|||
const E() : x = 0, x = 1;
|
||||
}
|
||||
''', [
|
||||
error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 11, 1),
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
11,
|
||||
1,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 54, 1,
|
||||
text:
|
||||
"The exception is 'Evaluation of this constant expression throws an exception.' and occurs here."),
|
||||
],
|
||||
),
|
||||
error(CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS, 50,
|
||||
1),
|
||||
]);
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../../generated/test_support.dart';
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
|
||||
main() {
|
||||
|
@ -38,7 +39,16 @@ enum E {
|
|||
const E() : x = 1;
|
||||
}
|
||||
''', [
|
||||
error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 11, 1),
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
11,
|
||||
1,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 51, 1,
|
||||
text:
|
||||
"The exception is 'Evaluation of this constant expression throws an exception.' and occurs here."),
|
||||
],
|
||||
),
|
||||
error(
|
||||
CompileTimeErrorCode.FIELD_INITIALIZED_IN_INITIALIZER_AND_DECLARATION,
|
||||
47,
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../../generated/test_support.dart';
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
|
||||
main() {
|
||||
|
@ -36,7 +37,16 @@ enum E {
|
|||
const E(this.x) : x = 1;
|
||||
}
|
||||
''', [
|
||||
error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 11, 4),
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
11,
|
||||
4,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 56, 1,
|
||||
text:
|
||||
"The exception is 'Evaluation of this constant expression throws an exception.' and occurs here."),
|
||||
],
|
||||
),
|
||||
error(CompileTimeErrorCode.FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER,
|
||||
52, 1),
|
||||
]);
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../../generated/test_support.dart';
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
|
||||
main() {
|
||||
|
@ -61,7 +62,16 @@ enum E {
|
|||
const E() : x = '';
|
||||
}
|
||||
''', [
|
||||
error(CompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH, 11, 1),
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
11,
|
||||
1,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 47, 2,
|
||||
text:
|
||||
"The exception is 'In a const constructor, a value of type 'String' can't be assigned to the field 'x', which has type 'int'.' and occurs here."),
|
||||
],
|
||||
),
|
||||
error(CompileTimeErrorCode.FIELD_INITIALIZER_NOT_ASSIGNABLE, 47, 2),
|
||||
error(CompileTimeErrorCode.CONST_FIELD_INITIALIZER_NOT_ASSIGNABLE, 47, 2),
|
||||
]);
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../../generated/test_support.dart';
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
|
||||
main() {
|
||||
|
@ -61,7 +62,16 @@ enum E {
|
|||
const E(String this.x);
|
||||
}
|
||||
''', [
|
||||
error(CompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, 13, 2),
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
11,
|
||||
5,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 13, 2,
|
||||
text:
|
||||
"The exception is 'A value of type 'String' can't be assigned to a parameter of type 'int' in a const constructor.' and occurs here."),
|
||||
],
|
||||
),
|
||||
error(CompileTimeErrorCode.FIELD_INITIALIZING_FORMAL_NOT_ASSIGNABLE, 43,
|
||||
13),
|
||||
]);
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../../generated/test_support.dart';
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
|
||||
main() {
|
||||
|
@ -38,7 +39,16 @@ enum E {
|
|||
const E(this.x);
|
||||
}
|
||||
''', [
|
||||
error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 11, 4),
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
11,
|
||||
4,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 11, 4,
|
||||
text:
|
||||
"The exception is 'Evaluation of this constant expression throws an exception.' and occurs here."),
|
||||
],
|
||||
),
|
||||
error(
|
||||
CompileTimeErrorCode.FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCTOR,
|
||||
47,
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../../generated/test_support.dart';
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
|
||||
main() {
|
||||
|
@ -190,7 +191,16 @@ class B {
|
|||
var b = const B();
|
||||
''', [
|
||||
error(CompileTimeErrorCode.INVALID_CONSTANT, 47, 7),
|
||||
error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 77, 9),
|
||||
error(
|
||||
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
|
||||
77,
|
||||
9,
|
||||
contextMessages: [
|
||||
ExpectedContextMessage(testFile.path, 47, 7,
|
||||
text:
|
||||
"The exception is 'Invalid constant value.' and occurs here."),
|
||||
],
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -29,25 +29,27 @@ class A {
|
|||
|
||||
const a1 = const A.a1();
|
||||
// ^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
|
||||
const a2 = const A.a2('foo');
|
||||
// ^^^^^^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
|
||||
// ^^^^^
|
||||
// [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'.
|
||||
const a3 = const A.a3();
|
||||
// ^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
|
||||
const a4 = const A.a4('foo');
|
||||
// ^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH
|
||||
// ^^^^^^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
|
||||
const a5 = const A.a5('foo');
|
||||
// ^^^^^^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
|
||||
const a6 = const A.a6('foo');
|
||||
// ^^^^^^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
|
||||
// ^^^^^
|
||||
// [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() {
|
||||
|
|
|
@ -29,25 +29,27 @@ class A {
|
|||
|
||||
var a1 = const A.a1();
|
||||
// ^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
|
||||
var a2 = const A.a2('foo');
|
||||
// ^^^^^^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
|
||||
// ^^^^^
|
||||
// [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'.
|
||||
var a3 = const A.a3();
|
||||
// ^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
|
||||
var a4 = const A.a4('foo');
|
||||
// ^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH
|
||||
// ^^^^^^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
|
||||
var a5 = const A.a5('foo');
|
||||
// ^^^^^^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
|
||||
var a6 = const A.a6('foo');
|
||||
// ^^^^^^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
|
||||
// ^^^^^
|
||||
// [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() {
|
||||
|
|
|
@ -14,11 +14,11 @@ class D extends C {
|
|||
const intValue = 0;
|
||||
const c = const C(0.0);
|
||||
const d = const C(intValue);
|
||||
// ^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH
|
||||
// [cfe] The argument type 'int' can't be assigned to the parameter type 'double'.
|
||||
// ^^^^^^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
|
||||
// ^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
|
||||
// [cfe] The argument type 'int' can't be assigned to the parameter type 'double'.
|
||||
const e = const D(0.0);
|
||||
const f = const D(intValue);
|
||||
// ^^^^^^^^^^^^^^^^^
|
||||
|
|
|
@ -16,9 +16,10 @@ class A {
|
|||
int foo(String x) => 499;
|
||||
|
||||
const a = const A(foo);
|
||||
// ^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
|
||||
// ^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH
|
||||
// [cfe] The argument type 'int Function(String)' can't be assigned to the parameter type 'String Function(int)'.
|
||||
|
||||
main() {
|
||||
|
|
|
@ -31,25 +31,27 @@ class A {
|
|||
|
||||
const a1 = const A.a1();
|
||||
// ^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
|
||||
const a2 = const A.a2('foo');
|
||||
// ^^^^^^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
|
||||
// ^^^^^
|
||||
// [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'.
|
||||
const a3 = const A.a3();
|
||||
// ^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
|
||||
const a4 = const A.a4('foo');
|
||||
// ^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH
|
||||
// ^^^^^^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
|
||||
const a5 = const A.a5('foo');
|
||||
// ^^^^^^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
|
||||
const a6 = const A.a6('foo');
|
||||
// ^^^^^^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
|
||||
// ^^^^^
|
||||
// [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() {
|
||||
|
|
|
@ -31,25 +31,27 @@ class A {
|
|||
|
||||
var a1 = const A.a1();
|
||||
// ^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
|
||||
var a2 = const A.a2('foo');
|
||||
// ^^^^^^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
|
||||
// ^^^^^
|
||||
// [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'.
|
||||
var a3 = const A.a3();
|
||||
// ^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
|
||||
var a4 = const A.a4('foo');
|
||||
// ^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH
|
||||
// ^^^^^^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
|
||||
var a5 = const A.a5('foo');
|
||||
// ^^^^^^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
|
||||
var a6 = const A.a6('foo');
|
||||
// ^^^^^^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
|
||||
// ^^^^^
|
||||
// [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() {
|
||||
|
|
|
@ -16,11 +16,11 @@ class D extends C {
|
|||
const intValue = 0;
|
||||
const c = const C(0.0);
|
||||
const d = const C(intValue);
|
||||
// ^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH
|
||||
// [cfe] The argument type 'int' can't be assigned to the parameter type 'double'.
|
||||
// ^^^^^^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
|
||||
// ^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
|
||||
// [cfe] The argument type 'int' can't be assigned to the parameter type 'double'.
|
||||
const e = const D(0.0);
|
||||
const f = const D(intValue);
|
||||
// ^^^^^^^^^^^^^^^^^
|
||||
|
|
|
@ -18,9 +18,10 @@ class A {
|
|||
int foo(String x) => 499;
|
||||
|
||||
const a = const A(foo);
|
||||
// ^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
|
||||
// ^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH
|
||||
// [cfe] The argument type 'int Function(String)' can't be assigned to the parameter type 'String Function(int)'.
|
||||
|
||||
main() {
|
||||
|
|
Loading…
Reference in a new issue