| Index: pkg/analyzer/test/generated/resolver_test.dart
|
| diff --git a/pkg/analyzer/test/generated/resolver_test.dart b/pkg/analyzer/test/generated/resolver_test.dart
|
| index 3fd5c07eb6a0ab82221c5a965eb3dc04d7fa9ad8..866010caa589a73d91dbd8c850f711e1a7265492 100644
|
| --- a/pkg/analyzer/test/generated/resolver_test.dart
|
| +++ b/pkg/analyzer/test/generated/resolver_test.dart
|
| @@ -995,13 +995,13 @@ class C<T> {
|
| final T x = y;
|
| const C();
|
| }
|
| -const y = 1;
|
| +const int y = 1;
|
| var v = const C<String>();
|
| ''');
|
| computeLibrarySourceErrors(source);
|
| assertErrors(source, [
|
| CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH,
|
| - HintCode.INVALID_ASSIGNMENT
|
| + StaticTypeWarningCode.INVALID_ASSIGNMENT
|
| ]);
|
| verify([source]);
|
| }
|
| @@ -1027,11 +1027,11 @@ class C<T> {
|
| final T x = y;
|
| const C();
|
| }
|
| -const y = 1;
|
| +const int y = 1;
|
| var v = const C<int>();
|
| ''');
|
| computeLibrarySourceErrors(source);
|
| - assertErrors(source, [HintCode.INVALID_ASSIGNMENT]);
|
| + assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]);
|
| verify([source]);
|
| }
|
|
|
| @@ -9974,31 +9974,6 @@ class SourceContainer_ChangeSetTest_test_toString implements SourceContainer {
|
| }
|
|
|
| /**
|
| - * Shared infrastructure for [StaticTypeAnalyzer2Test] and
|
| - * [StrongModeStaticTypeAnalyzer2Test].
|
| - */
|
| -class _StaticTypeAnalyzer2TestShared extends ResolverTestCase {
|
| - String testCode;
|
| - Source testSource;
|
| - CompilationUnit testUnit;
|
| -
|
| - SimpleIdentifier _findIdentifier(String search) {
|
| - SimpleIdentifier identifier = EngineTestCase.findNode(
|
| - testUnit, testCode, search, (node) => node is SimpleIdentifier);
|
| - return identifier;
|
| - }
|
| -
|
| - void _resolveTestUnit(String code) {
|
| - testCode = code;
|
| - testSource = addSource(testCode);
|
| - LibraryElement library = resolve2(testSource);
|
| - assertNoErrors(testSource);
|
| - verify([testSource]);
|
| - testUnit = resolveCompilationUnit(testSource, library);
|
| - }
|
| -}
|
| -
|
| -/**
|
| * Like [StaticTypeAnalyzerTest], but as end-to-end tests.
|
| */
|
| @reflectiveTest
|
| @@ -11915,10 +11890,11 @@ class StrongModeStaticTypeAnalyzer2Test extends _StaticTypeAnalyzer2TestShared {
|
| resetWithOptions(options);
|
| }
|
|
|
| - void test_ternaryOperator_null_right() {
|
| + void test_dynamicObjectGetter_hashCode() {
|
| String code = r'''
|
| main() {
|
| - var foo = (true) ? 3 : null;
|
| + dynamic a = null;
|
| + var foo = a.hashCode;
|
| }
|
| ''';
|
| _resolveTestUnit(code);
|
| @@ -11930,10 +11906,11 @@ main() {
|
| expect(declaration.initializer.propagatedType, isNull);
|
| }
|
|
|
| - void test_ternaryOperator_null_left() {
|
| + void test_dynamicObjectMethod_toString() {
|
| String code = r'''
|
| main() {
|
| - var foo = (true) ? null : 3;
|
| + dynamic a = null;
|
| + var foo = a.toString();
|
| }
|
| ''';
|
| _resolveTestUnit(code);
|
| @@ -11941,15 +11918,15 @@ main() {
|
| SimpleIdentifier identifier = _findIdentifier('foo');
|
| VariableDeclaration declaration =
|
| identifier.getAncestor((node) => node is VariableDeclaration);
|
| - expect(declaration.initializer.staticType.name, 'int');
|
| + expect(declaration.initializer.staticType.name, 'String');
|
| expect(declaration.initializer.propagatedType, isNull);
|
| }
|
|
|
| - void test_dynamicObjectMethod_toString() {
|
| + void test_pseudoGeneric_max_doubleDouble() {
|
| String code = r'''
|
| +import 'dart:math';
|
| main() {
|
| - dynamic a = null;
|
| - var foo = a.toString();
|
| + var foo = max(1.0, 2.0);
|
| }
|
| ''';
|
| _resolveTestUnit(code);
|
| @@ -11957,15 +11934,15 @@ main() {
|
| SimpleIdentifier identifier = _findIdentifier('foo');
|
| VariableDeclaration declaration =
|
| identifier.getAncestor((node) => node is VariableDeclaration);
|
| - expect(declaration.initializer.staticType.name, 'String');
|
| + expect(declaration.initializer.staticType.name, 'double');
|
| expect(declaration.initializer.propagatedType, isNull);
|
| }
|
|
|
| - void test_dynamicObjectGetter_hashCode() {
|
| + void test_pseudoGeneric_max_doubleInt() {
|
| String code = r'''
|
| +import 'dart:math';
|
| main() {
|
| - dynamic a = null;
|
| - var foo = a.hashCode;
|
| + var foo = max(1.0, 2);
|
| }
|
| ''';
|
| _resolveTestUnit(code);
|
| @@ -11973,15 +11950,15 @@ main() {
|
| SimpleIdentifier identifier = _findIdentifier('foo');
|
| VariableDeclaration declaration =
|
| identifier.getAncestor((node) => node is VariableDeclaration);
|
| - expect(declaration.initializer.staticType.name, 'int');
|
| + expect(declaration.initializer.staticType.name, 'num');
|
| expect(declaration.initializer.propagatedType, isNull);
|
| }
|
|
|
| - void test_pseudoGeneric_max_intInt() {
|
| + void test_pseudoGeneric_max_intDouble() {
|
| String code = r'''
|
| import 'dart:math';
|
| main() {
|
| - var foo = max(1, 2);
|
| + var foo = max(1, 2.0);
|
| }
|
| ''';
|
| _resolveTestUnit(code);
|
| @@ -11989,15 +11966,15 @@ main() {
|
| SimpleIdentifier identifier = _findIdentifier('foo');
|
| VariableDeclaration declaration =
|
| identifier.getAncestor((node) => node is VariableDeclaration);
|
| - expect(declaration.initializer.staticType.name, 'int');
|
| + expect(declaration.initializer.staticType.name, 'num');
|
| expect(declaration.initializer.propagatedType, isNull);
|
| }
|
|
|
| - void test_pseudoGeneric_max_doubleDouble() {
|
| + void test_pseudoGeneric_max_intInt() {
|
| String code = r'''
|
| import 'dart:math';
|
| main() {
|
| - var foo = max(1.0, 2.0);
|
| + var foo = max(1, 2);
|
| }
|
| ''';
|
| _resolveTestUnit(code);
|
| @@ -12005,15 +11982,17 @@ main() {
|
| SimpleIdentifier identifier = _findIdentifier('foo');
|
| VariableDeclaration declaration =
|
| identifier.getAncestor((node) => node is VariableDeclaration);
|
| - expect(declaration.initializer.staticType.name, 'double');
|
| + expect(declaration.initializer.staticType.name, 'int');
|
| expect(declaration.initializer.propagatedType, isNull);
|
| }
|
|
|
| - void test_pseudoGeneric_max_intDouble() {
|
| + void test_pseudoGeneric_then() {
|
| String code = r'''
|
| -import 'dart:math';
|
| +import 'dart:async';
|
| +String toString(int x) => x.toString();
|
| main() {
|
| - var foo = max(1, 2.0);
|
| + Future<int> bar = null;
|
| + var foo = bar.then(toString);
|
| }
|
| ''';
|
| _resolveTestUnit(code);
|
| @@ -12021,15 +12000,15 @@ main() {
|
| SimpleIdentifier identifier = _findIdentifier('foo');
|
| VariableDeclaration declaration =
|
| identifier.getAncestor((node) => node is VariableDeclaration);
|
| - expect(declaration.initializer.staticType.name, 'num');
|
| +
|
| + expect(declaration.initializer.staticType.toString(), "Future<String>");
|
| expect(declaration.initializer.propagatedType, isNull);
|
| }
|
|
|
| - void test_pseudoGeneric_max_doubleInt() {
|
| + void test_ternaryOperator_null_left() {
|
| String code = r'''
|
| -import 'dart:math';
|
| main() {
|
| - var foo = max(1.0, 2);
|
| + var foo = (true) ? null : 3;
|
| }
|
| ''';
|
| _resolveTestUnit(code);
|
| @@ -12037,17 +12016,14 @@ main() {
|
| SimpleIdentifier identifier = _findIdentifier('foo');
|
| VariableDeclaration declaration =
|
| identifier.getAncestor((node) => node is VariableDeclaration);
|
| - expect(declaration.initializer.staticType.name, 'num');
|
| + expect(declaration.initializer.staticType.name, 'int');
|
| expect(declaration.initializer.propagatedType, isNull);
|
| }
|
|
|
| - void test_pseudoGeneric_then() {
|
| + void test_ternaryOperator_null_right() {
|
| String code = r'''
|
| -import 'dart:async';
|
| -String toString(int x) => x.toString();
|
| main() {
|
| - Future<int> bar = null;
|
| - var foo = bar.then(toString);
|
| + var foo = (true) ? 3 : null;
|
| }
|
| ''';
|
| _resolveTestUnit(code);
|
| @@ -12055,8 +12031,7 @@ main() {
|
| SimpleIdentifier identifier = _findIdentifier('foo');
|
| VariableDeclaration declaration =
|
| identifier.getAncestor((node) => node is VariableDeclaration);
|
| -
|
| - expect(declaration.initializer.staticType.toString(), "Future<String>");
|
| + expect(declaration.initializer.staticType.name, 'int');
|
| expect(declaration.initializer.propagatedType, isNull);
|
| }
|
| }
|
| @@ -12555,6 +12530,18 @@ f(p) {
|
| code, typeProvider.dynamicType, typeProvider.intType);
|
| }
|
|
|
| + void fail_finalPropertyInducingVariable_classMember_instance_unprefixed() {
|
| + String code = r'''
|
| +class A {
|
| + final v = 0;
|
| + m() {
|
| + v; // marker
|
| + }
|
| +}''';
|
| + _assertTypeOfMarkedExpression(
|
| + code, typeProvider.dynamicType, typeProvider.intType);
|
| + }
|
| +
|
| void fail_finalPropertyInducingVariable_classMember_static() {
|
| addNamedSource(
|
| "/lib.dart",
|
| @@ -13849,6 +13836,99 @@ void g() {
|
| assertNoErrors(source);
|
| }
|
|
|
| + void test_objectAccessInference_disabled_for_library_prefix() {
|
| + String name = 'hashCode';
|
| + addNamedSource(
|
| + '/helper.dart',
|
| + '''
|
| +library helper;
|
| +dynamic get $name => 42;
|
| +''');
|
| + String code = '''
|
| +import 'helper.dart' as helper;
|
| +main() {
|
| + helper.$name; // marker
|
| +}''';
|
| +
|
| + SimpleIdentifier id = _findMarkedIdentifier(code, "; // marker");
|
| + PrefixedIdentifier prefixedId = id.parent;
|
| + expect(id.staticType, typeProvider.dynamicType);
|
| + expect(prefixedId.staticType, typeProvider.dynamicType);
|
| + }
|
| +
|
| + void test_objectAccessInference_disabled_for_local_getter() {
|
| + String name = 'hashCode';
|
| + String code = '''
|
| +dynamic get $name => null;
|
| +main() {
|
| + $name; // marker
|
| +}''';
|
| +
|
| + SimpleIdentifier getter = _findMarkedIdentifier(code, "; // marker");
|
| + expect(getter.staticType, typeProvider.dynamicType);
|
| + }
|
| +
|
| + void test_objectAccessInference_enabled_for_cascades() {
|
| + String name = 'hashCode';
|
| + String code = '''
|
| +main() {
|
| + dynamic obj;
|
| + obj..$name..$name; // marker
|
| +}''';
|
| + PropertyAccess access = _findMarkedIdentifier(code, "; // marker").parent;
|
| + expect(access.staticType, typeProvider.dynamicType);
|
| + expect(access.realTarget.staticType, typeProvider.dynamicType);
|
| + }
|
| +
|
| + void test_objectMethodInference_disabled_for_library_prefix() {
|
| + String name = 'toString';
|
| + addNamedSource(
|
| + '/helper.dart',
|
| + '''
|
| +library helper;
|
| +dynamic $name = (int x) => x + 42');
|
| +''');
|
| + String code = '''
|
| +import 'helper.dart' as helper;
|
| +main() {
|
| + helper.$name(); // marker
|
| +}''';
|
| + SimpleIdentifier methodName = _findMarkedIdentifier(code, "(); // marker");
|
| + MethodInvocation methodInvoke = methodName.parent;
|
| + expect(methodName.staticType, null, reason: 'library prefix has no type');
|
| + expect(methodInvoke.staticType, typeProvider.dynamicType);
|
| + }
|
| +
|
| + void test_objectMethodInference_disabled_for_local_function() {
|
| + String name = 'toString';
|
| + String code = '''
|
| +main() {
|
| + dynamic $name = () => null;
|
| + $name(); // marker
|
| +}''';
|
| + SimpleIdentifier identifier = _findMarkedIdentifier(code, "$name = ");
|
| + expect(identifier.staticType, typeProvider.dynamicType);
|
| +
|
| + SimpleIdentifier methodName = _findMarkedIdentifier(code, "(); // marker");
|
| + MethodInvocation methodInvoke = methodName.parent;
|
| + expect(methodName.staticType, typeProvider.dynamicType);
|
| + expect(methodInvoke.staticType, typeProvider.dynamicType);
|
| + }
|
| +
|
| + void test_objectMethodInference_enabled_for_cascades() {
|
| + String name = 'toString';
|
| + String code = '''
|
| +main() {
|
| + dynamic obj;
|
| + obj..$name()..$name(); // marker
|
| +}''';
|
| + SimpleIdentifier methodName = _findMarkedIdentifier(code, "(); // marker");
|
| + MethodInvocation methodInvoke = methodName.parent;
|
| +
|
| + expect(methodInvoke.staticType, typeProvider.dynamicType);
|
| + expect(methodInvoke.realTarget.staticType, typeProvider.dynamicType);
|
| + }
|
| +
|
| void test_objectMethodOnDynamicExpression_doubleEquals() {
|
| // https://code.google.com/p/dart/issues/detail?id=20342
|
| //
|
| @@ -13902,96 +13982,6 @@ f1(x) {
|
| typeProvider.stringType);
|
| }
|
|
|
| - void test_objectMethodInference_disabled_for_local_function() {
|
| - String name = 'toString';
|
| - String code = '''
|
| -main() {
|
| - dynamic $name = () => null;
|
| - $name(); // marker
|
| -}''';
|
| - SimpleIdentifier identifier = _findMarkedIdentifier(code, "$name = ");
|
| - expect(identifier.staticType, typeProvider.dynamicType);
|
| -
|
| - SimpleIdentifier methodName = _findMarkedIdentifier(code, "(); // marker");
|
| - MethodInvocation methodInvoke = methodName.parent;
|
| - expect(methodName.staticType, typeProvider.dynamicType);
|
| - expect(methodInvoke.staticType, typeProvider.dynamicType);
|
| - }
|
| -
|
| - void test_objectMethodInference_disabled_for_library_prefix() {
|
| - String name = 'toString';
|
| - addNamedSource('/helper.dart', '''
|
| -library helper;
|
| -dynamic $name = (int x) => x + 42');
|
| -''');
|
| - String code = '''
|
| -import 'helper.dart' as helper;
|
| -main() {
|
| - helper.$name(); // marker
|
| -}''';
|
| - SimpleIdentifier methodName = _findMarkedIdentifier(code, "(); // marker");
|
| - MethodInvocation methodInvoke = methodName.parent;
|
| - expect(methodName.staticType, null, reason: 'library prefix has no type');
|
| - expect(methodInvoke.staticType, typeProvider.dynamicType);
|
| - }
|
| -
|
| - void test_objectMethodInference_enabled_for_cascades() {
|
| - String name = 'toString';
|
| - String code = '''
|
| -main() {
|
| - dynamic obj;
|
| - obj..$name()..$name(); // marker
|
| -}''';
|
| - SimpleIdentifier methodName = _findMarkedIdentifier(code, "(); // marker");
|
| - MethodInvocation methodInvoke = methodName.parent;
|
| -
|
| - expect(methodInvoke.staticType, typeProvider.dynamicType);
|
| - expect(methodInvoke.realTarget.staticType, typeProvider.dynamicType);
|
| - }
|
| -
|
| -
|
| - void test_objectAccessInference_disabled_for_local_getter() {
|
| - String name = 'hashCode';
|
| - String code = '''
|
| -dynamic get $name => null;
|
| -main() {
|
| - $name; // marker
|
| -}''';
|
| -
|
| - SimpleIdentifier getter = _findMarkedIdentifier(code, "; // marker");
|
| - expect(getter.staticType, typeProvider.dynamicType);
|
| - }
|
| -
|
| - void test_objectAccessInference_disabled_for_library_prefix() {
|
| - String name = 'hashCode';
|
| - addNamedSource('/helper.dart', '''
|
| -library helper;
|
| -dynamic get $name => 42;
|
| -''');
|
| - String code = '''
|
| -import 'helper.dart' as helper;
|
| -main() {
|
| - helper.$name; // marker
|
| -}''';
|
| -
|
| - SimpleIdentifier id = _findMarkedIdentifier(code, "; // marker");
|
| - PrefixedIdentifier prefixedId = id.parent;
|
| - expect(id.staticType, typeProvider.dynamicType);
|
| - expect(prefixedId.staticType, typeProvider.dynamicType);
|
| - }
|
| -
|
| - void test_objectAccessInference_enabled_for_cascades() {
|
| - String name = 'hashCode';
|
| - String code = '''
|
| -main() {
|
| - dynamic obj;
|
| - obj..$name..$name; // marker
|
| -}''';
|
| - PropertyAccess access = _findMarkedIdentifier(code, "; // marker").parent;
|
| - expect(access.staticType, typeProvider.dynamicType);
|
| - expect(access.realTarget.staticType, typeProvider.dynamicType);
|
| - }
|
| -
|
| void test_propagatedReturnType_localFunction() {
|
| String code = r'''
|
| main() {
|
| @@ -14829,3 +14819,28 @@ class _SimpleResolverTest_localVariable_types_invoked
|
| return null;
|
| }
|
| }
|
| +
|
| +/**
|
| + * Shared infrastructure for [StaticTypeAnalyzer2Test] and
|
| + * [StrongModeStaticTypeAnalyzer2Test].
|
| + */
|
| +class _StaticTypeAnalyzer2TestShared extends ResolverTestCase {
|
| + String testCode;
|
| + Source testSource;
|
| + CompilationUnit testUnit;
|
| +
|
| + SimpleIdentifier _findIdentifier(String search) {
|
| + SimpleIdentifier identifier = EngineTestCase.findNode(
|
| + testUnit, testCode, search, (node) => node is SimpleIdentifier);
|
| + return identifier;
|
| + }
|
| +
|
| + void _resolveTestUnit(String code) {
|
| + testCode = code;
|
| + testSource = addSource(testCode);
|
| + LibraryElement library = resolve2(testSource);
|
| + assertNoErrors(testSource);
|
| + verify([testSource]);
|
| + testUnit = resolveCompilationUnit(testSource, library);
|
| + }
|
| +}
|
|
|