| // This code was auto-generated, is not intended to be edited, and is subject to |
| // significant change. Please see the README file for more information. |
| library engine.resolver_test; |
| import 'package:analyzer_experimental/src/generated/java_core.dart'; |
| import 'package:analyzer_experimental/src/generated/java_junit.dart'; |
| import 'package:analyzer_experimental/src/generated/source_io.dart'; |
| import 'package:analyzer_experimental/src/generated/error.dart'; |
| import 'package:analyzer_experimental/src/generated/scanner.dart'; |
| import 'package:analyzer_experimental/src/generated/ast.dart'; |
| import 'package:analyzer_experimental/src/generated/parser.dart' show ParserErrorCode; |
| import 'package:analyzer_experimental/src/generated/element.dart'; |
| import 'package:analyzer_experimental/src/generated/resolver.dart'; |
| import 'package:analyzer_experimental/src/generated/engine.dart'; |
| import 'package:analyzer_experimental/src/generated/java_engine_io.dart'; |
| import 'package:analyzer_experimental/src/generated/sdk.dart' show DartSdk; |
| import 'package:analyzer_experimental/src/generated/sdk_io.dart' show DirectoryBasedDartSdk; |
| import 'package:unittest/unittest.dart' as _ut; |
| import 'test_support.dart'; |
| import 'ast_test.dart' show ASTFactory; |
| import 'element_test.dart' show ElementFactory; |
| class TypePropagationTest extends ResolverTestCase { |
| void fail_functionExpression_asInvocationArgument_functionExpressionInvocation() { |
| String code = EngineTestCase.createSource([ |
| "main() {", |
| " (f(String value)) {} ((v) {", |
| " v;", |
| " });", |
| "}"]); |
| Source source = addSource(code); |
| LibraryElement library = resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| CompilationUnit unit = resolveCompilationUnit(source, library); |
| Type2 dynamicType = typeProvider.dynamicType; |
| Type2 stringType = typeProvider.stringType; |
| FormalParameter vParameter = EngineTestCase.findNode(unit, code, "v)", FormalParameter); |
| JUnitTestCase.assertSame(stringType, vParameter.identifier.propagatedType); |
| JUnitTestCase.assertSame(dynamicType, vParameter.identifier.staticType); |
| SimpleIdentifier vIdentifier = EngineTestCase.findNode(unit, code, "v;", SimpleIdentifier); |
| JUnitTestCase.assertSame(stringType, vIdentifier.propagatedType); |
| JUnitTestCase.assertSame(dynamicType, vIdentifier.staticType); |
| } |
| void fail_propagatedReturnType_functionExpression() { |
| String code = EngineTestCase.createSource(["main() {", " var v = (() {return 42;})();", "}"]); |
| check_propagatedReturnType(code, typeProvider.dynamicType, typeProvider.intType); |
| } |
| void test_as() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " bool get g => true;", |
| "}", |
| "A f(var p) {", |
| " if ((p as A).g) {", |
| " return p;", |
| " } else {", |
| " return null;", |
| " }", |
| "}"])); |
| LibraryElement library = resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| CompilationUnit unit = resolveCompilationUnit(source, library); |
| ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| InterfaceType typeA = classA.element.type; |
| FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| BlockFunctionBody body = function.functionExpression.body as BlockFunctionBody; |
| IfStatement ifStatement = body.block.statements[0] as IfStatement; |
| ReturnStatement statement = ((ifStatement.thenStatement as Block)).statements[0] as ReturnStatement; |
| SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| JUnitTestCase.assertSame(typeA, variableName.propagatedType); |
| } |
| void test_assert() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {}", |
| "A f(var p) {", |
| " assert (p is A);", |
| " return p;", |
| "}"])); |
| LibraryElement library = resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| CompilationUnit unit = resolveCompilationUnit(source, library); |
| ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| InterfaceType typeA = classA.element.type; |
| FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| BlockFunctionBody body = function.functionExpression.body as BlockFunctionBody; |
| ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| JUnitTestCase.assertSame(typeA, variableName.propagatedType); |
| } |
| void test_assignment() { |
| Source source = addSource(EngineTestCase.createSource(["f() {", " var v;", " v = 0;", " return v;", "}"])); |
| LibraryElement library = resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| CompilationUnit unit = resolveCompilationUnit(source, library); |
| FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| BlockFunctionBody body = function.functionExpression.body as BlockFunctionBody; |
| ReturnStatement statement = body.block.statements[2] as ReturnStatement; |
| SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| JUnitTestCase.assertSame(typeProvider.intType, variableName.propagatedType); |
| } |
| void test_assignment_afterInitializer() { |
| Source source = addSource(EngineTestCase.createSource(["f() {", " var v = 0;", " v = 1.0;", " return v;", "}"])); |
| LibraryElement library = resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| CompilationUnit unit = resolveCompilationUnit(source, library); |
| FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| BlockFunctionBody body = function.functionExpression.body as BlockFunctionBody; |
| ReturnStatement statement = body.block.statements[2] as ReturnStatement; |
| SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| JUnitTestCase.assertSame(typeProvider.doubleType, variableName.propagatedType); |
| } |
| void test_forEach() { |
| String code = EngineTestCase.createSource([ |
| "f(List<String> p) {", |
| " for (var e in p) {", |
| " e;", |
| " }", |
| "}"]); |
| Source source = addSource(code); |
| LibraryElement library = resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| CompilationUnit unit = resolveCompilationUnit(source, library); |
| InterfaceType stringType = typeProvider.stringType; |
| { |
| SimpleIdentifier identifier = EngineTestCase.findNode(unit, code, "e in", SimpleIdentifier); |
| JUnitTestCase.assertSame(stringType, identifier.propagatedType); |
| } |
| { |
| SimpleIdentifier identifier = EngineTestCase.findNode(unit, code, "e;", SimpleIdentifier); |
| JUnitTestCase.assertSame(stringType, identifier.propagatedType); |
| } |
| } |
| void test_functionExpression_asInvocationArgument() { |
| String code = EngineTestCase.createSource([ |
| "class MyMap<K, V> {", |
| " forEach(f(K key, V value)) {}", |
| "}", |
| "f(MyMap<int, String> m) {", |
| " m.forEach((k, v) {", |
| " k;", |
| " v;", |
| " });", |
| "}"]); |
| Source source = addSource(code); |
| LibraryElement library = resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| CompilationUnit unit = resolveCompilationUnit(source, library); |
| Type2 intType = typeProvider.intType; |
| FormalParameter kParameter = EngineTestCase.findNode(unit, code, "k, ", SimpleFormalParameter); |
| JUnitTestCase.assertSame(intType, kParameter.identifier.propagatedType); |
| SimpleIdentifier kIdentifier = EngineTestCase.findNode(unit, code, "k;", SimpleIdentifier); |
| JUnitTestCase.assertSame(intType, kIdentifier.propagatedType); |
| JUnitTestCase.assertSame(typeProvider.dynamicType, kIdentifier.staticType); |
| Type2 stringType = typeProvider.stringType; |
| FormalParameter vParameter = EngineTestCase.findNode(unit, code, "v)", SimpleFormalParameter); |
| JUnitTestCase.assertSame(stringType, vParameter.identifier.propagatedType); |
| SimpleIdentifier vIdentifier = EngineTestCase.findNode(unit, code, "v;", SimpleIdentifier); |
| JUnitTestCase.assertSame(stringType, vIdentifier.propagatedType); |
| JUnitTestCase.assertSame(typeProvider.dynamicType, vIdentifier.staticType); |
| } |
| void test_functionExpression_asInvocationArgument_fromInferredInvocation() { |
| String code = EngineTestCase.createSource([ |
| "class MyMap<K, V> {", |
| " forEach(f(K key, V value)) {}", |
| "}", |
| "f(MyMap<int, String> m) {", |
| " var m2 = m;", |
| " m2.forEach((k, v) {});", |
| "}"]); |
| Source source = addSource(code); |
| LibraryElement library = resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| CompilationUnit unit = resolveCompilationUnit(source, library); |
| Type2 intType = typeProvider.intType; |
| FormalParameter kParameter = EngineTestCase.findNode(unit, code, "k, ", SimpleFormalParameter); |
| JUnitTestCase.assertSame(intType, kParameter.identifier.propagatedType); |
| Type2 stringType = typeProvider.stringType; |
| FormalParameter vParameter = EngineTestCase.findNode(unit, code, "v)", SimpleFormalParameter); |
| JUnitTestCase.assertSame(stringType, vParameter.identifier.propagatedType); |
| } |
| void test_functionExpression_asInvocationArgument_keepIfLessSpecific() { |
| String code = EngineTestCase.createSource([ |
| "class MyList {", |
| " forEach(f(Object value)) {}", |
| "}", |
| "f(MyList list) {", |
| " list.forEach((int v) {", |
| " v;", |
| " });", |
| "}"]); |
| Source source = addSource(code); |
| LibraryElement library = resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| CompilationUnit unit = resolveCompilationUnit(source, library); |
| Type2 intType = typeProvider.intType; |
| FormalParameter vParameter = EngineTestCase.findNode(unit, code, "v)", SimpleFormalParameter); |
| JUnitTestCase.assertSame(null, vParameter.identifier.propagatedType); |
| JUnitTestCase.assertSame(intType, vParameter.identifier.staticType); |
| SimpleIdentifier vIdentifier = EngineTestCase.findNode(unit, code, "v;", SimpleIdentifier); |
| JUnitTestCase.assertSame(intType, vIdentifier.staticType); |
| JUnitTestCase.assertSame(null, vIdentifier.propagatedType); |
| } |
| void test_functionExpression_asInvocationArgument_replaceIfMoreSpecific() { |
| String code = EngineTestCase.createSource([ |
| "class MyList<E> {", |
| " forEach(f(E value)) {}", |
| "}", |
| "f(MyList<String> list) {", |
| " list.forEach((Object v) {", |
| " v;", |
| " });", |
| "}"]); |
| Source source = addSource(code); |
| LibraryElement library = resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| CompilationUnit unit = resolveCompilationUnit(source, library); |
| Type2 stringType = typeProvider.stringType; |
| FormalParameter vParameter = EngineTestCase.findNode(unit, code, "v)", SimpleFormalParameter); |
| JUnitTestCase.assertSame(stringType, vParameter.identifier.propagatedType); |
| JUnitTestCase.assertSame(typeProvider.objectType, vParameter.identifier.staticType); |
| SimpleIdentifier vIdentifier = EngineTestCase.findNode(unit, code, "v;", SimpleIdentifier); |
| JUnitTestCase.assertSame(stringType, vIdentifier.propagatedType); |
| } |
| void test_Future_then() { |
| String code = EngineTestCase.createSource([ |
| "import 'dart:async';", |
| "main(Future<int> firstFuture) {", |
| " firstFuture.then((p1) {", |
| " return 1.0;", |
| " }).then((p2) {", |
| " return new Future<String>.value('str');", |
| " }).then((p3) {", |
| " });", |
| "}"]); |
| Source source = addSource(code); |
| LibraryElement library = resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| CompilationUnit unit = resolveCompilationUnit(source, library); |
| FormalParameter p1 = EngineTestCase.findNode(unit, code, "p1) {", SimpleFormalParameter); |
| JUnitTestCase.assertSame(typeProvider.intType, p1.identifier.propagatedType); |
| FormalParameter p2 = EngineTestCase.findNode(unit, code, "p2) {", SimpleFormalParameter); |
| JUnitTestCase.assertSame(typeProvider.doubleType, p2.identifier.propagatedType); |
| FormalParameter p3 = EngineTestCase.findNode(unit, code, "p3) {", SimpleFormalParameter); |
| JUnitTestCase.assertSame(typeProvider.stringType, p3.identifier.propagatedType); |
| } |
| void test_initializer() { |
| Source source = addSource(EngineTestCase.createSource(["f() {", " var v = 0;", " return v;", "}"])); |
| LibraryElement library = resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| CompilationUnit unit = resolveCompilationUnit(source, library); |
| FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| BlockFunctionBody body = function.functionExpression.body as BlockFunctionBody; |
| NodeList<Statement> statements = body.block.statements; |
| { |
| VariableDeclarationStatement statement = statements[0] as VariableDeclarationStatement; |
| SimpleIdentifier variableName = statement.variables.variables[0].name; |
| JUnitTestCase.assertSame(typeProvider.dynamicType, variableName.staticType); |
| JUnitTestCase.assertSame(typeProvider.intType, variableName.propagatedType); |
| } |
| { |
| ReturnStatement statement = statements[1] as ReturnStatement; |
| SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| JUnitTestCase.assertSame(typeProvider.intType, variableName.propagatedType); |
| } |
| } |
| void test_initializer_dereference() { |
| Source source = addSource(EngineTestCase.createSource(["f() {", " var v = 'String';", " v.", "}"])); |
| LibraryElement library = resolve(source); |
| CompilationUnit unit = resolveCompilationUnit(source, library); |
| FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| BlockFunctionBody body = function.functionExpression.body as BlockFunctionBody; |
| ExpressionStatement statement = body.block.statements[1] as ExpressionStatement; |
| PrefixedIdentifier invocation = statement.expression as PrefixedIdentifier; |
| SimpleIdentifier variableName = invocation.prefix; |
| JUnitTestCase.assertSame(typeProvider.stringType, variableName.propagatedType); |
| } |
| void test_is_conditional() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {}", |
| "A f(var p) {", |
| " return (p is A) ? p : null;", |
| "}"])); |
| LibraryElement library = resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| CompilationUnit unit = resolveCompilationUnit(source, library); |
| ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| InterfaceType typeA = classA.element.type; |
| FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| BlockFunctionBody body = function.functionExpression.body as BlockFunctionBody; |
| ReturnStatement statement = body.block.statements[0] as ReturnStatement; |
| ConditionalExpression conditional = statement.expression as ConditionalExpression; |
| SimpleIdentifier variableName = conditional.thenExpression as SimpleIdentifier; |
| JUnitTestCase.assertSame(typeA, variableName.propagatedType); |
| } |
| void test_is_if() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {}", |
| "A f(var p) {", |
| " if (p is A) {", |
| " return p;", |
| " } else {", |
| " return null;", |
| " }", |
| "}"])); |
| LibraryElement library = resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| CompilationUnit unit = resolveCompilationUnit(source, library); |
| ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| InterfaceType typeA = classA.element.type; |
| FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| BlockFunctionBody body = function.functionExpression.body as BlockFunctionBody; |
| IfStatement ifStatement = body.block.statements[0] as IfStatement; |
| ReturnStatement statement = ((ifStatement.thenStatement as Block)).statements[0] as ReturnStatement; |
| SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| JUnitTestCase.assertSame(typeA, variableName.propagatedType); |
| } |
| void test_is_if_lessSpecific() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {}", |
| "A f(A p) {", |
| " if (p is String) {", |
| " return p;", |
| " } else {", |
| " return null;", |
| " }", |
| "}"])); |
| LibraryElement library = resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| CompilationUnit unit = resolveCompilationUnit(source, library); |
| FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| BlockFunctionBody body = function.functionExpression.body as BlockFunctionBody; |
| IfStatement ifStatement = body.block.statements[0] as IfStatement; |
| ReturnStatement statement = ((ifStatement.thenStatement as Block)).statements[0] as ReturnStatement; |
| SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| JUnitTestCase.assertSame(null, variableName.propagatedType); |
| } |
| void test_is_if_logicalAnd() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {}", |
| "A f(var p) {", |
| " if (p is A && p != null) {", |
| " return p;", |
| " } else {", |
| " return null;", |
| " }", |
| "}"])); |
| LibraryElement library = resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| CompilationUnit unit = resolveCompilationUnit(source, library); |
| ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| InterfaceType typeA = classA.element.type; |
| FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| BlockFunctionBody body = function.functionExpression.body as BlockFunctionBody; |
| IfStatement ifStatement = body.block.statements[0] as IfStatement; |
| ReturnStatement statement = ((ifStatement.thenStatement as Block)).statements[0] as ReturnStatement; |
| SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| JUnitTestCase.assertSame(typeA, variableName.propagatedType); |
| } |
| void test_is_postConditional() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {}", |
| "A f(var p) {", |
| " A a = (p is A) ? p : throw null;", |
| " return p;", |
| "}"])); |
| LibraryElement library = resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| CompilationUnit unit = resolveCompilationUnit(source, library); |
| ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| InterfaceType typeA = classA.element.type; |
| FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| BlockFunctionBody body = function.functionExpression.body as BlockFunctionBody; |
| ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| JUnitTestCase.assertSame(typeA, variableName.propagatedType); |
| } |
| void test_is_postIf() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {}", |
| "A f(var p) {", |
| " if (p is A) {", |
| " A a = p;", |
| " } else {", |
| " return null;", |
| " }", |
| " return p;", |
| "}"])); |
| LibraryElement library = resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| CompilationUnit unit = resolveCompilationUnit(source, library); |
| ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| InterfaceType typeA = classA.element.type; |
| FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| BlockFunctionBody body = function.functionExpression.body as BlockFunctionBody; |
| ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| JUnitTestCase.assertSame(typeA, variableName.propagatedType); |
| } |
| void test_is_subclass() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {}", |
| "class B extends A {", |
| " B m() => this;", |
| "}", |
| "A f(A p) {", |
| " if (p is B) {", |
| " return p.m();", |
| " }", |
| "}"])); |
| LibraryElement library = resolve(source); |
| assertErrors(source, [StaticTypeWarningCode.UNDEFINED_METHOD]); |
| CompilationUnit unit = resolveCompilationUnit(source, library); |
| FunctionDeclaration function = unit.declarations[2] as FunctionDeclaration; |
| BlockFunctionBody body = function.functionExpression.body as BlockFunctionBody; |
| IfStatement ifStatement = body.block.statements[0] as IfStatement; |
| ReturnStatement statement = ((ifStatement.thenStatement as Block)).statements[0] as ReturnStatement; |
| MethodInvocation invocation = statement.expression as MethodInvocation; |
| JUnitTestCase.assertNotNull(invocation.methodName.propagatedElement); |
| } |
| void test_is_while() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {}", |
| "A f(var p) {", |
| " while (p is A) {", |
| " return p;", |
| " }", |
| "}"])); |
| LibraryElement library = resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| CompilationUnit unit = resolveCompilationUnit(source, library); |
| ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| InterfaceType typeA = classA.element.type; |
| FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| BlockFunctionBody body = function.functionExpression.body as BlockFunctionBody; |
| WhileStatement whileStatement = body.block.statements[0] as WhileStatement; |
| ReturnStatement statement = ((whileStatement.body as Block)).statements[0] as ReturnStatement; |
| SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| JUnitTestCase.assertSame(typeA, variableName.propagatedType); |
| } |
| void test_isNot_conditional() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {}", |
| "A f(var p) {", |
| " return (p is! A) ? null : p;", |
| "}"])); |
| LibraryElement library = resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| CompilationUnit unit = resolveCompilationUnit(source, library); |
| ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| InterfaceType typeA = classA.element.type; |
| FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| BlockFunctionBody body = function.functionExpression.body as BlockFunctionBody; |
| ReturnStatement statement = body.block.statements[0] as ReturnStatement; |
| ConditionalExpression conditional = statement.expression as ConditionalExpression; |
| SimpleIdentifier variableName = conditional.elseExpression as SimpleIdentifier; |
| JUnitTestCase.assertSame(typeA, variableName.propagatedType); |
| } |
| void test_isNot_if() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {}", |
| "A f(var p) {", |
| " if (p is! A) {", |
| " return null;", |
| " } else {", |
| " return p;", |
| " }", |
| "}"])); |
| LibraryElement library = resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| CompilationUnit unit = resolveCompilationUnit(source, library); |
| ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| InterfaceType typeA = classA.element.type; |
| FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| BlockFunctionBody body = function.functionExpression.body as BlockFunctionBody; |
| IfStatement ifStatement = body.block.statements[0] as IfStatement; |
| ReturnStatement statement = ((ifStatement.elseStatement as Block)).statements[0] as ReturnStatement; |
| SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| JUnitTestCase.assertSame(typeA, variableName.propagatedType); |
| } |
| void test_isNot_if_logicalOr() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {}", |
| "A f(var p) {", |
| " if (p is! A || null == p) {", |
| " return null;", |
| " } else {", |
| " return p;", |
| " }", |
| "}"])); |
| LibraryElement library = resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| CompilationUnit unit = resolveCompilationUnit(source, library); |
| ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| InterfaceType typeA = classA.element.type; |
| FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| BlockFunctionBody body = function.functionExpression.body as BlockFunctionBody; |
| IfStatement ifStatement = body.block.statements[0] as IfStatement; |
| ReturnStatement statement = ((ifStatement.elseStatement as Block)).statements[0] as ReturnStatement; |
| SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| JUnitTestCase.assertSame(typeA, variableName.propagatedType); |
| } |
| void test_isNot_postConditional() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {}", |
| "A f(var p) {", |
| " A a = (p is! A) ? throw null : p;", |
| " return p;", |
| "}"])); |
| LibraryElement library = resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| CompilationUnit unit = resolveCompilationUnit(source, library); |
| ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| InterfaceType typeA = classA.element.type; |
| FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| BlockFunctionBody body = function.functionExpression.body as BlockFunctionBody; |
| ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| JUnitTestCase.assertSame(typeA, variableName.propagatedType); |
| } |
| void test_isNot_postIf() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {}", |
| "A f(var p) {", |
| " if (p is! A) {", |
| " return null;", |
| " }", |
| " return p;", |
| "}"])); |
| LibraryElement library = resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| CompilationUnit unit = resolveCompilationUnit(source, library); |
| ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| InterfaceType typeA = classA.element.type; |
| FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| BlockFunctionBody body = function.functionExpression.body as BlockFunctionBody; |
| ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| JUnitTestCase.assertSame(typeA, variableName.propagatedType); |
| } |
| void test_listLiteral_different() { |
| Source source = addSource(EngineTestCase.createSource(["f() {", " var v = [0, '1', 2];", " return v[2];", "}"])); |
| LibraryElement library = resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| CompilationUnit unit = resolveCompilationUnit(source, library); |
| FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| BlockFunctionBody body = function.functionExpression.body as BlockFunctionBody; |
| ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| IndexExpression indexExpression = statement.expression as IndexExpression; |
| JUnitTestCase.assertNull(indexExpression.propagatedType); |
| } |
| void test_listLiteral_same() { |
| Source source = addSource(EngineTestCase.createSource(["f() {", " var v = [0, 1, 2];", " return v[2];", "}"])); |
| LibraryElement library = resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| CompilationUnit unit = resolveCompilationUnit(source, library); |
| FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| BlockFunctionBody body = function.functionExpression.body as BlockFunctionBody; |
| ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| IndexExpression indexExpression = statement.expression as IndexExpression; |
| JUnitTestCase.assertSame(typeProvider.intType, indexExpression.propagatedType); |
| } |
| void test_mapLiteral_different() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "f() {", |
| " var v = {'0' : 0, 1 : '1', '2' : 2};", |
| " return v;", |
| "}"])); |
| LibraryElement library = resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| CompilationUnit unit = resolveCompilationUnit(source, library); |
| FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| BlockFunctionBody body = function.functionExpression.body as BlockFunctionBody; |
| ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| SimpleIdentifier identifier = statement.expression as SimpleIdentifier; |
| InterfaceType propagatedType = identifier.propagatedType as InterfaceType; |
| JUnitTestCase.assertSame(typeProvider.mapType.element, propagatedType.element); |
| List<Type2> typeArguments = propagatedType.typeArguments; |
| EngineTestCase.assertLength(2, typeArguments); |
| JUnitTestCase.assertSame(typeProvider.dynamicType, typeArguments[0]); |
| JUnitTestCase.assertSame(typeProvider.dynamicType, typeArguments[1]); |
| } |
| void test_mapLiteral_same() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "f() {", |
| " var v = {'a' : 0, 'b' : 1, 'c' : 2};", |
| " return v;", |
| "}"])); |
| LibraryElement library = resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| CompilationUnit unit = resolveCompilationUnit(source, library); |
| FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| BlockFunctionBody body = function.functionExpression.body as BlockFunctionBody; |
| ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| SimpleIdentifier identifier = statement.expression as SimpleIdentifier; |
| InterfaceType propagatedType = identifier.propagatedType as InterfaceType; |
| JUnitTestCase.assertSame(typeProvider.mapType.element, propagatedType.element); |
| List<Type2> typeArguments = propagatedType.typeArguments; |
| EngineTestCase.assertLength(2, typeArguments); |
| JUnitTestCase.assertSame(typeProvider.stringType, typeArguments[0]); |
| JUnitTestCase.assertSame(typeProvider.intType, typeArguments[1]); |
| } |
| void test_propagatedReturnType_function_hasReturnType_returnsNull() { |
| String code = EngineTestCase.createSource(["String f() => null;", "main() {", " var v = f();", "}"]); |
| check_propagatedReturnType(code, typeProvider.dynamicType, typeProvider.stringType); |
| } |
| void test_propagatedReturnType_function_lessSpecificStaticReturnType() { |
| String code = EngineTestCase.createSource(["Object f() => 42;", "main() {", " var v = f();", "}"]); |
| check_propagatedReturnType(code, typeProvider.dynamicType, typeProvider.intType); |
| } |
| void test_propagatedReturnType_function_moreSpecificStaticReturnType() { |
| String code = EngineTestCase.createSource([ |
| "int f(v) => (v as num);", |
| "main() {", |
| " var v = f(3);", |
| "}"]); |
| check_propagatedReturnType(code, typeProvider.dynamicType, typeProvider.intType); |
| } |
| void test_propagatedReturnType_function_noReturnTypeName_blockBody_multipleReturns() { |
| String code = EngineTestCase.createSource([ |
| "f() {", |
| " if (true) return 0;", |
| " return 1.0;", |
| "}", |
| "main() {", |
| " var v = f();", |
| "}"]); |
| check_propagatedReturnType(code, typeProvider.dynamicType, typeProvider.numType); |
| } |
| void test_propagatedReturnType_function_noReturnTypeName_blockBody_oneReturn() { |
| String code = EngineTestCase.createSource([ |
| "f() {", |
| " var z = 42;", |
| " return z;", |
| "}", |
| "main() {", |
| " var v = f();", |
| "}"]); |
| check_propagatedReturnType(code, typeProvider.dynamicType, typeProvider.intType); |
| } |
| void test_propagatedReturnType_function_noReturnTypeName_expressionBody() { |
| String code = EngineTestCase.createSource(["f() => 42;", "main() {", " var v = f();", "}"]); |
| check_propagatedReturnType(code, typeProvider.dynamicType, typeProvider.intType); |
| } |
| void test_propagatedReturnType_localFunction() { |
| String code = EngineTestCase.createSource(["main() {", " f() => 42;", " var v = f();", "}"]); |
| check_propagatedReturnType(code, typeProvider.dynamicType, typeProvider.intType); |
| } |
| void test_query() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "import 'dart:html';", |
| "", |
| "main() {", |
| " var v1 = query('a');", |
| " var v2 = query('A');", |
| " var v3 = query('body:active');", |
| " var v4 = query('button[foo=\"bar\"]');", |
| " var v5 = query('div.class');", |
| " var v6 = query('input#id');", |
| " var v7 = query('select#id');", |
| " // invocation of method", |
| " var m1 = document.query('div');", |
| " // unsupported currently", |
| " var b1 = query('noSuchTag');", |
| " var b2 = query('DART_EDITOR_NO_SUCH_TYPE');", |
| " var b3 = query('body div');", |
| " return [v1, v2, v3, v4, v5, v6, v7, m1, b1, b2, b3];", |
| "}"])); |
| LibraryElement library = resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| CompilationUnit unit = resolveCompilationUnit(source, library); |
| FunctionDeclaration main = unit.declarations[0] as FunctionDeclaration; |
| BlockFunctionBody body = main.functionExpression.body as BlockFunctionBody; |
| ReturnStatement statement = body.block.statements[11] as ReturnStatement; |
| NodeList<Expression> elements = ((statement.expression as ListLiteral)).elements; |
| JUnitTestCase.assertEquals("AnchorElement", elements[0].propagatedType.name); |
| JUnitTestCase.assertEquals("AnchorElement", elements[1].propagatedType.name); |
| JUnitTestCase.assertEquals("BodyElement", elements[2].propagatedType.name); |
| JUnitTestCase.assertEquals("ButtonElement", elements[3].propagatedType.name); |
| JUnitTestCase.assertEquals("DivElement", elements[4].propagatedType.name); |
| JUnitTestCase.assertEquals("InputElement", elements[5].propagatedType.name); |
| JUnitTestCase.assertEquals("SelectElement", elements[6].propagatedType.name); |
| JUnitTestCase.assertEquals("DivElement", elements[7].propagatedType.name); |
| JUnitTestCase.assertEquals("Element", elements[8].propagatedType.name); |
| JUnitTestCase.assertEquals("Element", elements[9].propagatedType.name); |
| JUnitTestCase.assertEquals("Element", elements[10].propagatedType.name); |
| } |
| |
| /** |
| * @param code the code that assigns the value to the variable "v", no matter how. We check that |
| * "v" has expected static and propagated type. |
| */ |
| void check_propagatedReturnType(String code, Type2 expectedStaticType, Type2 expectedPropagatedType) { |
| Source source = addSource(code); |
| LibraryElement library = resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| CompilationUnit unit = resolveCompilationUnit(source, library); |
| SimpleIdentifier identifier = EngineTestCase.findNode(unit, code, "v = ", SimpleIdentifier); |
| JUnitTestCase.assertSame(expectedStaticType, identifier.staticType); |
| JUnitTestCase.assertSame(expectedPropagatedType, identifier.propagatedType); |
| } |
| static dartSuite() { |
| _ut.group('TypePropagationTest', () { |
| _ut.test('test_Future_then', () { |
| final __test = new TypePropagationTest(); |
| runJUnitTest(__test, __test.test_Future_then); |
| }); |
| _ut.test('test_as', () { |
| final __test = new TypePropagationTest(); |
| runJUnitTest(__test, __test.test_as); |
| }); |
| _ut.test('test_assert', () { |
| final __test = new TypePropagationTest(); |
| runJUnitTest(__test, __test.test_assert); |
| }); |
| _ut.test('test_assignment', () { |
| final __test = new TypePropagationTest(); |
| runJUnitTest(__test, __test.test_assignment); |
| }); |
| _ut.test('test_assignment_afterInitializer', () { |
| final __test = new TypePropagationTest(); |
| runJUnitTest(__test, __test.test_assignment_afterInitializer); |
| }); |
| _ut.test('test_forEach', () { |
| final __test = new TypePropagationTest(); |
| runJUnitTest(__test, __test.test_forEach); |
| }); |
| _ut.test('test_functionExpression_asInvocationArgument', () { |
| final __test = new TypePropagationTest(); |
| runJUnitTest(__test, __test.test_functionExpression_asInvocationArgument); |
| }); |
| _ut.test('test_functionExpression_asInvocationArgument_fromInferredInvocation', () { |
| final __test = new TypePropagationTest(); |
| runJUnitTest(__test, __test.test_functionExpression_asInvocationArgument_fromInferredInvocation); |
| }); |
| _ut.test('test_functionExpression_asInvocationArgument_keepIfLessSpecific', () { |
| final __test = new TypePropagationTest(); |
| runJUnitTest(__test, __test.test_functionExpression_asInvocationArgument_keepIfLessSpecific); |
| }); |
| _ut.test('test_functionExpression_asInvocationArgument_replaceIfMoreSpecific', () { |
| final __test = new TypePropagationTest(); |
| runJUnitTest(__test, __test.test_functionExpression_asInvocationArgument_replaceIfMoreSpecific); |
| }); |
| _ut.test('test_initializer', () { |
| final __test = new TypePropagationTest(); |
| runJUnitTest(__test, __test.test_initializer); |
| }); |
| _ut.test('test_initializer_dereference', () { |
| final __test = new TypePropagationTest(); |
| runJUnitTest(__test, __test.test_initializer_dereference); |
| }); |
| _ut.test('test_isNot_conditional', () { |
| final __test = new TypePropagationTest(); |
| runJUnitTest(__test, __test.test_isNot_conditional); |
| }); |
| _ut.test('test_isNot_if', () { |
| final __test = new TypePropagationTest(); |
| runJUnitTest(__test, __test.test_isNot_if); |
| }); |
| _ut.test('test_isNot_if_logicalOr', () { |
| final __test = new TypePropagationTest(); |
| runJUnitTest(__test, __test.test_isNot_if_logicalOr); |
| }); |
| _ut.test('test_isNot_postConditional', () { |
| final __test = new TypePropagationTest(); |
| runJUnitTest(__test, __test.test_isNot_postConditional); |
| }); |
| _ut.test('test_isNot_postIf', () { |
| final __test = new TypePropagationTest(); |
| runJUnitTest(__test, __test.test_isNot_postIf); |
| }); |
| _ut.test('test_is_conditional', () { |
| final __test = new TypePropagationTest(); |
| runJUnitTest(__test, __test.test_is_conditional); |
| }); |
| _ut.test('test_is_if', () { |
| final __test = new TypePropagationTest(); |
| runJUnitTest(__test, __test.test_is_if); |
| }); |
| _ut.test('test_is_if_lessSpecific', () { |
| final __test = new TypePropagationTest(); |
| runJUnitTest(__test, __test.test_is_if_lessSpecific); |
| }); |
| _ut.test('test_is_if_logicalAnd', () { |
| final __test = new TypePropagationTest(); |
| runJUnitTest(__test, __test.test_is_if_logicalAnd); |
| }); |
| _ut.test('test_is_postConditional', () { |
| final __test = new TypePropagationTest(); |
| runJUnitTest(__test, __test.test_is_postConditional); |
| }); |
| _ut.test('test_is_postIf', () { |
| final __test = new TypePropagationTest(); |
| runJUnitTest(__test, __test.test_is_postIf); |
| }); |
| _ut.test('test_is_subclass', () { |
| final __test = new TypePropagationTest(); |
| runJUnitTest(__test, __test.test_is_subclass); |
| }); |
| _ut.test('test_is_while', () { |
| final __test = new TypePropagationTest(); |
| runJUnitTest(__test, __test.test_is_while); |
| }); |
| _ut.test('test_listLiteral_different', () { |
| final __test = new TypePropagationTest(); |
| runJUnitTest(__test, __test.test_listLiteral_different); |
| }); |
| _ut.test('test_listLiteral_same', () { |
| final __test = new TypePropagationTest(); |
| runJUnitTest(__test, __test.test_listLiteral_same); |
| }); |
| _ut.test('test_mapLiteral_different', () { |
| final __test = new TypePropagationTest(); |
| runJUnitTest(__test, __test.test_mapLiteral_different); |
| }); |
| _ut.test('test_mapLiteral_same', () { |
| final __test = new TypePropagationTest(); |
| runJUnitTest(__test, __test.test_mapLiteral_same); |
| }); |
| _ut.test('test_propagatedReturnType_function_hasReturnType_returnsNull', () { |
| final __test = new TypePropagationTest(); |
| runJUnitTest(__test, __test.test_propagatedReturnType_function_hasReturnType_returnsNull); |
| }); |
| _ut.test('test_propagatedReturnType_function_lessSpecificStaticReturnType', () { |
| final __test = new TypePropagationTest(); |
| runJUnitTest(__test, __test.test_propagatedReturnType_function_lessSpecificStaticReturnType); |
| }); |
| _ut.test('test_propagatedReturnType_function_moreSpecificStaticReturnType', () { |
| final __test = new TypePropagationTest(); |
| runJUnitTest(__test, __test.test_propagatedReturnType_function_moreSpecificStaticReturnType); |
| }); |
| _ut.test('test_propagatedReturnType_function_noReturnTypeName_blockBody_multipleReturns', () { |
| final __test = new TypePropagationTest(); |
| runJUnitTest(__test, __test.test_propagatedReturnType_function_noReturnTypeName_blockBody_multipleReturns); |
| }); |
| _ut.test('test_propagatedReturnType_function_noReturnTypeName_blockBody_oneReturn', () { |
| final __test = new TypePropagationTest(); |
| runJUnitTest(__test, __test.test_propagatedReturnType_function_noReturnTypeName_blockBody_oneReturn); |
| }); |
| _ut.test('test_propagatedReturnType_function_noReturnTypeName_expressionBody', () { |
| final __test = new TypePropagationTest(); |
| runJUnitTest(__test, __test.test_propagatedReturnType_function_noReturnTypeName_expressionBody); |
| }); |
| _ut.test('test_propagatedReturnType_localFunction', () { |
| final __test = new TypePropagationTest(); |
| runJUnitTest(__test, __test.test_propagatedReturnType_localFunction); |
| }); |
| _ut.test('test_query', () { |
| final __test = new TypePropagationTest(); |
| runJUnitTest(__test, __test.test_query); |
| }); |
| }); |
| } |
| } |
| class NonErrorResolverTest extends ResolverTestCase { |
| void test_ambiguousExport() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "library L;", |
| "export 'lib1.dart';", |
| "export 'lib2.dart';"])); |
| addSource2("/lib1.dart", EngineTestCase.createSource(["library lib1;", "class M {}"])); |
| addSource2("/lib2.dart", EngineTestCase.createSource(["library lib2;", "class N {}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_ambiguousExport_combinators_hide() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "library L;", |
| "export 'lib1.dart';", |
| "export 'lib2.dart' hide B;"])); |
| addSource2("/lib1.dart", EngineTestCase.createSource(["library L1;", "class A {}", "class B {}"])); |
| addSource2("/lib2.dart", EngineTestCase.createSource(["library L2;", "class B {}", "class C {}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_ambiguousExport_combinators_show() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "library L;", |
| "export 'lib1.dart';", |
| "export 'lib2.dart' show C;"])); |
| addSource2("/lib1.dart", EngineTestCase.createSource(["library L1;", "class A {}", "class B {}"])); |
| addSource2("/lib2.dart", EngineTestCase.createSource(["library L2;", "class B {}", "class C {}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_argumentDefinitionTestNonParameter_formalParameter() { |
| Source source = addSource(EngineTestCase.createSource(["f(var v) {", " return ?v;", "}"])); |
| resolve(source); |
| assertErrors(source, [ParserErrorCode.DEPRECATED_ARGUMENT_DEFINITION_TEST]); |
| verify([source]); |
| } |
| void test_argumentDefinitionTestNonParameter_namedParameter() { |
| Source source = addSource(EngineTestCase.createSource(["f({var v : 0}) {", " return ?v;", "}"])); |
| resolve(source); |
| assertErrors(source, [ParserErrorCode.DEPRECATED_ARGUMENT_DEFINITION_TEST]); |
| verify([source]); |
| } |
| void test_argumentDefinitionTestNonParameter_optionalParameter() { |
| Source source = addSource(EngineTestCase.createSource(["f([var v]) {", " return ?v;", "}"])); |
| resolve(source); |
| assertErrors(source, [ParserErrorCode.DEPRECATED_ARGUMENT_DEFINITION_TEST]); |
| verify([source]); |
| } |
| void test_argumentTypeNotAssignable_classWithCall_Function() { |
| Source source = addSource(EngineTestCase.createSource([ |
| " caller(Function callee) {", |
| " callee();", |
| " }", |
| "", |
| " class CallMeBack {", |
| " call() => 0;", |
| " }", |
| "", |
| " main() {", |
| " caller(new CallMeBack());", |
| " }"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_argumentTypeNotAssignable_invocation_functionParameter_generic() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A<K> {", |
| " m(f(K k), K v) {", |
| " f(v);", |
| " }", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_argumentTypeNotAssignable_invocation_typedef_generic() { |
| Source source = addSource(EngineTestCase.createSource(["typedef A<T>(T p);", "f(A<int> a) {", " a(1);", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_argumentTypeNotAssignable_Object_Function() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "main() {", |
| " process(() {});", |
| "}", |
| "process(Object x) {}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_argumentTypeNotAssignable_typedef_local() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "typedef A(int p1, String p2);", |
| "A getA() => null;", |
| "f() {", |
| " A a = getA();", |
| " a(1, '2');", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_argumentTypeNotAssignable_typedef_parameter() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "typedef A(int p1, String p2);", |
| "f(A a) {", |
| " a(1, '2');", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_assignmentToFinal_prefixNegate() { |
| Source source = addSource(EngineTestCase.createSource(["f() {", " final x = 0;", " -x;", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_assignmentToFinals_importWithPrefix() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "library lib;", |
| "import 'lib1.dart' as foo;", |
| "main() {", |
| " foo.x = true;", |
| "}"])); |
| addSource2("/lib1.dart", EngineTestCase.createSource(["library lib1;", "bool x = false;"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_breakWithoutLabelInSwitch() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " void m(int i) {", |
| " switch (i) {", |
| " case 0:", |
| " break;", |
| " }", |
| " }", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_builtInIdentifierAsType_dynamic() { |
| Source source = addSource(EngineTestCase.createSource(["f() {", " dynamic x;", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_caseBlockNotTerminated() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "f(int p) {", |
| " for (int i = 0; i < 10; i++) {", |
| " switch (p) {", |
| " case 0:", |
| " break;", |
| " case 1:", |
| " continue;", |
| " case 2:", |
| " return;", |
| " case 3:", |
| " throw new Object();", |
| " case 4:", |
| " case 5:", |
| " return;", |
| " case 6:", |
| " default:", |
| " return;", |
| " }", |
| " }", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_caseBlockNotTerminated_lastCase() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "f(int p) {", |
| " switch (p) {", |
| " case 0:", |
| " p = p + 1;", |
| " }", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_caseExpressionTypeImplementsEquals_int() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "f(int i) {", |
| " switch(i) {", |
| " case(1) : return 1;", |
| " default: return 0;", |
| " }", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_caseExpressionTypeImplementsEquals_Object() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class IntWrapper {", |
| " final int value;", |
| " const IntWrapper(this.value);", |
| "}", |
| "", |
| "f(IntWrapper intWrapper) {", |
| " switch(intWrapper) {", |
| " case(const IntWrapper(1)) : return 1;", |
| " default: return 0;", |
| " }", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_caseExpressionTypeImplementsEquals_String() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "f(String s) {", |
| " switch(s) {", |
| " case('1') : return 1;", |
| " default: return 0;", |
| " }", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_concreteClassWithAbstractMember() { |
| Source source = addSource(EngineTestCase.createSource(["abstract class A {", " m();", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_conflictingInstanceGetterAndSuperclassMember_instance() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " get v => 0;", |
| "}", |
| "class B extends A {", |
| " get v => 1;", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_conflictingStaticGetterAndInstanceSetter_thisClass() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " static get x => 0;", |
| " static set x(int p) {}", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_conflictingStaticSetterAndInstanceMember_thisClass_method() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " static x() {}", |
| " static set x(int p) {}", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_constConstructorWithNonConstSuper_redirectingFactory() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " A();", |
| "}", |
| "class B implements C {", |
| " const B();", |
| "}", |
| "class C extends A {", |
| " const factory C() = B;", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_constConstructorWithNonFinalField_finalInstanceVar() { |
| Source source = addSource(EngineTestCase.createSource(["class A {", " final int x = 0;", " const A();", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_constConstructorWithNonFinalField_mixin() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " a() {}", |
| "}", |
| "class B extends Object with A {", |
| " const B();", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_constConstructorWithNonFinalField_static() { |
| Source source = addSource(EngineTestCase.createSource(["class A {", " static int x;", " const A();", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_constConstructorWithNonFinalField_syntheticField() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " const A();", |
| " set x(value) {}", |
| " get x {return 0;}", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_constEval_propertyExtraction_fieldStatic_targetType() { |
| addSource2("/math.dart", EngineTestCase.createSource(["library math;", "const PI = 3.14;"])); |
| Source source = addSource(EngineTestCase.createSource(["import 'math.dart' as math;", "const C = math.PI;"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_constEval_propertyExtraction_methodStatic_targetType() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " const A();", |
| " static m() {}", |
| "}", |
| "const C = A.m;"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_constEvalTypeBoolNumString_equal() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " const A();", |
| "}", |
| "class B {", |
| " final v;", |
| " const B.a1(bool p) : v = p == true;", |
| " const B.a2(bool p) : v = p == false;", |
| " const B.a3(bool p) : v = p == 0;", |
| " const B.a4(bool p) : v = p == 0.0;", |
| " const B.a5(bool p) : v = p == '';", |
| " const B.b1(int p) : v = p == true;", |
| " const B.b2(int p) : v = p == false;", |
| " const B.b3(int p) : v = p == 0;", |
| " const B.b4(int p) : v = p == 0.0;", |
| " const B.b5(int p) : v = p == '';", |
| " const B.c1(String p) : v = p == true;", |
| " const B.c2(String p) : v = p == false;", |
| " const B.c3(String p) : v = p == 0;", |
| " const B.c4(String p) : v = p == 0.0;", |
| " const B.c5(String p) : v = p == '';", |
| " const B.n1(num p) : v = p == null;", |
| " const B.n2(num p) : v = null == p;", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_constEvalTypeBoolNumString_notEqual() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " const A();", |
| "}", |
| "class B {", |
| " final v;", |
| " const B.a1(bool p) : v = p != true;", |
| " const B.a2(bool p) : v = p != false;", |
| " const B.a3(bool p) : v = p != 0;", |
| " const B.a4(bool p) : v = p != 0.0;", |
| " const B.a5(bool p) : v = p != '';", |
| " const B.b1(int p) : v = p != true;", |
| " const B.b2(int p) : v = p != false;", |
| " const B.b3(int p) : v = p != 0;", |
| " const B.b4(int p) : v = p != 0.0;", |
| " const B.b5(int p) : v = p != '';", |
| " const B.c1(String p) : v = p != true;", |
| " const B.c2(String p) : v = p != false;", |
| " const B.c3(String p) : v = p != 0;", |
| " const B.c4(String p) : v = p != 0.0;", |
| " const B.c5(String p) : v = p != '';", |
| " const B.n1(num p) : v = p != null;", |
| " const B.n2(num p) : v = null != p;", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_constNotInitialized_field() { |
| Source source = addSource(EngineTestCase.createSource(["class A {", " static const int x = 0;", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_constNotInitialized_local() { |
| Source source = addSource(EngineTestCase.createSource(["main() {", " const int x = 0;", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_constWithNonConstantArgument_literals() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " const A(a, b, c, d);", |
| "}", |
| "f() { return const A(true, 0, 1.0, '2'); }"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_constWithTypeParameters_direct() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A<T> {", |
| " static const V = const A<int>();", |
| " const A();", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_constWithUndefinedConstructor() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " const A.name();", |
| "}", |
| "f() {", |
| " return const A.name();", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_constWithUndefinedConstructorDefault() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " const A();", |
| "}", |
| "f() {", |
| " return const A();", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_defaultValueInFunctionTypeAlias() { |
| Source source = addSource(EngineTestCase.createSource(["typedef F([x]);"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_defaultValueInFunctionTypedParameter_named() { |
| Source source = addSource(EngineTestCase.createSource(["f(g({p})) {}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_defaultValueInFunctionTypedParameter_optional() { |
| Source source = addSource(EngineTestCase.createSource(["f(g([p])) {}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_duplicateDefinition_emptyName() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "Map _globalMap = {", |
| " 'a' : () {},", |
| " 'b' : () {}", |
| "};"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_duplicateDefinition_getter() { |
| Source source = addSource(EngineTestCase.createSource(["bool get a => true;"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_dynamicIdentifier() { |
| Source source = addSource(EngineTestCase.createSource(["main() {", " var v = dynamic;", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_exportOfNonLibrary_libraryDeclared() { |
| Source source = addSource(EngineTestCase.createSource(["library L;", "export 'lib1.dart';"])); |
| addSource2("/lib1.dart", EngineTestCase.createSource(["library lib1;"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_exportOfNonLibrary_libraryNotDeclared() { |
| Source source = addSource(EngineTestCase.createSource(["library L;", "export 'lib1.dart';"])); |
| addSource2("/lib1.dart", EngineTestCase.createSource([""])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_extraPositionalArguments_function() { |
| Source source = addSource(EngineTestCase.createSource(["f(p1, p2) {}", "main() {", " f(1, 2);", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_extraPositionalArguments_Function() { |
| Source source = addSource(EngineTestCase.createSource(["f(Function a) {", " a(1, 2);", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_extraPositionalArguments_typedef_local() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "typedef A(p1, p2);", |
| "A getA() => null;", |
| "f() {", |
| " A a = getA();", |
| " a(1, 2);", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_extraPositionalArguments_typedef_parameter() { |
| Source source = addSource(EngineTestCase.createSource(["typedef A(p1, p2);", "f(A a) {", " a(1, 2);", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_fieldInitializedByMultipleInitializers() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " int x;", |
| " int y;", |
| " A() : x = 0, y = 0 {}", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_fieldInitializedInInitializerAndDeclaration_fieldNotFinal() { |
| Source source = addSource(EngineTestCase.createSource(["class A {", " int x = 0;", " A() : x = 1 {}", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_fieldInitializedInInitializerAndDeclaration_finalFieldNotSet() { |
| Source source = addSource(EngineTestCase.createSource(["class A {", " final int x;", " A() : x = 1 {}", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_fieldInitializerOutsideConstructor() { |
| Source source = addSource(EngineTestCase.createSource(["class A {", " int x;", " A(this.x) {}", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_fieldInitializerOutsideConstructor_defaultParameters() { |
| Source source = addSource(EngineTestCase.createSource(["class A {", " int x;", " A([this.x]) {}", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_fieldInitializerRedirectingConstructor_super() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " A() {}", |
| "}", |
| "class B extends A {", |
| " int x;", |
| " B(this.x) : super();", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_finalInitializedInDeclarationAndConstructor_initializer() { |
| Source source = addSource(EngineTestCase.createSource(["class A {", " final x;", " A() : x = 1 {}", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_finalInitializedInDeclarationAndConstructor_initializingFormal() { |
| Source source = addSource(EngineTestCase.createSource(["class A {", " final x;", " A(this.x) {}", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_finalNotInitialized_atDeclaration() { |
| Source source = addSource(EngineTestCase.createSource(["class A {", " final int x = 0;", " A() {}", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_finalNotInitialized_fieldFormal() { |
| Source source = addSource(EngineTestCase.createSource(["class A {", " final int x = 0;", " A() {}", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_finalNotInitialized_functionTypedFieldFormal() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " final Function x;", |
| " A(int this.x(int p)) {}", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_finalNotInitialized_hasNativeClause_hasConstructor() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A native 'something' {", |
| " final int x;", |
| " A() {}", |
| "}"])); |
| resolve(source); |
| assertErrors(source, [ParserErrorCode.NATIVE_CLAUSE_IN_NON_SDK_CODE]); |
| verify([source]); |
| } |
| void test_finalNotInitialized_hasNativeClause_noConstructor() { |
| Source source = addSource(EngineTestCase.createSource(["class A native 'something' {", " final int x;", "}"])); |
| resolve(source); |
| assertErrors(source, [ParserErrorCode.NATIVE_CLAUSE_IN_NON_SDK_CODE]); |
| verify([source]); |
| } |
| void test_finalNotInitialized_initializer() { |
| Source source = addSource(EngineTestCase.createSource(["class A {", " final int x;", " A() : x = 0 {}", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_finalNotInitialized_redirectingConstructor() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " final int x;", |
| " A(this.x);", |
| " A.named() : this (42);", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_implicitThisReferenceInInitializer_constructorName() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " A.named() {}", |
| "}", |
| "class B {", |
| " var v;", |
| " B() : v = new A.named();", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_implicitThisReferenceInInitializer_prefixedIdentifier() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " var f;", |
| "}", |
| "class B {", |
| " var v;", |
| " B(A a) : v = a.f;", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_implicitThisReferenceInInitializer_qualifiedMethodInvocation() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " f() {}", |
| "}", |
| "class B {", |
| " var v;", |
| " B() : v = new A().f();", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_implicitThisReferenceInInitializer_qualifiedPropertyAccess() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " var f;", |
| "}", |
| "class B {", |
| " var v;", |
| " B() : v = new A().f;", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_implicitThisReferenceInInitializer_staticField_thisClass() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " var v;", |
| " A() : v = f;", |
| " static var f;", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_implicitThisReferenceInInitializer_staticGetter() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " var v;", |
| " A() : v = f;", |
| " static get f => 42;", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_implicitThisReferenceInInitializer_staticMethod() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " var v;", |
| " A() : v = f();", |
| " static f() => 42;", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_implicitThisReferenceInInitializer_topLevelField() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " var v;", |
| " A() : v = f;", |
| "}", |
| "var f = 42;"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_implicitThisReferenceInInitializer_topLevelFunction() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " var v;", |
| " A() : v = f();", |
| "}", |
| "f() => 42;"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_implicitThisReferenceInInitializer_topLevelGetter() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " var v;", |
| " A() : v = f;", |
| "}", |
| "get f => 42;"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_implicitThisReferenceInInitializer_typeParameter() { |
| Source source = addSource(EngineTestCase.createSource(["class A<T> {", " var v;", " A(p) : v = (p is T);", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_importDuplicatedLibraryName() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "library test;", |
| "import 'lib.dart';", |
| "import 'lib.dart';"])); |
| addSource2("/lib.dart", "library lib;"); |
| resolve(source); |
| assertErrors(source, [ |
| HintCode.UNUSED_IMPORT, |
| HintCode.UNUSED_IMPORT, |
| HintCode.DUPLICATE_IMPORT]); |
| verify([source]); |
| } |
| void test_importOfNonLibrary_libraryDeclared() { |
| Source source = addSource(EngineTestCase.createSource(["library lib;", "import 'part.dart';", "A a;"])); |
| addSource2("/part.dart", EngineTestCase.createSource(["library lib1;", "class A {}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_importOfNonLibrary_libraryNotDeclared() { |
| Source source = addSource(EngineTestCase.createSource(["library lib;", "import 'part.dart';", "A a;"])); |
| addSource2("/part.dart", EngineTestCase.createSource(["class A {}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_inconsistentCaseExpressionTypes() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "f(var p) {", |
| " switch (p) {", |
| " case 1:", |
| " break;", |
| " case 2:", |
| " break;", |
| " }", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_inconsistentMethodInheritance_accessors_typeParameter2() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "abstract class A<E> {", |
| " E get x {return 1;}", |
| "}", |
| "class B<E> {", |
| " E get x {return 1;}", |
| "}", |
| "class C<E> extends A<E> implements B<E> {", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_inconsistentMethodInheritance_accessors_typeParameters_diamond() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "abstract class F<E> extends B<E> {}", |
| "class D<E> extends F<E> {", |
| " external E get g;", |
| "}", |
| "abstract class C<E> {", |
| " E get g;", |
| "}", |
| "abstract class B<E> implements C<E> {", |
| " E get g { return null; }", |
| "}", |
| "class A<E> extends B<E> implements D<E> {", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_inconsistentMethodInheritance_accessors_typeParameters1() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "abstract class A<E> {", |
| " E get x;", |
| "}", |
| "abstract class B<E> {", |
| " E get x;", |
| "}", |
| "class C<E> implements A<E>, B<E> {", |
| " E get x => 1;", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_inconsistentMethodInheritance_methods_typeParameter2() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A<E> {", |
| " x(E e) {}", |
| "}", |
| "class B<E> {", |
| " x(E e) {}", |
| "}", |
| "class C<E> extends A<E> implements B<E> {", |
| " x(E e) {}", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_inconsistentMethodInheritance_methods_typeParameters1() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A<E> {", |
| " x(E e) {}", |
| "}", |
| "class B<E> {", |
| " x(E e) {}", |
| "}", |
| "class C<E> implements A<E>, B<E> {", |
| " x(E e) {}", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_inconsistentMethodInheritance_simple() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "abstract class A {", |
| " x();", |
| "}", |
| "abstract class B {", |
| " x();", |
| "}", |
| "class C implements A, B {", |
| " x() {}", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_initializingFormalForNonExistantField() { |
| Source source = addSource(EngineTestCase.createSource(["class A {", " int x;", " A(this.x) {}", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_instanceAccessToStaticMember_fromComment() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " static m() {}", |
| "}", |
| "/// [A.m]", |
| "main() {", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_instanceAccessToStaticMember_topLevel() { |
| Source source = addSource(EngineTestCase.createSource(["m() {}", "main() {", " m();", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_instanceMemberAccessFromStatic_fromComment() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " m() {}", |
| " /// [m]", |
| " static foo() {", |
| " }", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_invalidAnnotation_constantVariable() { |
| Source source = addSource(EngineTestCase.createSource(["const C = 0;", "@C", "main() {", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_invalidAnnotation_importWithPrefix_constantVariable() { |
| addSource2("/lib.dart", EngineTestCase.createSource(["library lib;", "const C = 0;"])); |
| Source source = addSource(EngineTestCase.createSource(["import 'lib.dart' as p;", "@p.C", "main() {", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_invalidAnnotation_importWithPrefix_constConstructor() { |
| addSource2("/lib.dart", EngineTestCase.createSource([ |
| "library lib;", |
| "class A {", |
| " const A.named(int p);", |
| "}"])); |
| Source source = addSource(EngineTestCase.createSource([ |
| "import 'lib.dart' as p;", |
| "@p.A.named(42)", |
| "main() {", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_invalidAssignment() { |
| Source source = addSource(EngineTestCase.createSource(["f() {", " var x;", " var y;", " x = y;", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_invalidAssignment_compoundAssignment() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class byte {", |
| " int _value;", |
| " byte(this._value);", |
| " byte operator +(int val) {}", |
| "}", |
| "", |
| "void main() {", |
| " byte b = new byte(52);", |
| " b += 3;", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_invalidAssignment_defaultValue_named() { |
| Source source = addSource(EngineTestCase.createSource(["f({String x: '0'}) {", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_invalidAssignment_defaultValue_optional() { |
| Source source = addSource(EngineTestCase.createSource(["f([String x = '0']) {", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_invalidAssignment_toDynamic() { |
| Source source = addSource(EngineTestCase.createSource(["f() {", " var g;", " g = () => 0;", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_invalidFactoryNameNotAClass() { |
| Source source = addSource(EngineTestCase.createSource(["class A {", " factory A() {}", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_invalidMethodOverrideNamedParamType() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " m({int a}) {}", |
| "}", |
| "class B implements A {", |
| " m({int a, int b}) {}", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_invalidOverrideDifferentDefaultValues_named() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " m({int p : 0}) {}", |
| "}", |
| "class B extends A {", |
| " m({int p : 0}) {}", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_invalidOverrideDifferentDefaultValues_positional() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " m([int p = 0]) {}", |
| "}", |
| "class B extends A {", |
| " m([int p = 0]) {}", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_invalidOverrideDifferentDefaultValues_positional_changedOrder() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " m([int a = 0, String b = '0']) {}", |
| "}", |
| "class B extends A {", |
| " m([int b = 0, String a = '0']) {}", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_invalidOverrideNamed_unorderedNamedParameter() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " m({a, b}) {}", |
| "}", |
| "class B extends A {", |
| " m({b, a}) {}", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_invalidOverrideRequired_less() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " m(a, b) {}", |
| "}", |
| "class B extends A {", |
| " m(a) {}", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_invalidOverrideRequired_same() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " m(a) {}", |
| "}", |
| "class B extends A {", |
| " m(a) {}", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_invalidOverrideReturnType_returnType_interface() { |
| Source source = addSource2("/test.dart", EngineTestCase.createSource([ |
| "abstract class A {", |
| " num m();", |
| "}", |
| "class B implements A {", |
| " int m() { return 1; }", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_invalidOverrideReturnType_returnType_interface2() { |
| Source source = addSource2("/test.dart", EngineTestCase.createSource([ |
| "abstract class A {", |
| " num m();", |
| "}", |
| "abstract class B implements A {", |
| "}", |
| "class C implements B {", |
| " int m() { return 1; }", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_invalidOverrideReturnType_returnType_mixin() { |
| Source source = addSource2("/test.dart", EngineTestCase.createSource([ |
| "class A {", |
| " num m() { return 0; }", |
| "}", |
| "class B extends Object with A {", |
| " int m() { return 1; }", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_invalidOverrideReturnType_returnType_parameterizedTypes() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "abstract class A<E> {", |
| " List<E> m();", |
| "}", |
| "class B extends A<dynamic> {", |
| " List<dynamic> m() { return new List<dynamic>(); }", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_invalidOverrideReturnType_returnType_sameType() { |
| Source source = addSource2("/test.dart", EngineTestCase.createSource([ |
| "class A {", |
| " int m() { return 0; }", |
| "}", |
| "class B extends A {", |
| " int m() { return 1; }", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_invalidOverrideReturnType_returnType_superclass() { |
| Source source = addSource2("/test.dart", EngineTestCase.createSource([ |
| "class A {", |
| " num m() { return 0; }", |
| "}", |
| "class B extends A {", |
| " int m() { return 1; }", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_invalidOverrideReturnType_returnType_superclass2() { |
| Source source = addSource2("/test.dart", EngineTestCase.createSource([ |
| "class A {", |
| " num m() { return 0; }", |
| "}", |
| "class B extends A {", |
| "}", |
| "class C extends B {", |
| " int m() { return 1; }", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_invalidOverrideReturnType_returnType_void() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " void m() {}", |
| "}", |
| "class B extends A {", |
| " int m() {}", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_invalidReferenceToThis_constructor() { |
| Source source = addSource(EngineTestCase.createSource(["class A {", " A() {", " var v = this;", " }", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_invalidReferenceToThis_instanceMethod() { |
| Source source = addSource(EngineTestCase.createSource(["class A {", " m() {", " var v = this;", " }", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_invalidTypeArgumentForKey() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " m() {", |
| " return const <int, int>{};", |
| " }", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_invalidTypeArgumentInConstList() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A<E> {", |
| " m() {", |
| " return <E>[];", |
| " }", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_invalidTypeArgumentInConstMap() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A<E> {", |
| " m() {", |
| " return <String, E>{};", |
| " }", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_invocationOfNonFunction_dynamic() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " var f;", |
| "}", |
| "class B extends A {", |
| " g() {", |
| " f();", |
| " }", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_invocationOfNonFunction_getter() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " var g;", |
| "}", |
| "f() {", |
| " A a;", |
| " a.g();", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_invocationOfNonFunction_localVariable() { |
| Source source = addSource(EngineTestCase.createSource(["f() {", " var g;", " g();", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_invocationOfNonFunction_localVariable_dynamic() { |
| Source source = addSource(EngineTestCase.createSource(["f() {}", "main() {", " var v = f;", " v();", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_invocationOfNonFunction_localVariable_dynamic2() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "f() {}", |
| "main() {", |
| " var v = f;", |
| " v = 1;", |
| " v();", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_invocationOfNonFunction_Object() { |
| Source source = addSource(EngineTestCase.createSource(["main() {", " Object v = null;", " v();", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_listElementTypeNotAssignable() { |
| Source source = addSource(EngineTestCase.createSource(["var v1 = <int> [42];", "var v2 = const <int> [42];"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_mapKeyTypeNotAssignable() { |
| Source source = addSource(EngineTestCase.createSource(["var v = <String, int > {'a' : 1};"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_memberWithClassName_setter() { |
| Source source = addSource(EngineTestCase.createSource(["class A {", " set A(v) {}", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_misMatchedGetterAndSetterTypes_instance_sameTypes() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class C {", |
| " int get x => 0;", |
| " set x(int v) {}", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_misMatchedGetterAndSetterTypes_instance_unspecifiedGetter() { |
| Source source = addSource(EngineTestCase.createSource(["class C {", " get x => 0;", " set x(String v) {}", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_misMatchedGetterAndSetterTypes_instance_unspecifiedSetter() { |
| Source source = addSource(EngineTestCase.createSource(["class C {", " int get x => 0;", " set x(v) {}", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_misMatchedGetterAndSetterTypes_topLevel_sameTypes() { |
| Source source = addSource(EngineTestCase.createSource(["int get x => 0;", "set x(int v) {}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_misMatchedGetterAndSetterTypes_topLevel_unspecifiedGetter() { |
| Source source = addSource(EngineTestCase.createSource(["get x => 0;", "set x(String v) {}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_misMatchedGetterAndSetterTypes_topLevel_unspecifiedSetter() { |
| Source source = addSource(EngineTestCase.createSource(["int get x => 0;", "set x(v) {}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_mixinDeclaresConstructor() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " m() {}", |
| "}", |
| "class B extends Object with A {}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_mixinDeclaresConstructor_factory() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " factory A() {}", |
| "}", |
| "class B extends Object with A {}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_mixinInheritsFromNotObject_classDeclaration_mixTypedef() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {}", |
| "typedef B = Object with A;", |
| "class C extends Object with B {}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_mixinInheritsFromNotObject_typedef_mixTypedef() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {}", |
| "typedef B = Object with A;", |
| "typedef C = Object with B;"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_multipleSuperInitializers_no() { |
| Source source = addSource(EngineTestCase.createSource(["class A {}", "class B extends A {", " B() {}", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_multipleSuperInitializers_single() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {}", |
| "class B extends A {", |
| " B() : super() {}", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_newWithAbstractClass_factory() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "abstract class A {", |
| " factory A() { return new B(); }", |
| "}", |
| "class B implements A {", |
| " B() {}", |
| "}", |
| "A f() {", |
| " return new A();", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_newWithUndefinedConstructor() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " A.name() {}", |
| "}", |
| "f() {", |
| " new A.name();", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_newWithUndefinedConstructorDefault() { |
| Source source = addSource(EngineTestCase.createSource(["class A {", " A() {}", "}", "f() {", " new A();", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_nonAbstractClassInheritsAbstractMemberOne_abstractOverridesConcrete_accessor() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " int get g => 0;", |
| "}", |
| "abstract class B extends A {", |
| " int get g;", |
| "}", |
| "class C extends B {", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_nonAbstractClassInheritsAbstractMemberOne_abstractOverridesConcrete_method() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " m(p) {}", |
| "}", |
| "abstract class B extends A {", |
| " m(p);", |
| "}", |
| "class C extends B {", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_nonBoolExpression_functionType() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "bool makeAssertion() => true;", |
| "f() {", |
| " assert(makeAssertion);", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_nonBoolExpression_interfaceType() { |
| Source source = addSource(EngineTestCase.createSource(["f() {", " assert(true);", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_nonConstantDefaultValue_function_named() { |
| Source source = addSource(EngineTestCase.createSource(["f({x : 2 + 3}) {}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_nonConstantDefaultValue_function_positional() { |
| Source source = addSource(EngineTestCase.createSource(["f([x = 2 + 3]) {}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_nonConstantDefaultValue_inConstructor_named() { |
| Source source = addSource(EngineTestCase.createSource(["class A {", " A({x : 2 + 3}) {}", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_nonConstantDefaultValue_inConstructor_positional() { |
| Source source = addSource(EngineTestCase.createSource(["class A {", " A([x = 2 + 3]) {}", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_nonConstantDefaultValue_method_named() { |
| Source source = addSource(EngineTestCase.createSource(["class A {", " m({x : 2 + 3}) {}", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_nonConstantDefaultValue_method_positional() { |
| Source source = addSource(EngineTestCase.createSource(["class A {", " m([x = 2 + 3]) {}", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_nonConstantValueInInitializer_namedArgument() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " final a;", |
| " const A({this.a});", |
| "}", |
| "class B extends A {", |
| " const B({b}) : super(a: b);", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_nonConstCaseExpression() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "f(Type t) {", |
| " switch (t) {", |
| " case bool:", |
| " case int:", |
| " return true;", |
| " default:", |
| " return false;", |
| " }", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_nonConstMapAsExpressionStatement_const() { |
| Source source = addSource(EngineTestCase.createSource(["f() {", " const {'a' : 0, 'b' : 1};", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_nonConstMapAsExpressionStatement_notExpressionStatement() { |
| Source source = addSource(EngineTestCase.createSource(["f() {", " var m = {'a' : 0, 'b' : 1};", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_nonConstMapAsExpressionStatement_typeArguments() { |
| Source source = addSource(EngineTestCase.createSource(["f() {", " <String, int> {'a' : 0, 'b' : 1};", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_nonConstValueInInitializer_binary_bool() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " final v;", |
| " const A.a1(bool p) : v = p && true;", |
| " const A.a2(bool p) : v = true && p;", |
| " const A.b1(bool p) : v = p || true;", |
| " const A.b2(bool p) : v = true || p;", |
| "}"])); |
| resolve(source); |
| assertErrors(source, [HintCode.DEAD_CODE]); |
| verify([source]); |
| } |
| void test_nonConstValueInInitializer_binary_dynamic() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " final v;", |
| " const A.a1(p) : v = p + 5;", |
| " const A.a2(p) : v = 5 + p;", |
| " const A.b1(p) : v = p - 5;", |
| " const A.b2(p) : v = 5 - p;", |
| " const A.c1(p) : v = p * 5;", |
| " const A.c2(p) : v = 5 * p;", |
| " const A.d1(p) : v = p / 5;", |
| " const A.d2(p) : v = 5 / p;", |
| " const A.e1(p) : v = p ~/ 5;", |
| " const A.e2(p) : v = 5 ~/ p;", |
| " const A.f1(p) : v = p > 5;", |
| " const A.f2(p) : v = 5 > p;", |
| " const A.g1(p) : v = p < 5;", |
| " const A.g2(p) : v = 5 < p;", |
| " const A.h1(p) : v = p >= 5;", |
| " const A.h2(p) : v = 5 >= p;", |
| " const A.i1(p) : v = p <= 5;", |
| " const A.i2(p) : v = 5 <= p;", |
| " const A.j1(p) : v = p % 5;", |
| " const A.j2(p) : v = 5 % p;", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| } |
| void test_nonConstValueInInitializer_binary_int() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " final v;", |
| " const A.a1(int p) : v = p ^ 5;", |
| " const A.a2(int p) : v = 5 ^ p;", |
| " const A.b1(int p) : v = p & 5;", |
| " const A.b2(int p) : v = 5 & p;", |
| " const A.c1(int p) : v = p | 5;", |
| " const A.c2(int p) : v = 5 | p;", |
| " const A.d1(int p) : v = p >> 5;", |
| " const A.d2(int p) : v = 5 >> p;", |
| " const A.e1(int p) : v = p << 5;", |
| " const A.e2(int p) : v = 5 << p;", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_nonConstValueInInitializer_binary_num() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " final v;", |
| " const A.a1(num p) : v = p + 5;", |
| " const A.a2(num p) : v = 5 + p;", |
| " const A.b1(num p) : v = p - 5;", |
| " const A.b2(num p) : v = 5 - p;", |
| " const A.c1(num p) : v = p * 5;", |
| " const A.c2(num p) : v = 5 * p;", |
| " const A.d1(num p) : v = p / 5;", |
| " const A.d2(num p) : v = 5 / p;", |
| " const A.e1(num p) : v = p ~/ 5;", |
| " const A.e2(num p) : v = 5 ~/ p;", |
| " const A.f1(num p) : v = p > 5;", |
| " const A.f2(num p) : v = 5 > p;", |
| " const A.g1(num p) : v = p < 5;", |
| " const A.g2(num p) : v = 5 < p;", |
| " const A.h1(num p) : v = p >= 5;", |
| " const A.h2(num p) : v = 5 >= p;", |
| " const A.i1(num p) : v = p <= 5;", |
| " const A.i2(num p) : v = 5 <= p;", |
| " const A.j1(num p) : v = p % 5;", |
| " const A.j2(num p) : v = 5 % p;", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_nonConstValueInInitializer_field() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " final int a;", |
| " const A() : a = 5;", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_nonConstValueInInitializer_redirecting() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " const A.named(p);", |
| " const A() : this.named(42);", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_nonConstValueInInitializer_super() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " const A(p);", |
| "}", |
| "class B extends A {", |
| " const B() : super(42);", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_nonConstValueInInitializer_unary() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " final v;", |
| " const A.a(bool p) : v = !p;", |
| " const A.b(int p) : v = ~p;", |
| " const A.c(num p) : v = -p;", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_nonGenerativeConstructor() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " A.named() {}", |
| " factory A() {}", |
| "}", |
| "class B extends A {", |
| " B() : super.named();", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_nonTypeInCatchClause_isClass() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "f() {", |
| " try {", |
| " } on String catch (e) {", |
| " }", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_nonTypeInCatchClause_isFunctionTypeAlias() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "typedef F();", |
| "f() {", |
| " try {", |
| " } on F catch (e) {", |
| " }", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_nonTypeInCatchClause_isTypeParameter() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A<T> {", |
| " f() {", |
| " try {", |
| " } on T catch (e) {", |
| " }", |
| " }", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_nonTypeInCatchClause_noType() { |
| Source source = addSource(EngineTestCase.createSource(["f() {", " try {", " } catch (e) {", " }", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_nonVoidReturnForOperator_no() { |
| Source source = addSource(EngineTestCase.createSource(["class A {", " operator []=(a, b) {}", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_nonVoidReturnForOperator_void() { |
| Source source = addSource(EngineTestCase.createSource(["class A {", " void operator []=(a, b) {}", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_nonVoidReturnForSetter_function_no() { |
| Source source = addSource("set x(v) {}"); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_nonVoidReturnForSetter_function_void() { |
| Source source = addSource("void set x(v) {}"); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_nonVoidReturnForSetter_method_no() { |
| Source source = addSource(EngineTestCase.createSource(["class A {", " set x(v) {}", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_nonVoidReturnForSetter_method_void() { |
| Source source = addSource(EngineTestCase.createSource(["class A {", " void set x(v) {}", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_optionalParameterInOperator_required() { |
| Source source = addSource(EngineTestCase.createSource(["class A {", " operator +(p) {}", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_prefixCollidesWithTopLevelMembers() { |
| addSource2("/lib.dart", EngineTestCase.createSource(["library lib;", "class A {}"])); |
| Source source = addSource(EngineTestCase.createSource([ |
| "import 'lib.dart' as p;", |
| "typedef P();", |
| "p2() {}", |
| "var p3;", |
| "class p4 {}", |
| "p.A a;"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_proxy_annotation_prefixed() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "library L;", |
| "import 'meta.dart';", |
| "@proxy", |
| "class A {}", |
| "f(A a) {", |
| " a.m();", |
| " var x = a.g;", |
| " a.s = 1;", |
| " var y = a + a;", |
| " a++;", |
| " ++a;", |
| "}"])); |
| addSource2("/meta.dart", EngineTestCase.createSource([ |
| "library meta;", |
| "const proxy = const _Proxy();", |
| "class _Proxy { const _Proxy(); }"])); |
| resolve(source); |
| assertNoErrors(source); |
| } |
| void test_proxy_annotation_prefixed2() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "library L;", |
| "import 'meta.dart';", |
| "@proxy", |
| "class A {}", |
| "class B {", |
| " f(A a) {", |
| " a.m();", |
| " var x = a.g;", |
| " a.s = 1;", |
| " var y = a + a;", |
| " a++;", |
| " ++a;", |
| " }", |
| "}"])); |
| addSource2("/meta.dart", EngineTestCase.createSource([ |
| "library meta;", |
| "const proxy = const _Proxy();", |
| "class _Proxy { const _Proxy(); }"])); |
| resolve(source); |
| assertNoErrors(source); |
| } |
| void test_proxy_annotation_prefixed3() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "library L;", |
| "import 'meta.dart';", |
| "class B {", |
| " f(A a) {", |
| " a.m();", |
| " var x = a.g;", |
| " a.s = 1;", |
| " var y = a + a;", |
| " a++;", |
| " ++a;", |
| " }", |
| "}", |
| "@proxy", |
| "class A {}"])); |
| addSource2("/meta.dart", EngineTestCase.createSource([ |
| "library meta;", |
| "const proxy = const _Proxy();", |
| "class _Proxy { const _Proxy(); }"])); |
| resolve(source); |
| assertNoErrors(source); |
| } |
| void test_proxy_annotation_simple() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "library L;", |
| "import 'meta.dart';", |
| "@proxy", |
| "class B {", |
| " m() {", |
| " n();", |
| " var x = g;", |
| " s = 1;", |
| " var y = this + this;", |
| " }", |
| "}"])); |
| addSource2("/meta.dart", EngineTestCase.createSource([ |
| "library meta;", |
| "const proxy = const _Proxy();", |
| "class _Proxy { const _Proxy(); }"])); |
| resolve(source); |
| assertNoErrors(source); |
| } |
| void test_recursiveConstructorRedirect() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " A.a() : this.b();", |
| " A.b() : this.c();", |
| " A.c() {}", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_recursiveFactoryRedirect() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " factory A() = B;", |
| "}", |
| "class B implements A {", |
| " factory B() = C;", |
| "}", |
| "class C implements B {", |
| " factory C() {}", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_redirectToInvalidFunctionType() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A implements B {", |
| " A(int p) {}", |
| "}", |
| "class B {", |
| " factory B(int p) = A;", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_redirectToNonConstConstructor() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " const A.a();", |
| " const factory A.b() = A.a;", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_referenceToDeclaredVariableInInitializer_constructorName() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " A.x() {}", |
| "}", |
| "f() {", |
| " var x = new A.x();", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_referenceToDeclaredVariableInInitializer_methodName() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " x() {}", |
| "}", |
| "f(A a) {", |
| " var x = a.x();", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_referenceToDeclaredVariableInInitializer_propertyName() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " var x;", |
| "}", |
| "f(A a) {", |
| " var x = a.x;", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_rethrowOutsideCatch() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class A {", |
| " void m() {", |
| " try {} catch (e) {rethrow;}", |
| " }", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_returnInGenerativeConstructor() { |
| Source source = addSource(EngineTestCase.createSource(["class A {", " A() { return; }", "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_returnOfInvalidType_dynamic() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class TypeError {}", |
| "class A {", |
| " static void testLogicalOp() {", |
| " testOr(a, b, onTypeError) {", |
| " try {", |
| " return a || b;", |
| " } on TypeError catch (t) {", |
| " return onTypeError;", |
| " }", |
| " }", |
| " }", |
| "}"])); |
| resolve(source); |
| assertNoErrors(source); |
| verify([source]); |
| } |
| void test_returnOfInvalidType_dynamicAsTypeArgument() { |
| Source source = addSource(EngineTestCase.createSource([ |
| "class I<T> {", |
| " factory I() => new A<T>();", |
| "}", |
| "class A<T> implements I {", |
| "}"])); |
| |