| Index: tests/compiler/dart2js/constant_expression_evaluate_test.dart
|
| diff --git a/tests/compiler/dart2js/constant_expression_evaluate_test.dart b/tests/compiler/dart2js/constant_expression_evaluate_test.dart
|
| index 5fa34cc12c5088073032d3de26dc3378cf322798..fe65bf5ac3f721fb848007f16a6bb89defc0c770 100644
|
| --- a/tests/compiler/dart2js/constant_expression_evaluate_test.dart
|
| +++ b/tests/compiler/dart2js/constant_expression_evaluate_test.dart
|
| @@ -11,8 +11,12 @@ import 'package:compiler/src/constants/evaluation.dart';
|
| import 'package:compiler/src/constants/expressions.dart';
|
| import 'package:compiler/src/constants/values.dart';
|
| import 'package:compiler/src/constant_system_dart.dart';
|
| +import 'package:compiler/src/core_types.dart';
|
| import 'package:compiler/src/compiler.dart';
|
| +import 'package:compiler/src/diagnostics/messages.dart';
|
| +import 'package:compiler/src/diagnostics/spannable.dart';
|
| import 'package:compiler/src/elements/elements.dart';
|
| +import 'package:compiler/src/elements/modelx.dart';
|
| import 'memory_compiler.dart';
|
|
|
| class TestData {
|
| @@ -24,71 +28,135 @@ class TestData {
|
| const TestData(this.declarations, this.constants);
|
| }
|
|
|
| +class ConstantResult {
|
| + final String value;
|
| + final errors;
|
| +
|
| + const ConstantResult(this.value, [this.errors]);
|
| +}
|
| +
|
| class ConstantData {
|
| /// Source code for the constant expression.
|
| final String code;
|
| - /// Map from environment to expected constant value as structured text.
|
| - final Map<Map<String, String>, String> expectedValues;
|
| +
|
| + /// Constant value as structured text for the empty environment or a map from
|
| + /// environment to either the expected constant value as structured text or
|
| + /// a [ConstantResult].
|
| + final expectedResults;
|
| +
|
| + /// A [MessageKind] or a list of [MessageKind]s containing the error messages
|
| + /// expected as the result of evaluating the constant under the empty
|
| + /// environment.
|
| + final expectedErrors;
|
|
|
| const ConstantData(this.code,
|
| - this.expectedValues);
|
| + this.expectedResults,
|
| + [this.expectedErrors]);
|
| +}
|
| +
|
| +class EvaluationError {
|
| + final MessageKind kind;
|
| + final Map arguments;
|
| +
|
| + EvaluationError(this.kind, this.arguments);
|
| }
|
|
|
| class MemoryEnvironment implements Environment {
|
| final Compiler compiler;
|
| + final Spannable spannable;
|
| final Map<String, String> env;
|
| + final List<EvaluationError> errors = <EvaluationError>[];
|
|
|
| MemoryEnvironment(this.compiler,
|
| + this.spannable,
|
| [this.env = const <String, String>{}]);
|
|
|
| @override
|
| String readFromEnvironment(String name) => env[name];
|
| +
|
| + @override
|
| + CoreTypes get coreTypes => compiler.coreTypes;
|
| +
|
| + @override
|
| + void reportError(ConstantExpression expression,
|
| + MessageKind kind,
|
| + Map arguments) {
|
| + errors.add(new EvaluationError(kind, arguments));
|
| + compiler.reportError(spannable, kind, arguments);
|
| + }
|
| +
|
| + @override
|
| + ConstantValue evaluateConstructor(
|
| + ConstructorElement constructor,
|
| + ConstantValue evaluate()) {
|
| + return evaluate();
|
| + }
|
| +
|
| + @override
|
| + ConstantValue evaluateVariable(
|
| + VariableElement variable,
|
| + ConstantValue evaluate()) {
|
| + return evaluate();
|
| + }
|
| }
|
|
|
| const List<TestData> DATA = const [
|
| const TestData('', const [
|
| - const ConstantData('null', const { const {} : 'NullConstant' }),
|
| - const ConstantData('false', const { const {} : 'BoolConstant(false)' }),
|
| - const ConstantData('true', const { const {} : 'BoolConstant(true)' }),
|
| - const ConstantData('0', const { const {} : 'IntConstant(0)' }),
|
| - const ConstantData('0.0', const { const {} : 'DoubleConstant(0.0)' }),
|
| - const ConstantData('"foo"', const { const {} : 'StringConstant("foo")' }),
|
| - const ConstantData('1 + 2', const { const {} : 'IntConstant(3)' }),
|
| - const ConstantData('-(1)', const { const {} : 'IntConstant(-1)' }),
|
| - const ConstantData('"foo".length', const { const {} : 'IntConstant(3)' }),
|
| - const ConstantData('identical(0, 1)',
|
| - const { const {} : 'BoolConstant(false)' }),
|
| - const ConstantData('"a" "b"', const { const {} : 'StringConstant("ab")' }),
|
| - const ConstantData('identical',
|
| - const { const {} : 'FunctionConstant(identical)' }),
|
| - const ConstantData('true ? 0 : 1', const { const {} : 'IntConstant(0)' }),
|
| - const ConstantData('proxy',
|
| - const { const {} : 'ConstructedConstant(_Proxy())' }),
|
| - const ConstantData('Object', const { const {} : 'TypeConstant(Object)' }),
|
| + const ConstantData('null', 'NullConstant'),
|
| + const ConstantData('false', 'BoolConstant(false)'),
|
| + const ConstantData('true', 'BoolConstant(true)'),
|
| + const ConstantData('0', 'IntConstant(0)'),
|
| + const ConstantData('0.0', 'DoubleConstant(0.0)'),
|
| + const ConstantData('"foo"', 'StringConstant("foo")'),
|
| + const ConstantData('1 + 2', 'IntConstant(3)'),
|
| + const ConstantData('-(1)', 'IntConstant(-1)'),
|
| + const ConstantData('"foo".length', 'IntConstant(3)'),
|
| + const ConstantData('identical(0, 1)', 'BoolConstant(false)'),
|
| + const ConstantData('"a" "b"', 'StringConstant("ab")'),
|
| + const ConstantData('identical', 'FunctionConstant(identical)'),
|
| + const ConstantData('true ? 0 : 1', 'IntConstant(0)'),
|
| + const ConstantData('true || false', 'BoolConstant(true)'),
|
| + const ConstantData('true && false', 'BoolConstant(false)'),
|
| + const ConstantData('proxy', 'ConstructedConstant(_Proxy())'),
|
| + //const ConstantData('Object', const { const {} : 'TypeConstant(Object)' }),
|
| const ConstantData('const [0, 1]',
|
| - const { const {} : 'ListConstant([IntConstant(0), IntConstant(1)])' }),
|
| - const ConstantData('const <int>[0, 1]', const {
|
| - const {} : 'ListConstant(<int>[IntConstant(0), IntConstant(1)])' }),
|
| + 'ListConstant([IntConstant(0), IntConstant(1)])'),
|
| + const ConstantData('const <int>[0, 1]',
|
| + 'ListConstant(<int>[IntConstant(0), IntConstant(1)])'),
|
| const ConstantData('const {0: 1, 2: 3}',
|
| - const { const {} :
|
| - 'MapConstant({IntConstant(0): IntConstant(1), '
|
| - 'IntConstant(2): IntConstant(3)})' }),
|
| + 'MapConstant({IntConstant(0): IntConstant(1), '
|
| + 'IntConstant(2): IntConstant(3)})'),
|
| const ConstantData('const <int, int>{0: 1, 2: 3}',
|
| - const { const {} :
|
| - 'MapConstant(<int, int>{IntConstant(0): IntConstant(1), '
|
| - 'IntConstant(2): IntConstant(3)})' }),
|
| + 'MapConstant(<int, int>{IntConstant(0): IntConstant(1), '
|
| + 'IntConstant(2): IntConstant(3)})'),
|
| + const ConstantData(
|
| + 'const bool.fromEnvironment("foo")',
|
| + const { const {} : 'BoolConstant(false)',
|
| + const {'foo': 'true'} : 'BoolConstant(true)'}),
|
| const ConstantData(
|
| 'const bool.fromEnvironment("foo", defaultValue: false)',
|
| const { const {} : 'BoolConstant(false)',
|
| const {'foo': 'true'} : 'BoolConstant(true)'}),
|
| const ConstantData(
|
| + 'const bool.fromEnvironment("foo", defaultValue: null)',
|
| + const { const {} : 'NullConstant',
|
| + const {'foo': 'false'} : 'BoolConstant(false)'}),
|
| + const ConstantData(
|
| 'const int.fromEnvironment("foo", defaultValue: 42)',
|
| const { const {} : 'IntConstant(42)',
|
| const {'foo': '87'} : 'IntConstant(87)'}),
|
| const ConstantData(
|
| + 'const int.fromEnvironment("foo", defaultValue: null)',
|
| + const { const {} : 'NullConstant',
|
| + const {'foo': '87'} : 'IntConstant(87)'}),
|
| + const ConstantData(
|
| 'const String.fromEnvironment("foo", defaultValue: "bar")',
|
| const { const {} : 'StringConstant("bar")',
|
| const {'foo': 'foo'} : 'StringConstant("foo")'}),
|
| + const ConstantData(
|
| + 'const String.fromEnvironment("foo", defaultValue: null)',
|
| + const { const {} : 'NullConstant',
|
| + const {'foo': 'foo'} : 'StringConstant("foo")'}),
|
| ]),
|
| const TestData('''
|
| const a = const bool.fromEnvironment("foo", defaultValue: true);
|
| @@ -108,36 +176,35 @@ class C extends B {
|
| }
|
| ''', const [
|
| const ConstantData('const Object()',
|
| - const { const {} : 'ConstructedConstant(Object())' }),
|
| + 'ConstructedConstant(Object())'),
|
| const ConstantData('const A()',
|
| - const { const {} : 'ConstructedConstant(A())' }),
|
| + 'ConstructedConstant(A())'),
|
| const ConstantData('const B(0)',
|
| - const { const {} : 'ConstructedConstant(B(field1=IntConstant(0)))' }),
|
| + 'ConstructedConstant(B(field1=IntConstant(0)))'),
|
| const ConstantData('const B(const A())',
|
| - const { const {} :
|
| - 'ConstructedConstant(B(field1=ConstructedConstant(A())))' }),
|
| - const ConstantData('const C()', const { const {} :
|
| - 'ConstructedConstant(C(field1=IntConstant(42),'
|
| - 'field2=BoolConstant(false)))' }),
|
| - const ConstantData('const C(field1: 87)', const { const {} :
|
| - 'ConstructedConstant(C(field1=IntConstant(87),'
|
| - 'field2=BoolConstant(false)))' }),
|
| - const ConstantData('const C(field2: true)', const { const {} :
|
| - 'ConstructedConstant(C(field1=IntConstant(42),'
|
| - 'field2=BoolConstant(true)))' }),
|
| - const ConstantData('const C.named()', const { const {} :
|
| - 'ConstructedConstant(C(field1=BoolConstant(false),'
|
| - 'field2=BoolConstant(false)))' }),
|
| - const ConstantData('const C.named(87)', const { const {} :
|
| - 'ConstructedConstant(C(field1=IntConstant(87),'
|
| - 'field2=IntConstant(87)))' }),
|
| + 'ConstructedConstant(B(field1=ConstructedConstant(A())))'),
|
| + const ConstantData('const C()',
|
| + 'ConstructedConstant(C(field2=BoolConstant(false),'
|
| + 'field1=IntConstant(42)))'),
|
| + const ConstantData('const C(field1: 87)',
|
| + 'ConstructedConstant(C(field2=BoolConstant(false),'
|
| + 'field1=IntConstant(87)))'),
|
| + const ConstantData('const C(field2: true)',
|
| + 'ConstructedConstant(C(field2=BoolConstant(true),'
|
| + 'field1=IntConstant(42)))'),
|
| + const ConstantData('const C.named()',
|
| + 'ConstructedConstant(C(field2=BoolConstant(false),'
|
| + 'field1=BoolConstant(false)))'),
|
| + const ConstantData('const C.named(87)',
|
| + 'ConstructedConstant(C(field2=IntConstant(87),'
|
| + 'field1=IntConstant(87)))'),
|
| const ConstantData('const C(field1: a, field2: b)', const {
|
| const {} :
|
| - 'ConstructedConstant(C(field1=BoolConstant(true),'
|
| - 'field2=IntConstant(42)))',
|
| + 'ConstructedConstant(C(field2=IntConstant(42),'
|
| + 'field1=BoolConstant(true)))',
|
| const {'foo': 'false', 'bar': '87'} :
|
| - 'ConstructedConstant(C(field1=BoolConstant(false),'
|
| - 'field2=IntConstant(87)))', }),
|
| + 'ConstructedConstant(C(field2=IntConstant(87),'
|
| + 'field1=BoolConstant(false)))', }),
|
| ]),
|
| const TestData('''
|
| class A<T> implements B {
|
| @@ -153,26 +220,19 @@ class C<U> {
|
| }
|
| ''', const [
|
| const ConstantData('const A()',
|
| - const { const {} :
|
| - 'ConstructedConstant(A<dynamic>(field1=IntConstant(42)))' }),
|
| + 'ConstructedConstant(A<dynamic>(field1=IntConstant(42)))'),
|
| const ConstantData('const A<int>(field1: 87)',
|
| - const { const {} :
|
| - 'ConstructedConstant(A<int>(field1=IntConstant(87)))' }),
|
| + 'ConstructedConstant(A<int>(field1=IntConstant(87)))'),
|
| const ConstantData('const B()',
|
| - const { const {} :
|
| - 'ConstructedConstant(A<B<dynamic>>(field1=IntConstant(42)))' }),
|
| + 'ConstructedConstant(A<B<dynamic>>(field1=IntConstant(42)))'),
|
| const ConstantData('const B<int>()',
|
| - const { const {} :
|
| - 'ConstructedConstant(A<B<int>>(field1=IntConstant(42)))' }),
|
| + 'ConstructedConstant(A<B<int>>(field1=IntConstant(42)))'),
|
| const ConstantData('const B<int>(field1: 87)',
|
| - const { const {} :
|
| - 'ConstructedConstant(A<B<int>>(field1=IntConstant(87)))' }),
|
| + 'ConstructedConstant(A<B<int>>(field1=IntConstant(87)))'),
|
| const ConstantData('const C<int>(field1: 87)',
|
| - const { const {} :
|
| - 'ConstructedConstant(A<B<double>>(field1=IntConstant(87)))' }),
|
| + 'ConstructedConstant(A<B<double>>(field1=IntConstant(87)))'),
|
| const ConstantData('const B<int>.named()',
|
| - const { const {} :
|
| - 'ConstructedConstant(A<int>(field1=IntConstant(42)))' }),
|
| + 'ConstructedConstant(A<int>(field1=IntConstant(42)))'),
|
| ]),
|
| const TestData('''
|
| const c = const int.fromEnvironment("foo", defaultValue: 5);
|
| @@ -198,6 +258,162 @@ class B extends A {
|
| const {'bar': '42'} :
|
| 'ConstructedConstant(B(field=IntConstant(126)))', }),
|
| ]),
|
| + const TestData('''
|
| +class A {
|
| + final x;
|
| + final y;
|
| + final z;
|
| + final t;
|
| + final u = 42;
|
| +
|
| + const A(this.z, tt) : y = 499, t = tt, x = 3;
|
| + const A.named(z, this.t) : y = 400 + z, this.z = z, x = 3;
|
| + const A.named2(t, z, y, x) : x = t, y = z, z = y, t = x;
|
| +}
|
| +''', const [
|
| + const ConstantData(
|
| + 'const A.named(99, 100)',
|
| + 'ConstructedConstant(A(x=IntConstant(3),'
|
| + 'y=IntConstant(499),'
|
| + 'z=IntConstant(99),'
|
| + 't=IntConstant(100),'
|
| + 'u=IntConstant(42)))'),
|
| + const ConstantData(
|
| + 'const A(99, 100)',
|
| + 'ConstructedConstant(A(x=IntConstant(3),'
|
| + 'y=IntConstant(499),'
|
| + 'z=IntConstant(99),'
|
| + 't=IntConstant(100),'
|
| + 'u=IntConstant(42)))'),
|
| + ]),
|
| + const TestData('''
|
| +const integer = const int.fromEnvironment("foo", defaultValue: 5);
|
| +const string = const String.fromEnvironment("bar", defaultValue: "baz");
|
| +const boolean = const bool.fromEnvironment("baz", defaultValue: false);
|
| +''', const [
|
| + const ConstantData(
|
| + r'"$integer $string $boolean"',
|
| + 'StringConstant("5 baz false")'),
|
| + const ConstantData(
|
| + '0 ? true : false', 'NonConstant',
|
| + MessageKind.INVALID_CONSTANT_CONDITIONAL_TYPE),
|
| +
|
| + const ConstantData(
|
| + 'integer ? true : false',
|
| + 'NonConstant',
|
| + MessageKind.INVALID_CONSTANT_CONDITIONAL_TYPE),
|
| +
|
| + const ConstantData(r'"${const []}"', 'NonConstant',
|
| + MessageKind.INVALID_CONSTANT_INTERPOLATION_TYPE),
|
| + const ConstantData(r'"${proxy}"', 'NonConstant',
|
| + MessageKind.INVALID_CONSTANT_INTERPOLATION_TYPE),
|
| + const ConstantData('0 + ""', 'NonConstant',
|
| + MessageKind.INVALID_CONSTANT_NUM_ADD_TYPE),
|
| + const ConstantData('0 + string', 'NonConstant',
|
| + MessageKind.INVALID_CONSTANT_NUM_ADD_TYPE),
|
| + const ConstantData('"" + 0', 'NonConstant',
|
| + MessageKind.INVALID_CONSTANT_STRING_ADD_TYPE),
|
| + const ConstantData('string + 0', 'NonConstant',
|
| + MessageKind.INVALID_CONSTANT_STRING_ADD_TYPE),
|
| + const ConstantData('true + ""', 'NonConstant',
|
| + MessageKind.INVALID_CONSTANT_STRING_ADD_TYPE),
|
| + const ConstantData('boolean + string', 'NonConstant',
|
| + MessageKind.INVALID_CONSTANT_STRING_ADD_TYPE),
|
| + const ConstantData('true + false', 'NonConstant',
|
| + MessageKind.INVALID_CONSTANT_ADD_TYPES),
|
| + const ConstantData('boolean + false', 'NonConstant',
|
| + MessageKind.INVALID_CONSTANT_ADD_TYPES),
|
| + const ConstantData('const [] == null', 'NonConstant',
|
| + MessageKind.INVALID_CONSTANT_BINARY_PRIMITIVE_TYPE),
|
| + const ConstantData('proxy == null', 'NonConstant',
|
| + MessageKind.INVALID_CONSTANT_BINARY_PRIMITIVE_TYPE),
|
| + const ConstantData('0 * ""', 'NonConstant',
|
| + MessageKind.INVALID_CONSTANT_BINARY_NUM_TYPE),
|
| + const ConstantData('0 * string', 'NonConstant',
|
| + MessageKind.INVALID_CONSTANT_BINARY_NUM_TYPE),
|
| + const ConstantData('0 % ""', 'NonConstant',
|
| + MessageKind.INVALID_CONSTANT_BINARY_NUM_TYPE),
|
| + const ConstantData('0 % string', 'NonConstant',
|
| + MessageKind.INVALID_CONSTANT_BINARY_NUM_TYPE),
|
| + const ConstantData('0 << ""', 'NonConstant',
|
| + MessageKind.INVALID_CONSTANT_BINARY_INT_TYPE),
|
| + const ConstantData('0 << string', 'NonConstant',
|
| + MessageKind.INVALID_CONSTANT_BINARY_INT_TYPE),
|
| + const ConstantData('null[0]', 'NonConstant',
|
| + MessageKind.INVALID_CONSTANT_INDEX),
|
| + const ConstantData('null ?? 0', 'NonConstant',
|
| + MessageKind.INVALID_CONSTANT_IF_NULL),
|
| + const ConstantData(
|
| + 'const bool.fromEnvironment(0)',
|
| + 'NonConstant',
|
| + MessageKind.INVALID_FROM_ENVIRONMENT_NAME_TYPE),
|
| + const ConstantData(
|
| + 'const bool.fromEnvironment(integer)',
|
| + 'NonConstant',
|
| + MessageKind.INVALID_FROM_ENVIRONMENT_NAME_TYPE),
|
| + const ConstantData(
|
| + 'const bool.fromEnvironment("baz", defaultValue: 0)',
|
| + 'NonConstant',
|
| + MessageKind.INVALID_BOOL_FROM_ENVIRONMENT_DEFAULT_VALUE_TYPE),
|
| + const ConstantData(
|
| + 'const bool.fromEnvironment("baz", defaultValue: integer)',
|
| + 'NonConstant',
|
| + MessageKind.INVALID_BOOL_FROM_ENVIRONMENT_DEFAULT_VALUE_TYPE),
|
| + const ConstantData(
|
| + 'const int.fromEnvironment(0)',
|
| + 'NonConstant',
|
| + MessageKind.INVALID_FROM_ENVIRONMENT_NAME_TYPE),
|
| + const ConstantData(
|
| + 'const int.fromEnvironment(integer)',
|
| + 'NonConstant',
|
| + MessageKind.INVALID_FROM_ENVIRONMENT_NAME_TYPE),
|
| + const ConstantData(
|
| + 'const int.fromEnvironment("baz", defaultValue: "")',
|
| + 'NonConstant',
|
| + MessageKind.INVALID_INT_FROM_ENVIRONMENT_DEFAULT_VALUE_TYPE),
|
| + const ConstantData(
|
| + 'const int.fromEnvironment("baz", defaultValue: string)',
|
| + 'NonConstant',
|
| + MessageKind.INVALID_INT_FROM_ENVIRONMENT_DEFAULT_VALUE_TYPE),
|
| + const ConstantData(
|
| + 'const String.fromEnvironment(0)',
|
| + 'NonConstant',
|
| + MessageKind.INVALID_FROM_ENVIRONMENT_NAME_TYPE),
|
| + const ConstantData(
|
| + 'const String.fromEnvironment(integer)',
|
| + 'NonConstant',
|
| + MessageKind.INVALID_FROM_ENVIRONMENT_NAME_TYPE),
|
| + const ConstantData(
|
| + 'const String.fromEnvironment("baz", defaultValue: 0)',
|
| + 'NonConstant',
|
| + MessageKind.INVALID_STRING_FROM_ENVIRONMENT_DEFAULT_VALUE_TYPE),
|
| + const ConstantData(
|
| + 'const String.fromEnvironment("baz", defaultValue: integer)',
|
| + 'NonConstant',
|
| + MessageKind.INVALID_STRING_FROM_ENVIRONMENT_DEFAULT_VALUE_TYPE),
|
| + const ConstantData('true || 0', 'NonConstant',
|
| + MessageKind.INVALID_LOGICAL_OR_OPERAND_TYPE),
|
| + const ConstantData('0 || true', 'NonConstant',
|
| + MessageKind.INVALID_LOGICAL_OR_OPERAND_TYPE),
|
| + const ConstantData('true || integer', 'NonConstant',
|
| + MessageKind.INVALID_LOGICAL_OR_OPERAND_TYPE),
|
| + const ConstantData('integer || true', 'NonConstant',
|
| + MessageKind.INVALID_LOGICAL_OR_OPERAND_TYPE),
|
| + const ConstantData('true && 0', 'NonConstant',
|
| + MessageKind.INVALID_LOGICAL_AND_OPERAND_TYPE),
|
| + const ConstantData('0 && true', 'NonConstant',
|
| + MessageKind.INVALID_LOGICAL_AND_OPERAND_TYPE),
|
| + const ConstantData('integer && true', 'NonConstant',
|
| + MessageKind.INVALID_LOGICAL_AND_OPERAND_TYPE),
|
| + const ConstantData('!0', 'NonConstant',
|
| + MessageKind.INVALID_CONSTANT_NOT_TYPE),
|
| + const ConstantData('!string', 'NonConstant',
|
| + MessageKind.INVALID_CONSTANT_NOT_TYPE),
|
| + const ConstantData('-("")', 'NonConstant',
|
| + MessageKind.INVALID_CONSTANT_NEGATE_TYPE),
|
| + const ConstantData('-(string)', 'NonConstant',
|
| + MessageKind.INVALID_CONSTANT_NEGATE_TYPE),
|
| + ]),
|
| ];
|
|
|
| main() {
|
| @@ -215,22 +431,70 @@ Future testData(TestData data) async {
|
| });
|
| sb.write('main() {}\n');
|
| String source = sb.toString();
|
| + DiagnosticCollector collector = new DiagnosticCollector();
|
| CompilationResult result = await runCompiler(
|
| - memorySourceFiles: {'main.dart': source}, options: ['--analyze-all']);
|
| + memorySourceFiles: {'main.dart': source},
|
| + diagnosticHandler: collector,
|
| + options: ['--analyze-only']);
|
| Compiler compiler = result.compiler;
|
| + Expect.isTrue(collector.errors.isEmpty,
|
| + "Unexpected errors: ${collector.errors}");
|
| + Expect.isTrue(collector.warnings.isEmpty,
|
| + "Unexpected warnings: ${collector.warnings}");
|
| + compiler.enqueuer.resolution.queueIsClosed = false;
|
| var library = compiler.mainApp;
|
| constants.forEach((String name, ConstantData data) {
|
| - FieldElement field = library.localLookup(name);
|
| + collector.clear();
|
| + FieldElementX field = library.localLookup(name);
|
| + compiler.enqueuer.resolution.addToWorkList(field);
|
| + compiler.processEnqueuerQueue(compiler.enqueuer.resolution);
|
| +
|
| + Expect.isNotNull(field.constantCache,
|
| + "Expected non-null constant for field "
|
| + "`$field = ${field.initializer}`.");
|
| ConstantExpression constant = field.constant;
|
| - data.expectedValues.forEach(
|
| + Expect.isNotNull(constant,
|
| + "Expected non-null constant for field "
|
| + "`$field = ${field.initializer}`.");
|
| + var expectedResults = data.expectedResults;
|
| + if (expectedResults is String) {
|
| + expectedResults = { const <String, String>{}: expectedResults};
|
| + }
|
| + expectedResults.forEach(
|
| (Map<String, String> env, String expectedText) {
|
| - Environment environment = new MemoryEnvironment(compiler, env);
|
| + Environment environment =
|
| + new MemoryEnvironment(
|
| + compiler, field/*.initializer*/, env);
|
| ConstantValue value =
|
| constant.evaluate(environment, DART_CONSTANT_SYSTEM);
|
| + Expect.isNotNull(value,
|
| + "Expected non-null value from evaluation of "
|
| + "`${constant.getText()}`.");
|
| String valueText = value.toStructuredString();
|
| Expect.equals(expectedText, valueText,
|
| "Unexpected value '${valueText}' for contant "
|
| "`${constant.getText()}`, expected '${expectedText}'.");
|
| + return;
|
| + List<MessageKind> errors =
|
| + collector.errors.map((m) => m.message.kind).
|
| + where((k) {
|
| + return k != MessageKind.NOT_ASSIGNABLE &&
|
| + k != MessageKind.NOT_A_COMPILE_TIME_CONSTANT;
|
| + }).toList();
|
| + var expectedErrors = data.expectedErrors;
|
| + if (expectedErrors != null) {
|
| + if (expectedErrors is! List) {
|
| + expectedErrors = [expectedErrors];
|
| + }
|
| + Expect.listEquals(expectedErrors, errors,
|
| + "Error mismatch for `$field = ${field.initializer}`:\n"
|
| + "Expected: ${data.expectedErrors},\n"
|
| + "Found: ${errors}.");
|
| + } else {
|
| + Expect.isTrue(errors.isEmpty,
|
| + "Unexpected errors for `$field = ${field.initializer}`:\n"
|
| + "Found: ${errors}.");
|
| + }
|
| });
|
| });
|
| }
|
|
|