blob: 130f6f0384e7df43f58161c68c98f51aaef376d0 [file] [log] [blame]
// 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 'dart:collection';
import 'package:analyzer_experimental/src/generated/java_core.dart';
import 'package:analyzer_experimental/src/generated/java_engine.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' hide Annotation;
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 test_as() {
Source source = addSource("/test.dart", 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();
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 body2 = function.functionExpression.body as BlockFunctionBody;
IfStatement ifStatement = body2.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.staticType);
}
void test_assert() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "A f(var p) {", " assert (p is A);", " return p;", "}"]));
LibraryElement library = resolve(source, []);
assertNoErrors();
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 body2 = function.functionExpression.body as BlockFunctionBody;
ReturnStatement statement = body2.block.statements[1] as ReturnStatement;
SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
JUnitTestCase.assertSame(typeA, variableName.staticType);
}
void test_assignment() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {", " var v;", " v = 0;", " return v;", "}"]));
LibraryElement library = resolve(source, []);
assertNoErrors();
verify([source]);
CompilationUnit unit = resolveCompilationUnit(source, library);
FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
BlockFunctionBody body2 = function.functionExpression.body as BlockFunctionBody;
ReturnStatement statement = body2.block.statements[2] as ReturnStatement;
SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
JUnitTestCase.assertSame(typeProvider.intType, variableName.staticType);
}
void test_assignment_afterInitializer() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {", " var v = 0;", " v = 1.0;", " return v;", "}"]));
LibraryElement library = resolve(source, []);
assertNoErrors();
verify([source]);
CompilationUnit unit = resolveCompilationUnit(source, library);
FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
BlockFunctionBody body2 = function.functionExpression.body as BlockFunctionBody;
ReturnStatement statement = body2.block.statements[2] as ReturnStatement;
SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
JUnitTestCase.assertSame(typeProvider.doubleType, variableName.staticType);
}
void test_initializer() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {", " var v = 0;", " return v;", "}"]));
LibraryElement library = resolve(source, []);
assertNoErrors();
verify([source]);
CompilationUnit unit = resolveCompilationUnit(source, library);
FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
BlockFunctionBody body2 = function.functionExpression.body as BlockFunctionBody;
ReturnStatement statement = body2.block.statements[1] as ReturnStatement;
SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
JUnitTestCase.assertSame(typeProvider.intType, variableName.staticType);
}
void test_is_conditional() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "A f(var p) {", " return (p is A) ? p : null;", "}"]));
LibraryElement library = resolve(source, []);
assertNoErrors();
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 body2 = function.functionExpression.body as BlockFunctionBody;
ReturnStatement statement = body2.block.statements[0] as ReturnStatement;
ConditionalExpression conditional = statement.expression as ConditionalExpression;
SimpleIdentifier variableName = conditional.thenExpression as SimpleIdentifier;
JUnitTestCase.assertSame(typeA, variableName.staticType);
}
void test_is_if() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "A f(var p) {", " if (p is A) {", " return p;", " } else {", " return null;", " }", "}"]));
LibraryElement library = resolve(source, []);
assertNoErrors();
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 body2 = function.functionExpression.body as BlockFunctionBody;
IfStatement ifStatement = body2.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.staticType);
}
void test_is_if_logicalAnd() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "A f(var p) {", " if (p is A && p != null) {", " return p;", " } else {", " return null;", " }", "}"]));
LibraryElement library = resolve(source, []);
assertNoErrors();
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 body2 = function.functionExpression.body as BlockFunctionBody;
IfStatement ifStatement = body2.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.staticType);
}
void test_is_postConditional() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "A f(var p) {", " A a = (p is A) ? p : throw null;", " return p;", "}"]));
LibraryElement library = resolve(source, []);
assertNoErrors();
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 body2 = function.functionExpression.body as BlockFunctionBody;
ReturnStatement statement = body2.block.statements[1] as ReturnStatement;
SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
JUnitTestCase.assertSame(typeA, variableName.staticType);
}
void test_is_postIf() {
Source source = addSource("/test.dart", 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();
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 body2 = function.functionExpression.body as BlockFunctionBody;
ReturnStatement statement = body2.block.statements[1] as ReturnStatement;
SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
JUnitTestCase.assertSame(typeA, variableName.staticType);
}
void test_is_subclass() {
Source source = addSource("/test.dart", 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, []);
assertNoErrors();
verify([source]);
CompilationUnit unit = resolveCompilationUnit(source, library);
FunctionDeclaration function = unit.declarations[2] as FunctionDeclaration;
BlockFunctionBody body2 = function.functionExpression.body as BlockFunctionBody;
IfStatement ifStatement = body2.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.element);
}
void test_isNot_conditional() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "A f(var p) {", " return (p is! A) ? null : p;", "}"]));
LibraryElement library = resolve(source, []);
assertNoErrors();
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 body2 = function.functionExpression.body as BlockFunctionBody;
ReturnStatement statement = body2.block.statements[0] as ReturnStatement;
ConditionalExpression conditional = statement.expression as ConditionalExpression;
SimpleIdentifier variableName = conditional.elseExpression as SimpleIdentifier;
JUnitTestCase.assertSame(typeA, variableName.staticType);
}
void test_isNot_if() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "A f(var p) {", " if (p is! A) {", " return null;", " } else {", " return p;", " }", "}"]));
LibraryElement library = resolve(source, []);
assertNoErrors();
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 body2 = function.functionExpression.body as BlockFunctionBody;
IfStatement ifStatement = body2.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.staticType);
}
void test_isNot_if_logicalOr() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "A f(var p) {", " if (p is! A || null == p) {", " return null;", " } else {", " return p;", " }", "}"]));
LibraryElement library = resolve(source, []);
assertNoErrors();
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 body2 = function.functionExpression.body as BlockFunctionBody;
IfStatement ifStatement = body2.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.staticType);
}
void test_isNot_postConditional() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "A f(var p) {", " A a = (p is! A) ? throw null : p;", " return p;", "}"]));
LibraryElement library = resolve(source, []);
assertNoErrors();
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 body2 = function.functionExpression.body as BlockFunctionBody;
ReturnStatement statement = body2.block.statements[1] as ReturnStatement;
SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
JUnitTestCase.assertSame(typeA, variableName.staticType);
}
void test_isNot_postIf() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "A f(var p) {", " if (p is! A) {", " return null;", " }", " return p;", "}"]));
LibraryElement library = resolve(source, []);
assertNoErrors();
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 body2 = function.functionExpression.body as BlockFunctionBody;
ReturnStatement statement = body2.block.statements[1] as ReturnStatement;
SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
JUnitTestCase.assertSame(typeA, variableName.staticType);
}
void test_query() {
Source source = addSource("/test.dart", 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();
verify([source]);
CompilationUnit unit = resolveCompilationUnit(source, library);
FunctionDeclaration main = unit.declarations[0] as FunctionDeclaration;
BlockFunctionBody body2 = main.functionExpression.body as BlockFunctionBody;
ReturnStatement statement = body2.block.statements[11] as ReturnStatement;
NodeList<Expression> elements2 = ((statement.expression as ListLiteral)).elements;
JUnitTestCase.assertEquals("AnchorElement", elements2[0].staticType.name);
JUnitTestCase.assertEquals("AnchorElement", elements2[1].staticType.name);
JUnitTestCase.assertEquals("BodyElement", elements2[2].staticType.name);
JUnitTestCase.assertEquals("ButtonElement", elements2[3].staticType.name);
JUnitTestCase.assertEquals("DivElement", elements2[4].staticType.name);
JUnitTestCase.assertEquals("InputElement", elements2[5].staticType.name);
JUnitTestCase.assertEquals("SelectElement", elements2[6].staticType.name);
JUnitTestCase.assertEquals("DivElement", elements2[7].staticType.name);
JUnitTestCase.assertEquals("Element", elements2[8].staticType.name);
JUnitTestCase.assertEquals("Element", elements2[9].staticType.name);
JUnitTestCase.assertEquals("Element", elements2[10].staticType.name);
}
static dartSuite() {
_ut.group('TypePropagationTest', () {
_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_initializer', () {
final __test = new TypePropagationTest();
runJUnitTest(__test, __test.test_initializer);
});
_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_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_query', () {
final __test = new TypePropagationTest();
runJUnitTest(__test, __test.test_query);
});
});
}
}
class NonErrorResolverTest extends ResolverTestCase {
void test_argumentDefinitionTestNonParameter_formalParameter() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["f(var v) {", " return ?v;", "}"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_argumentDefinitionTestNonParameter_namedParameter() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["f({var v : 0}) {", " return ?v;", "}"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_argumentDefinitionTestNonParameter_optionalParameter() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["f([var v]) {", " return ?v;", "}"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_breakWithoutLabelInSwitch() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " void m(int i) {", " switch (i) {", " case 0:", " break;", " }", " }", "}"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_builtInIdentifierAsType_dynamic() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {", " dynamic x;", "}"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_caseExpressionTypeImplementsEquals_int() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["f(int i) {", " switch(i) {", " case(1) : return 1;", " default: return 0;", " }", "}"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_caseExpressionTypeImplementsEquals_Object() {
Source source = addSource("/test.dart", 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();
verify([source]);
}
void test_caseExpressionTypeImplementsEquals_String() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["f(String s) {", " switch(s) {", " case('1') : return 1;", " default: return 0;", " }", "}"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_constConstructorWithNonFinalField_constInstanceVar() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " const int x = 0;", " const A() {}", "}"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_constConstructorWithNonFinalField_finalInstanceVar() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " final int x = 0;", " const A() {}", "}"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_constConstructorWithNonFinalField_static() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " static int x;", " const A() {}", "}"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_constConstructorWithNonFinalField_syntheticField() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " const A();", " set x(value) {}", " get x {return 0;}", "}"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_defaultValueInFunctionTypeAlias() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["typedef F([x]);"]));
resolve(source, []);
assertErrors([]);
verify([source]);
}
void test_duplicateDefinition_emptyName() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["Map _globalMap = {", " 'a' : () {},", " 'b' : () {}", "}"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_duplicateDefinition_getter() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["bool get a => true;"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_exportOfNonLibrary_libraryDeclared() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["library L;", "export 'lib1.dart';"]));
addSource("/lib1.dart", EngineTestCase.createSource(["library lib1;"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_exportOfNonLibrary_libraryNotDeclared() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["library L;", "export 'lib1.dart';"]));
addSource("/lib1.dart", EngineTestCase.createSource([""]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_fieldInitializedByMultipleInitializers() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " int x;", " int y;", " A() : x = 0, y = 0 {}", "}"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_fieldInitializedInInitializerAndDeclaration_fieldNotFinal() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " int x = 0;", " A() : x = 1 {}", "}"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_fieldInitializedInInitializerAndDeclaration_finalFieldNotSet() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " final int x;", " A() : x = 1 {}", "}"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_fieldInitializerOutsideConstructor() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " int x;", " A(this.x) {}", "}"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_fieldInitializerOutsideConstructor_defaultParameters() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " int x;", " A([this.x]) {}", "}"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_finalInitializedInDeclarationAndConstructor_initializer() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " final x;", " A() : x = 1 {}", "}"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_finalInitializedInDeclarationAndConstructor_initializingFormal() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " final x;", " A(this.x) {}", "}"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_finalNotInitialized_atDeclaration() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " final int x = 0;", " A() {}", "}"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_finalNotInitialized_fieldFormal() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " final int x = 0;", " A() {}", "}"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_finalNotInitialized_initializer() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " final int x;", " A() : x = 0 {}", "}"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_importOfNonLibrary_libraryDeclared() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["library lib;", "import 'part.dart';"]));
addSource("/part.dart", EngineTestCase.createSource(["library lib1;"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_importOfNonLibrary_libraryNotDeclared() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["library lib;", "import 'part.dart';"]));
addSource("/part.dart", EngineTestCase.createSource([""]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_inconsistentCaseExpressionTypes() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["f(var p) {", " switch (p) {", " case 1:", " break;", " case 2:", " break;", " }", "}"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_initializingFormalForNonExistantField() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " int x;", " A(this.x) {}", "}"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_invalidAssignment() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {", " var x;", " var y;", " x = y;", "}"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_invalidAssignment_toDynamic() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {", " var g;", " g = () => 0;", "}"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_invocationOfNonFunction_dynamic() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " var f;", "}", "class B extends A {", " g() {", " f();", " }", "}"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_invocationOfNonFunction_getter() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " var g;", "}", "f() {", " A a;", " a.g();", "}"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_invocationOfNonFunction_localVariable() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {", " var g;", " g();", "}"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_newWithAbstractClass_factory() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["abstract class A {", " factory A() { return new B(); }", "}", "class B implements A {", " B() {}", "}", "A f() {", " return new A();", "}"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_nonBoolExpression_assert_bool() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {", " assert(true);", "}"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_nonBoolExpression_assert_functionType() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["bool makeAssertion() => true;", "f() {", " assert(makeAssertion);", "}"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_rethrowOutsideCatch() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " void m() {", " try {} catch (e) {rethrow;}", " }", "}"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_returnOfInvalidType_dynamic() {
Source source = addSource("/test.dart", 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();
verify([source]);
}
void test_returnOfInvalidType_subtype() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "class B extends A {}", "A f(B b) { return b; }"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_returnOfInvalidType_supertype() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "class B extends A {}", "B f(A a) { return a; }"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_typeArgumentNotMatchingBounds_const() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "class B extends A {}", "class G<E extends A> {", " const G() {}", "}", "f() { return const G<B>(); }"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_typeArgumentNotMatchingBounds_new() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "class B extends A {}", "class G<E extends A> {}", "f() { return new G<B>(); }"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_undefinedGetter_typeSubstitution() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A<E> {", " E element;", "}", "class B extends A<List> {", " m() {", " element.last;", " }", "}"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_undefinedIdentifier_hide() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["library L;", "export 'lib1.dart' hide a;"]));
addSource("/lib1.dart", EngineTestCase.createSource(["library lib1;"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_undefinedIdentifier_show() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["library L;", "export 'lib1.dart' show a;"]));
addSource("/lib1.dart", EngineTestCase.createSource(["library lib1;"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
void test_undefinedOperator_tilde() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["const A = 3;", "const B = ~((1 << A) - 1);"]));
resolve(source, []);
assertNoErrors();
verify([source]);
}
static dartSuite() {
_ut.group('NonErrorResolverTest', () {
_ut.test('test_argumentDefinitionTestNonParameter_formalParameter', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_argumentDefinitionTestNonParameter_formalParameter);
});
_ut.test('test_argumentDefinitionTestNonParameter_namedParameter', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_argumentDefinitionTestNonParameter_namedParameter);
});
_ut.test('test_argumentDefinitionTestNonParameter_optionalParameter', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_argumentDefinitionTestNonParameter_optionalParameter);
});
_ut.test('test_breakWithoutLabelInSwitch', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_breakWithoutLabelInSwitch);
});
_ut.test('test_builtInIdentifierAsType_dynamic', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_builtInIdentifierAsType_dynamic);
});
_ut.test('test_caseExpressionTypeImplementsEquals_Object', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_caseExpressionTypeImplementsEquals_Object);
});
_ut.test('test_caseExpressionTypeImplementsEquals_String', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_caseExpressionTypeImplementsEquals_String);
});
_ut.test('test_caseExpressionTypeImplementsEquals_int', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_caseExpressionTypeImplementsEquals_int);
});
_ut.test('test_constConstructorWithNonFinalField_constInstanceVar', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_constConstructorWithNonFinalField_constInstanceVar);
});
_ut.test('test_constConstructorWithNonFinalField_finalInstanceVar', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_constConstructorWithNonFinalField_finalInstanceVar);
});
_ut.test('test_constConstructorWithNonFinalField_static', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_constConstructorWithNonFinalField_static);
});
_ut.test('test_constConstructorWithNonFinalField_syntheticField', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_constConstructorWithNonFinalField_syntheticField);
});
_ut.test('test_defaultValueInFunctionTypeAlias', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_defaultValueInFunctionTypeAlias);
});
_ut.test('test_duplicateDefinition_emptyName', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_duplicateDefinition_emptyName);
});
_ut.test('test_duplicateDefinition_getter', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_duplicateDefinition_getter);
});
_ut.test('test_exportOfNonLibrary_libraryDeclared', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_exportOfNonLibrary_libraryDeclared);
});
_ut.test('test_exportOfNonLibrary_libraryNotDeclared', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_exportOfNonLibrary_libraryNotDeclared);
});
_ut.test('test_fieldInitializedByMultipleInitializers', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_fieldInitializedByMultipleInitializers);
});
_ut.test('test_fieldInitializedInInitializerAndDeclaration_fieldNotFinal', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_fieldInitializedInInitializerAndDeclaration_fieldNotFinal);
});
_ut.test('test_fieldInitializedInInitializerAndDeclaration_finalFieldNotSet', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_fieldInitializedInInitializerAndDeclaration_finalFieldNotSet);
});
_ut.test('test_fieldInitializerOutsideConstructor', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_fieldInitializerOutsideConstructor);
});
_ut.test('test_fieldInitializerOutsideConstructor_defaultParameters', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_fieldInitializerOutsideConstructor_defaultParameters);
});
_ut.test('test_finalInitializedInDeclarationAndConstructor_initializer', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_finalInitializedInDeclarationAndConstructor_initializer);
});
_ut.test('test_finalInitializedInDeclarationAndConstructor_initializingFormal', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_finalInitializedInDeclarationAndConstructor_initializingFormal);
});
_ut.test('test_finalNotInitialized_atDeclaration', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_finalNotInitialized_atDeclaration);
});
_ut.test('test_finalNotInitialized_fieldFormal', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_finalNotInitialized_fieldFormal);
});
_ut.test('test_finalNotInitialized_initializer', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_finalNotInitialized_initializer);
});
_ut.test('test_importOfNonLibrary_libraryDeclared', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_importOfNonLibrary_libraryDeclared);
});
_ut.test('test_importOfNonLibrary_libraryNotDeclared', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_importOfNonLibrary_libraryNotDeclared);
});
_ut.test('test_inconsistentCaseExpressionTypes', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_inconsistentCaseExpressionTypes);
});
_ut.test('test_initializingFormalForNonExistantField', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_initializingFormalForNonExistantField);
});
_ut.test('test_invalidAssignment', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_invalidAssignment);
});
_ut.test('test_invalidAssignment_toDynamic', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_invalidAssignment_toDynamic);
});
_ut.test('test_invocationOfNonFunction_dynamic', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_invocationOfNonFunction_dynamic);
});
_ut.test('test_invocationOfNonFunction_getter', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_invocationOfNonFunction_getter);
});
_ut.test('test_invocationOfNonFunction_localVariable', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_invocationOfNonFunction_localVariable);
});
_ut.test('test_newWithAbstractClass_factory', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_newWithAbstractClass_factory);
});
_ut.test('test_nonBoolExpression_assert_bool', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_nonBoolExpression_assert_bool);
});
_ut.test('test_nonBoolExpression_assert_functionType', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_nonBoolExpression_assert_functionType);
});
_ut.test('test_rethrowOutsideCatch', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_rethrowOutsideCatch);
});
_ut.test('test_returnOfInvalidType_dynamic', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_returnOfInvalidType_dynamic);
});
_ut.test('test_returnOfInvalidType_subtype', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_returnOfInvalidType_subtype);
});
_ut.test('test_returnOfInvalidType_supertype', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_returnOfInvalidType_supertype);
});
_ut.test('test_typeArgumentNotMatchingBounds_const', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_typeArgumentNotMatchingBounds_const);
});
_ut.test('test_typeArgumentNotMatchingBounds_new', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_typeArgumentNotMatchingBounds_new);
});
_ut.test('test_undefinedGetter_typeSubstitution', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_undefinedGetter_typeSubstitution);
});
_ut.test('test_undefinedIdentifier_hide', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_undefinedIdentifier_hide);
});
_ut.test('test_undefinedIdentifier_show', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_undefinedIdentifier_show);
});
_ut.test('test_undefinedOperator_tilde', () {
final __test = new NonErrorResolverTest();
runJUnitTest(__test, __test.test_undefinedOperator_tilde);
});
});
}
}
class LibraryTest extends EngineTestCase {
/**
* The error listener to which all errors will be reported.
*/
GatheringErrorListener _errorListener;
/**
* The source factory used to create libraries.
*/
SourceFactory _sourceFactory;
/**
* The analysis context to pass in to all libraries created by the tests.
*/
AnalysisContextImpl _analysisContext;
/**
* The library used by the tests.
*/
Library _library5;
void setUp() {
_sourceFactory = new SourceFactory.con2([new FileUriResolver()]);
_analysisContext = new AnalysisContextImpl();
_analysisContext.sourceFactory = _sourceFactory;
_errorListener = new GatheringErrorListener();
_library5 = library("/lib.dart");
}
void test_addExport() {
Library exportLibrary = library("/exported.dart");
_library5.addExport(ASTFactory.exportDirective2("exported.dart", []), exportLibrary);
List<Library> exports2 = _library5.exports;
EngineTestCase.assertLength(1, exports2);
JUnitTestCase.assertSame(exportLibrary, exports2[0]);
_errorListener.assertNoErrors();
}
void test_addImport() {
Library importLibrary = library("/imported.dart");
_library5.addImport(ASTFactory.importDirective2("imported.dart", null, []), importLibrary);
List<Library> imports2 = _library5.imports;
EngineTestCase.assertLength(1, imports2);
JUnitTestCase.assertSame(importLibrary, imports2[0]);
_errorListener.assertNoErrors();
}
void test_getExplicitlyImportsCore() {
JUnitTestCase.assertFalse(_library5.explicitlyImportsCore);
_errorListener.assertNoErrors();
}
void test_getExport() {
ExportDirective directive = ASTFactory.exportDirective2("exported.dart", []);
Library exportLibrary = library("/exported.dart");
_library5.addExport(directive, exportLibrary);
JUnitTestCase.assertSame(exportLibrary, _library5.getExport(directive));
_errorListener.assertNoErrors();
}
void test_getExports() {
EngineTestCase.assertLength(0, _library5.exports);
_errorListener.assertNoErrors();
}
void test_getImport() {
ImportDirective directive = ASTFactory.importDirective2("imported.dart", null, []);
Library importLibrary = library("/imported.dart");
_library5.addImport(directive, importLibrary);
JUnitTestCase.assertSame(importLibrary, _library5.getImport(directive));
_errorListener.assertNoErrors();
}
void test_getImports() {
EngineTestCase.assertLength(0, _library5.imports);
_errorListener.assertNoErrors();
}
void test_getImportsAndExports() {
_library5.addImport(ASTFactory.importDirective2("imported.dart", null, []), library("/imported.dart"));
_library5.addExport(ASTFactory.exportDirective2("exported.dart", []), library("/exported.dart"));
EngineTestCase.assertLength(2, _library5.importsAndExports);
_errorListener.assertNoErrors();
}
void test_getLibraryScope() {
LibraryElementImpl element = new LibraryElementImpl(_analysisContext, ASTFactory.libraryIdentifier2(["lib"]));
element.definingCompilationUnit = new CompilationUnitElementImpl("lib.dart");
_library5.libraryElement = element;
JUnitTestCase.assertNotNull(_library5.libraryScope);
_errorListener.assertNoErrors();
}
void test_getLibrarySource() {
JUnitTestCase.assertNotNull(_library5.librarySource);
}
void test_setExplicitlyImportsCore() {
_library5.explicitlyImportsCore = true;
JUnitTestCase.assertTrue(_library5.explicitlyImportsCore);
_errorListener.assertNoErrors();
}
void test_setLibraryElement() {
LibraryElementImpl element = new LibraryElementImpl(_analysisContext, ASTFactory.libraryIdentifier2(["lib"]));
_library5.libraryElement = element;
JUnitTestCase.assertSame(element, _library5.libraryElement);
}
Library library(String definingCompilationUnitPath) => new Library(_analysisContext, _errorListener, new FileBasedSource.con1(_sourceFactory.contentCache, FileUtilities2.createFile(definingCompilationUnitPath)));
static dartSuite() {
_ut.group('LibraryTest', () {
_ut.test('test_addExport', () {
final __test = new LibraryTest();
runJUnitTest(__test, __test.test_addExport);
});
_ut.test('test_addImport', () {
final __test = new LibraryTest();
runJUnitTest(__test, __test.test_addImport);
});
_ut.test('test_getExplicitlyImportsCore', () {
final __test = new LibraryTest();
runJUnitTest(__test, __test.test_getExplicitlyImportsCore);
});
_ut.test('test_getExport', () {
final __test = new LibraryTest();
runJUnitTest(__test, __test.test_getExport);
});
_ut.test('test_getExports', () {
final __test = new LibraryTest();
runJUnitTest(__test, __test.test_getExports);
});
_ut.test('test_getImport', () {
final __test = new LibraryTest();
runJUnitTest(__test, __test.test_getImport);
});
_ut.test('test_getImports', () {
final __test = new LibraryTest();
runJUnitTest(__test, __test.test_getImports);
});
_ut.test('test_getImportsAndExports', () {
final __test = new LibraryTest();
runJUnitTest(__test, __test.test_getImportsAndExports);
});
_ut.test('test_getLibraryScope', () {
final __test = new LibraryTest();
runJUnitTest(__test, __test.test_getLibraryScope);
});
_ut.test('test_getLibrarySource', () {
final __test = new LibraryTest();
runJUnitTest(__test, __test.test_getLibrarySource);
});
_ut.test('test_setExplicitlyImportsCore', () {
final __test = new LibraryTest();
runJUnitTest(__test, __test.test_setExplicitlyImportsCore);
});
_ut.test('test_setLibraryElement', () {
final __test = new LibraryTest();
runJUnitTest(__test, __test.test_setLibraryElement);
});
});
}
}
class StaticTypeWarningCodeTest extends ResolverTestCase {
void fail_inaccessibleSetter() {
Source source = addSource("/test.dart", EngineTestCase.createSource([]));
resolve(source, []);
assertErrors([StaticTypeWarningCode.INACCESSIBLE_SETTER]);
verify([source]);
}
void fail_inconsistentMethodInheritance() {
Source source = addSource("/test.dart", EngineTestCase.createSource([]));
resolve(source, []);
assertErrors([StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE]);
verify([source]);
}
void fail_nonTypeAsTypeArgument() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["int A;", "class B<E> {}", "f(B<A> b) {}"]));
resolve(source, []);
assertErrors([StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT]);
verify([source]);
}
void fail_redirectWithInvalidTypeParameters() {
Source source = addSource("/test.dart", EngineTestCase.createSource([]));
resolve(source, []);
assertErrors([StaticTypeWarningCode.REDIRECT_WITH_INVALID_TYPE_PARAMETERS]);
verify([source]);
}
void fail_typeArgumentViolatesBounds() {
Source source = addSource("/test.dart", EngineTestCase.createSource([]));
resolve(source, []);
assertErrors([StaticTypeWarningCode.TYPE_ARGUMENT_VIOLATES_BOUNDS]);
verify([source]);
}
void test_invalidAssignment_instanceVariable() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " int x;", "}", "f() {", " A a;", " a.x = '0';", "}"]));
resolve(source, []);
assertErrors([StaticTypeWarningCode.INVALID_ASSIGNMENT]);
verify([source]);
}
void test_invalidAssignment_localVariable() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {", " int x;", " x = '0';", "}"]));
resolve(source, []);
assertErrors([StaticTypeWarningCode.INVALID_ASSIGNMENT]);
verify([source]);
}
void test_invalidAssignment_staticVariable() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " static int x;", "}", "f() {", " A.x = '0';", "}"]));
resolve(source, []);
assertErrors([StaticTypeWarningCode.INVALID_ASSIGNMENT]);
verify([source]);
}
void test_invocationOfNonFunction_class() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " void m() {", " A();", " }", "}"]));
resolve(source, []);
assertErrors([StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION]);
}
void test_invocationOfNonFunction_localVariable() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {", " int x;", " return x();", "}"]));
resolve(source, []);
assertErrors([StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION]);
verify([source]);
}
void test_invocationOfNonFunction_ordinaryInvocation() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " int x;", "}", "class B {", " m() {", " A.x();", " }", "}"]));
resolve(source, []);
assertErrors([StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION]);
}
void test_invocationOfNonFunction_staticInvocation() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " static int get g => 0;", " f() {", " A.g();", " }", "}"]));
resolve(source, []);
assertErrors([StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION]);
}
void test_nonBoolCondition_conditional() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["f() { return 3 ? 2 : 1; }"]));
resolve(source, []);
assertErrors([StaticTypeWarningCode.NON_BOOL_CONDITION]);
verify([source]);
}
void test_nonBoolCondition_do() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {", " do {} while (3);", "}"]));
resolve(source, []);
assertErrors([StaticTypeWarningCode.NON_BOOL_CONDITION]);
verify([source]);
}
void test_nonBoolCondition_if() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {", " if (3) return 2; else return 1;", "}"]));
resolve(source, []);
assertErrors([StaticTypeWarningCode.NON_BOOL_CONDITION]);
verify([source]);
}
void test_nonBoolCondition_while() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {", " while (3) {}", "}"]));
resolve(source, []);
assertErrors([StaticTypeWarningCode.NON_BOOL_CONDITION]);
verify([source]);
}
void test_nonBoolExpression() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {", " assert(0);", "}"]));
resolve(source, []);
assertErrors([StaticTypeWarningCode.NON_BOOL_EXPRESSION]);
verify([source]);
}
void test_returnOfInvalidType_function() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["int f() { return '0'; }"]));
resolve(source, []);
assertErrors([StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]);
verify([source]);
}
void test_returnOfInvalidType_localFunction() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " String m() {", " int f() { return '0'; }", " }", "}"]));
resolve(source, []);
assertErrors([StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]);
verify([source]);
}
void test_returnOfInvalidType_method() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " int f() { return '0'; }", "}"]));
resolve(source, []);
assertErrors([StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]);
verify([source]);
}
void test_typeArgumentNotMatchingBounds_const() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "class B {}", "class G<E extends A> {", " const G() {}", "}", "f() { return const G<B>(); }"]));
resolve(source, []);
assertErrors([StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]);
verify([source]);
}
void test_typeArgumentNotMatchingBounds_new() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "class B {}", "class G<E extends A> {}", "f() { return new G<B>(); }"]));
resolve(source, []);
assertErrors([StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]);
verify([source]);
}
void test_undefinedFunction() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["void f() {", " g();", "}"]));
resolve(source, []);
assertErrors([StaticTypeWarningCode.UNDEFINED_FUNCTION]);
}
void test_undefinedGetter() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class T {}", "f(T e) { return e.m; }"]));
resolve(source, []);
assertErrors([StaticTypeWarningCode.UNDEFINED_GETTER]);
}
void test_undefinedGetter_static() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "var a = A.B;"]));
resolve(source, []);
assertErrors([StaticTypeWarningCode.UNDEFINED_GETTER]);
}
void test_undefinedMethod() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " void m() {", " n();", " }", "}"]));
resolve(source, []);
assertErrors([StaticTypeWarningCode.UNDEFINED_METHOD]);
}
void test_undefinedSetter() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class T {}", "f(T e1) { e1.m = 0; }"]));
resolve(source, []);
assertErrors([StaticTypeWarningCode.UNDEFINED_SETTER]);
}
void test_undefinedSetter_static() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "f() { A.B = 0;}"]));
resolve(source, []);
assertErrors([StaticTypeWarningCode.UNDEFINED_SETTER]);
}
void test_undefinedSuperMethod() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "class B extends A {", " m() { return super.m(); }", "}"]));
resolve(source, []);
assertErrors([StaticTypeWarningCode.UNDEFINED_SUPER_METHOD]);
}
void test_wrongNumberOfTypeArguments_tooFew() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A<E, F> {}", "A<A> a = null;"]));
resolve(source, []);
assertErrors([StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]);
verify([source]);
}
void test_wrongNumberOfTypeArguments_tooMany() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A<E> {}", "A<A, A> a = null;"]));
resolve(source, []);
assertErrors([StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]);
verify([source]);
}
static dartSuite() {
_ut.group('StaticTypeWarningCodeTest', () {
_ut.test('test_invalidAssignment_instanceVariable', () {
final __test = new StaticTypeWarningCodeTest();
runJUnitTest(__test, __test.test_invalidAssignment_instanceVariable);
});
_ut.test('test_invalidAssignment_localVariable', () {
final __test = new StaticTypeWarningCodeTest();
runJUnitTest(__test, __test.test_invalidAssignment_localVariable);
});
_ut.test('test_invalidAssignment_staticVariable', () {
final __test = new StaticTypeWarningCodeTest();
runJUnitTest(__test, __test.test_invalidAssignment_staticVariable);
});
_ut.test('test_invocationOfNonFunction_class', () {
final __test = new StaticTypeWarningCodeTest();
runJUnitTest(__test, __test.test_invocationOfNonFunction_class);
});
_ut.test('test_invocationOfNonFunction_localVariable', () {
final __test = new StaticTypeWarningCodeTest();
runJUnitTest(__test, __test.test_invocationOfNonFunction_localVariable);
});
_ut.test('test_invocationOfNonFunction_ordinaryInvocation', () {
final __test = new StaticTypeWarningCodeTest();
runJUnitTest(__test, __test.test_invocationOfNonFunction_ordinaryInvocation);
});
_ut.test('test_invocationOfNonFunction_staticInvocation', () {
final __test = new StaticTypeWarningCodeTest();
runJUnitTest(__test, __test.test_invocationOfNonFunction_staticInvocation);
});
_ut.test('test_nonBoolCondition_conditional', () {
final __test = new StaticTypeWarningCodeTest();
runJUnitTest(__test, __test.test_nonBoolCondition_conditional);
});
_ut.test('test_nonBoolCondition_do', () {
final __test = new StaticTypeWarningCodeTest();
runJUnitTest(__test, __test.test_nonBoolCondition_do);
});
_ut.test('test_nonBoolCondition_if', () {
final __test = new StaticTypeWarningCodeTest();
runJUnitTest(__test, __test.test_nonBoolCondition_if);
});
_ut.test('test_nonBoolCondition_while', () {
final __test = new StaticTypeWarningCodeTest();
runJUnitTest(__test, __test.test_nonBoolCondition_while);
});
_ut.test('test_nonBoolExpression', () {
final __test = new StaticTypeWarningCodeTest();
runJUnitTest(__test, __test.test_nonBoolExpression);
});
_ut.test('test_returnOfInvalidType_function', () {
final __test = new StaticTypeWarningCodeTest();
runJUnitTest(__test, __test.test_returnOfInvalidType_function);
});
_ut.test('test_returnOfInvalidType_localFunction', () {
final __test = new StaticTypeWarningCodeTest();
runJUnitTest(__test, __test.test_returnOfInvalidType_localFunction);
});
_ut.test('test_returnOfInvalidType_method', () {
final __test = new StaticTypeWarningCodeTest();
runJUnitTest(__test, __test.test_returnOfInvalidType_method);
});
_ut.test('test_typeArgumentNotMatchingBounds_const', () {
final __test = new StaticTypeWarningCodeTest();
runJUnitTest(__test, __test.test_typeArgumentNotMatchingBounds_const);
});
_ut.test('test_typeArgumentNotMatchingBounds_new', () {
final __test = new StaticTypeWarningCodeTest();
runJUnitTest(__test, __test.test_typeArgumentNotMatchingBounds_new);
});
_ut.test('test_undefinedFunction', () {
final __test = new StaticTypeWarningCodeTest();
runJUnitTest(__test, __test.test_undefinedFunction);
});
_ut.test('test_undefinedGetter', () {
final __test = new StaticTypeWarningCodeTest();
runJUnitTest(__test, __test.test_undefinedGetter);
});
_ut.test('test_undefinedGetter_static', () {
final __test = new StaticTypeWarningCodeTest();
runJUnitTest(__test, __test.test_undefinedGetter_static);
});
_ut.test('test_undefinedMethod', () {
final __test = new StaticTypeWarningCodeTest();
runJUnitTest(__test, __test.test_undefinedMethod);
});
_ut.test('test_undefinedSetter', () {
final __test = new StaticTypeWarningCodeTest();
runJUnitTest(__test, __test.test_undefinedSetter);
});
_ut.test('test_undefinedSetter_static', () {
final __test = new StaticTypeWarningCodeTest();
runJUnitTest(__test, __test.test_undefinedSetter_static);
});
_ut.test('test_undefinedSuperMethod', () {
final __test = new StaticTypeWarningCodeTest();
runJUnitTest(__test, __test.test_undefinedSuperMethod);
});
_ut.test('test_wrongNumberOfTypeArguments_tooFew', () {
final __test = new StaticTypeWarningCodeTest();
runJUnitTest(__test, __test.test_wrongNumberOfTypeArguments_tooFew);
});
_ut.test('test_wrongNumberOfTypeArguments_tooMany', () {
final __test = new StaticTypeWarningCodeTest();
runJUnitTest(__test, __test.test_wrongNumberOfTypeArguments_tooMany);
});
});
}
}
class TypeResolverVisitorTest extends EngineTestCase {
/**
* The error listener to which errors will be reported.
*/
GatheringErrorListener _listener;
/**
* The object representing the information about the library in which the types are being
* resolved.
*/
Library _library;
/**
* The type provider used to access the types.
*/
TestTypeProvider _typeProvider;
/**
* The visitor used to resolve types needed to form the type hierarchy.
*/
TypeResolverVisitor _visitor;
void fail_visitConstructorDeclaration() {
JUnitTestCase.fail("Not yet tested");
_listener.assertNoErrors();
}
void fail_visitFieldFormalParameter_noType() {
FormalParameter node = ASTFactory.fieldFormalParameter(Keyword.VAR, null, "p");
JUnitTestCase.assertSame(_typeProvider.dynamicType, resolve5(node, []));
_listener.assertNoErrors();
}
void fail_visitFieldFormalParameter_type() {
FormalParameter node = ASTFactory.fieldFormalParameter(null, ASTFactory.typeName4("int", []), "p");
JUnitTestCase.assertSame(_typeProvider.intType, resolve5(node, []));
_listener.assertNoErrors();
}
void fail_visitFunctionDeclaration() {
JUnitTestCase.fail("Not yet tested");
_listener.assertNoErrors();
}
void fail_visitFunctionTypeAlias() {
JUnitTestCase.fail("Not yet tested");
_listener.assertNoErrors();
}
void fail_visitFunctionTypedFormalParameter() {
JUnitTestCase.fail("Not yet tested");
_listener.assertNoErrors();
}
void fail_visitMethodDeclaration() {
JUnitTestCase.fail("Not yet tested");
_listener.assertNoErrors();
}
void fail_visitVariableDeclaration() {
JUnitTestCase.fail("Not yet tested");
ClassElement type = ElementFactory.classElement2("A", []);
VariableDeclaration node = ASTFactory.variableDeclaration("a");
ASTFactory.variableDeclarationList(null, ASTFactory.typeName(type, []), [node]);
JUnitTestCase.assertSame(type.type, node.name.staticType);
_listener.assertNoErrors();
}
void setUp() {
_listener = new GatheringErrorListener();
SourceFactory factory = new SourceFactory.con2([new FileUriResolver()]);
AnalysisContextImpl context = new AnalysisContextImpl();
context.sourceFactory = factory;
Source librarySource = new FileBasedSource.con1(factory.contentCache, FileUtilities2.createFile("/lib.dart"));
_library = new Library(context, _listener, librarySource);
LibraryElementImpl element = new LibraryElementImpl(context, ASTFactory.libraryIdentifier2(["lib"]));
element.definingCompilationUnit = new CompilationUnitElementImpl("lib.dart");
_library.libraryElement = element;
_typeProvider = new TestTypeProvider();
_visitor = new TypeResolverVisitor.con1(_library, librarySource, _typeProvider);
}
void test_visitCatchClause_exception() {
CatchClause clause = ASTFactory.catchClause("e", []);
SimpleIdentifier exceptionParameter2 = clause.exceptionParameter;
exceptionParameter2.element = new LocalVariableElementImpl(exceptionParameter2);
resolve(clause, _typeProvider.objectType, null, []);
_listener.assertNoErrors();
}
void test_visitCatchClause_exception_stackTrace() {
CatchClause clause = ASTFactory.catchClause2("e", "s", []);
SimpleIdentifier exceptionParameter2 = clause.exceptionParameter;
exceptionParameter2.element = new LocalVariableElementImpl(exceptionParameter2);
SimpleIdentifier stackTraceParameter2 = clause.stackTraceParameter;
stackTraceParameter2.element = new LocalVariableElementImpl(stackTraceParameter2);
resolve(clause, _typeProvider.objectType, _typeProvider.stackTraceType, []);
_listener.assertNoErrors();
}
void test_visitCatchClause_on_exception() {
ClassElement exceptionElement = ElementFactory.classElement2("E", []);
TypeName exceptionType = ASTFactory.typeName(exceptionElement, []);
CatchClause clause = ASTFactory.catchClause4(exceptionType, "e", []);
SimpleIdentifier exceptionParameter2 = clause.exceptionParameter;
exceptionParameter2.element = new LocalVariableElementImpl(exceptionParameter2);
resolve(clause, exceptionElement.type, null, [exceptionElement]);
_listener.assertNoErrors();
}
void test_visitCatchClause_on_exception_stackTrace() {
ClassElement exceptionElement = ElementFactory.classElement2("E", []);
TypeName exceptionType = ASTFactory.typeName(exceptionElement, []);
((exceptionType.name as SimpleIdentifier)).element = exceptionElement;
CatchClause clause = ASTFactory.catchClause5(exceptionType, "e", "s", []);
SimpleIdentifier exceptionParameter2 = clause.exceptionParameter;
exceptionParameter2.element = new LocalVariableElementImpl(exceptionParameter2);
SimpleIdentifier stackTraceParameter2 = clause.stackTraceParameter;
stackTraceParameter2.element = new LocalVariableElementImpl(stackTraceParameter2);
resolve(clause, exceptionElement.type, _typeProvider.stackTraceType, [exceptionElement]);
_listener.assertNoErrors();
}
void test_visitClassDeclaration() {
ClassElement elementA = ElementFactory.classElement2("A", []);
ClassElement elementB = ElementFactory.classElement2("B", []);
ClassElement elementC = ElementFactory.classElement2("C", []);
ClassElement elementD = ElementFactory.classElement2("D", []);
ExtendsClause extendsClause2 = ASTFactory.extendsClause(ASTFactory.typeName(elementB, []));
WithClause withClause2 = ASTFactory.withClause([ASTFactory.typeName(elementC, [])]);
ImplementsClause implementsClause2 = ASTFactory.implementsClause([ASTFactory.typeName(elementD, [])]);
ClassDeclaration declaration = ASTFactory.classDeclaration(null, "A", null, extendsClause2, withClause2, implementsClause2, []);
declaration.name.element = elementA;
resolveNode(declaration, [elementA, elementB, elementC, elementD]);
JUnitTestCase.assertSame(elementB.type, elementA.supertype);
List<InterfaceType> mixins2 = elementA.mixins;
EngineTestCase.assertLength(1, mixins2);
JUnitTestCase.assertSame(elementC.type, mixins2[0]);
List<InterfaceType> interfaces2 = elementA.interfaces;
EngineTestCase.assertLength(1, interfaces2);
JUnitTestCase.assertSame(elementD.type, interfaces2[0]);
_listener.assertNoErrors();
}
void test_visitClassTypeAlias() {
ClassElement elementA = ElementFactory.classElement2("A", []);
ClassElement elementB = ElementFactory.classElement2("B", []);
ClassElement elementC = ElementFactory.classElement2("C", []);
ClassElement elementD = ElementFactory.classElement2("D", []);
WithClause withClause2 = ASTFactory.withClause([ASTFactory.typeName(elementC, [])]);
ImplementsClause implementsClause2 = ASTFactory.implementsClause([ASTFactory.typeName(elementD, [])]);
ClassTypeAlias alias = ASTFactory.classTypeAlias("A", null, null, ASTFactory.typeName(elementB, []), withClause2, implementsClause2);
alias.name.element = elementA;
resolveNode(alias, [elementA, elementB, elementC, elementD]);
JUnitTestCase.assertSame(elementB.type, elementA.supertype);
List<InterfaceType> mixins2 = elementA.mixins;
EngineTestCase.assertLength(1, mixins2);
JUnitTestCase.assertSame(elementC.type, mixins2[0]);
List<InterfaceType> interfaces2 = elementA.interfaces;
EngineTestCase.assertLength(1, interfaces2);
JUnitTestCase.assertSame(elementD.type, interfaces2[0]);
_listener.assertNoErrors();
}
void test_visitSimpleFormalParameter_noType() {
FormalParameter node = ASTFactory.simpleFormalParameter3("p");
node.identifier.element = new ParameterElementImpl(ASTFactory.identifier3("p"));
JUnitTestCase.assertSame(_typeProvider.dynamicType, resolve5(node, []));
_listener.assertNoErrors();
}
void test_visitSimpleFormalParameter_type() {
InterfaceType intType2 = _typeProvider.intType;
ClassElement intElement = intType2.element;
FormalParameter node = ASTFactory.simpleFormalParameter4(ASTFactory.typeName(intElement, []), "p");
SimpleIdentifier identifier2 = node.identifier;
ParameterElementImpl element = new ParameterElementImpl(identifier2);
identifier2.element = element;
JUnitTestCase.assertSame(intType2, resolve5(node, [intElement]));
_listener.assertNoErrors();
}
void test_visitTypeName_noParameters_noArguments() {
ClassElement classA = ElementFactory.classElement2("A", []);
TypeName typeName2 = ASTFactory.typeName(classA, []);
typeName2.type = null;
resolveNode(typeName2, [classA]);
JUnitTestCase.assertSame(classA.type, typeName2.type);
_listener.assertNoErrors();
}
void test_visitTypeName_parameters_arguments() {
ClassElement classA = ElementFactory.classElement2("A", ["E"]);
ClassElement classB = ElementFactory.classElement2("B", []);
TypeName typeName2 = ASTFactory.typeName(classA, [ASTFactory.typeName(classB, [])]);
typeName2.type = null;
resolveNode(typeName2, [classA, classB]);
InterfaceType resultType = typeName2.type as InterfaceType;
JUnitTestCase.assertSame(classA, resultType.element);
List<Type2> resultArguments = resultType.typeArguments;
EngineTestCase.assertLength(1, resultArguments);
JUnitTestCase.assertSame(classB.type, resultArguments[0]);
_listener.assertNoErrors();
}
void test_visitTypeName_parameters_noArguments() {
ClassElement classA = ElementFactory.classElement2("A", ["E"]);
TypeName typeName2 = ASTFactory.typeName(classA, []);
typeName2.type = null;
resolveNode(typeName2, [classA]);
InterfaceType resultType = typeName2.type as InterfaceType;
JUnitTestCase.assertSame(classA, resultType.element);
List<Type2> resultArguments = resultType.typeArguments;
EngineTestCase.assertLength(1, resultArguments);
JUnitTestCase.assertSame(DynamicTypeImpl.instance, resultArguments[0]);
_listener.assertNoErrors();
}
void test_visitTypeName_void() {
ClassElement classA = ElementFactory.classElement2("A", []);
TypeName typeName = ASTFactory.typeName4("void", []);
resolveNode(typeName, [classA]);
JUnitTestCase.assertSame(VoidTypeImpl.instance, typeName.type);
_listener.assertNoErrors();
}
/**
* Analyze the given catch clause and assert that the types of the parameters have been set to the
* given types. The types can be null if the catch clause does not have the corresponding
* parameter.
* @param node the catch clause to be analyzed
* @param exceptionType the expected type of the exception parameter
* @param stackTraceType the expected type of the stack trace parameter
* @param definedElements the elements that are to be defined in the scope in which the element is
* being resolved
*/
void resolve(CatchClause node, InterfaceType exceptionType, InterfaceType stackTraceType, List<Element> definedElements) {
resolveNode(node, definedElements);
SimpleIdentifier exceptionParameter2 = node.exceptionParameter;
if (exceptionParameter2 != null) {
JUnitTestCase.assertSame(exceptionType, exceptionParameter2.staticType);
}
SimpleIdentifier stackTraceParameter2 = node.stackTraceParameter;
if (stackTraceParameter2 != null) {
JUnitTestCase.assertSame(stackTraceType, stackTraceParameter2.staticType);
}
}
/**
* Return the type associated with the given parameter after the static type analyzer has computed
* a type for it.
* @param node the parameter with which the type is associated
* @param definedElements the elements that are to be defined in the scope in which the element is
* being resolved
* @return the type associated with the parameter
*/
Type2 resolve5(FormalParameter node, List<Element> definedElements) {
resolveNode(node, definedElements);
return ((node.identifier.element as ParameterElement)).type;
}
/**
* Return the element associated with the given identifier after the resolver has resolved the
* identifier.
* @param node the expression to be resolved
* @param definedElements the elements that are to be defined in the scope in which the element is
* being resolved
* @return the element to which the expression was resolved
*/
void resolveNode(ASTNode node, List<Element> definedElements) {
for (Element element in definedElements) {
_library.libraryScope.define(element);
}
node.accept(_visitor);
}
static dartSuite() {
_ut.group('TypeResolverVisitorTest', () {
_ut.test('test_visitCatchClause_exception', () {
final __test = new TypeResolverVisitorTest();
runJUnitTest(__test, __test.test_visitCatchClause_exception);
});
_ut.test('test_visitCatchClause_exception_stackTrace', () {
final __test = new TypeResolverVisitorTest();
runJUnitTest(__test, __test.test_visitCatchClause_exception_stackTrace);
});
_ut.test('test_visitCatchClause_on_exception', () {
final __test = new TypeResolverVisitorTest();
runJUnitTest(__test, __test.test_visitCatchClause_on_exception);
});
_ut.test('test_visitCatchClause_on_exception_stackTrace', () {
final __test = new TypeResolverVisitorTest();
runJUnitTest(__test, __test.test_visitCatchClause_on_exception_stackTrace);
});
_ut.test('test_visitClassDeclaration', () {
final __test = new TypeResolverVisitorTest();
runJUnitTest(__test, __test.test_visitClassDeclaration);
});
_ut.test('test_visitClassTypeAlias', () {
final __test = new TypeResolverVisitorTest();
runJUnitTest(__test, __test.test_visitClassTypeAlias);
});
_ut.test('test_visitSimpleFormalParameter_noType', () {
final __test = new TypeResolverVisitorTest();
runJUnitTest(__test, __test.test_visitSimpleFormalParameter_noType);
});
_ut.test('test_visitSimpleFormalParameter_type', () {
final __test = new TypeResolverVisitorTest();
runJUnitTest(__test, __test.test_visitSimpleFormalParameter_type);
});
_ut.test('test_visitTypeName_noParameters_noArguments', () {
final __test = new TypeResolverVisitorTest();
runJUnitTest(__test, __test.test_visitTypeName_noParameters_noArguments);
});
_ut.test('test_visitTypeName_parameters_arguments', () {
final __test = new TypeResolverVisitorTest();
runJUnitTest(__test, __test.test_visitTypeName_parameters_arguments);
});
_ut.test('test_visitTypeName_parameters_noArguments', () {
final __test = new TypeResolverVisitorTest();
runJUnitTest(__test, __test.test_visitTypeName_parameters_noArguments);
});
_ut.test('test_visitTypeName_void', () {
final __test = new TypeResolverVisitorTest();
runJUnitTest(__test, __test.test_visitTypeName_void);
});
});
}
}
class ResolverTestCase extends EngineTestCase {
/**
* The source factory used to create {@link Source sources}.
*/
SourceFactory _sourceFactory;
/**
* The error listener used during resolution.
*/
GatheringErrorListener _errorListener;
/**
* The analysis context used to parse the compilation units being resolved.
*/
AnalysisContextImpl _analysisContext;
/**
* Assert that the number of errors that have been gathered matches the number of errors that are
* given and that they have the expected error codes. The order in which the errors were gathered
* is ignored.
* @param expectedErrorCodes the error codes of the errors that should have been gathered
* @throws AssertionFailedError if a different number of errors have been gathered than were
* expected
*/
void assertErrors(List<ErrorCode> expectedErrorCodes) {
_errorListener.assertErrors2(expectedErrorCodes);
}
void setUp() {
_errorListener = new GatheringErrorListener();
_analysisContext = AnalysisContextFactory.contextWithCore();
_sourceFactory = _analysisContext.sourceFactory;
}
/**
* Add a source file to the content provider. The file path should be absolute.
* @param filePath the path of the file being added
* @param contents the contents to be returned by the content provider for the specified file
* @return the source object representing the added file
*/
Source addSource(String filePath, String contents) {
Source source = new FileBasedSource.con1(_sourceFactory.contentCache, FileUtilities2.createFile(filePath));
_sourceFactory.setContents(source, contents);
ChangeSet changeSet = new ChangeSet();
changeSet.added(source);
_analysisContext.applyChanges(changeSet);
return source;
}
/**
* Assert that no errors have been gathered.
* @throws AssertionFailedError if any errors have been gathered
*/
void assertNoErrors() {
_errorListener.assertNoErrors();
}
/**
* Create a library element that represents a library named {@code "test"} containing a single
* empty compilation unit.
* @return the library element that was created
*/
LibraryElementImpl createTestLibrary() => createTestLibrary2(new AnalysisContextImpl(), "test", []);
/**
* Create a library element that represents a library with the given name containing a single
* empty compilation unit.
* @param libraryName the name of the library to be created
* @return the library element that was created
*/
LibraryElementImpl createTestLibrary2(AnalysisContext context, String libraryName, List<String> typeNames) {
int count = typeNames.length;
List<CompilationUnitElementImpl> sourcedCompilationUnits = new List<CompilationUnitElementImpl>(count);
for (int i = 0; i < count; i++) {
String typeName = typeNames[i];
ClassElementImpl type = new ClassElementImpl(ASTFactory.identifier3(typeName));
String fileName = "${typeName}.dart";
CompilationUnitElementImpl compilationUnit = new CompilationUnitElementImpl(fileName);
compilationUnit.source = createSource2(fileName);
compilationUnit.types = <ClassElement> [type];
sourcedCompilationUnits[i] = compilationUnit;
}
String fileName = "${libraryName}.dart";
CompilationUnitElementImpl compilationUnit = new CompilationUnitElementImpl(fileName);
compilationUnit.source = createSource2(fileName);
LibraryElementImpl library = new LibraryElementImpl(context, ASTFactory.libraryIdentifier2([libraryName]));
library.definingCompilationUnit = compilationUnit;
library.parts = sourcedCompilationUnits;
return library;
}
AnalysisContext get analysisContext => _analysisContext;
GatheringErrorListener get errorListener => _errorListener;
SourceFactory get sourceFactory => _sourceFactory;
/**
* Return a type provider that can be used to test the results of resolution.
* @return a type provider
*/
TypeProvider get typeProvider {
Source coreSource = _analysisContext.sourceFactory.forUri(DartSdk.DART_CORE);
LibraryElement coreElement = _analysisContext.getLibraryElement(coreSource);
return new TypeProviderImpl(coreElement);
}
/**
* Given a library and all of its parts, resolve the contents of the library and the contents of
* the parts. This assumes that the sources for the library and its parts have already been added
* to the content provider using the method {@link #addSource(String,String)}.
* @param librarySource the source for the compilation unit that defines the library
* @param unitSources the sources for the compilation units that are part of the library
* @return the element representing the resolved library
* @throws AnalysisException if the analysis could not be performed
*/
LibraryElement resolve(Source librarySource, List<Source> unitSources) {
LibraryResolver resolver = new LibraryResolver.con2(_analysisContext, _errorListener);
return resolver.resolveLibrary(librarySource, true);
}
/**
* Return the resolved compilation unit corresponding to the given source in the given library.
* @param source the source of the compilation unit to be returned
* @param library the library in which the compilation unit is to be resolved
* @return the resolved compilation unit
* @throws Exception if the compilation unit could not be resolved
*/
CompilationUnit resolveCompilationUnit(Source source, LibraryElement library) => _analysisContext.resolveCompilationUnit(source, library);
/**
* Verify that all of the identifiers in the compilation units associated with the given sources
* have been resolved.
* @param resolvedElementMap a table mapping the AST nodes that have been resolved to the element
* to which they were resolved
* @param sources the sources identifying the compilation units to be verified
* @throws Exception if the contents of the compilation unit cannot be accessed
*/
void verify(List<Source> sources) {
ResolutionVerifier verifier = new ResolutionVerifier();
for (Source source in sources) {
_analysisContext.parseCompilationUnit(source).accept(verifier);
}
verifier.assertResolved();
}
/**
* Create a source object representing a file with the given name and give it an empty content.
* @param fileName the name of the file for which a source is to be created
* @return the source that was created
*/
FileBasedSource createSource2(String fileName) {
FileBasedSource source = new FileBasedSource.con1(_sourceFactory.contentCache, FileUtilities2.createFile(fileName));
_sourceFactory.setContents(source, "");
return source;
}
static dartSuite() {
_ut.group('ResolverTestCase', () {
});
}
}
class TypeProviderImplTest extends EngineTestCase {
void test_creation() {
InterfaceType objectType = classElement("Object", null, []).type;
InterfaceType boolType = classElement("bool", objectType, []).type;
InterfaceType numType = classElement("num", objectType, []).type;
InterfaceType doubleType = classElement("double", numType, []).type;
InterfaceType functionType = classElement("Function", objectType, []).type;
InterfaceType intType = classElement("int", numType, []).type;
InterfaceType listType = classElement("List", objectType, ["E"]).type;
InterfaceType mapType = classElement("Map", objectType, ["K", "V"]).type;
InterfaceType stackTraceType = classElement("StackTrace", objectType, []).type;
InterfaceType stringType = classElement("String", objectType, []).type;
InterfaceType typeType = classElement("Type", objectType, []).type;
CompilationUnitElementImpl unit = new CompilationUnitElementImpl("lib.dart");
unit.types = <ClassElement> [boolType.element, doubleType.element, functionType.element, intType.element, listType.element, mapType.element, objectType.element, stackTraceType.element, stringType.element, typeType.element];
LibraryElementImpl library = new LibraryElementImpl(new AnalysisContextImpl(), ASTFactory.libraryIdentifier2(["lib"]));
library.definingCompilationUnit = unit;
TypeProviderImpl provider = new TypeProviderImpl(library);
JUnitTestCase.assertSame(boolType, provider.boolType);
JUnitTestCase.assertNotNull(provider.bottomType);
JUnitTestCase.assertSame(doubleType, provider.doubleType);
JUnitTestCase.assertNotNull(provider.dynamicType);
JUnitTestCase.assertSame(functionType, provider.functionType);
JUnitTestCase.assertSame(intType, provider.intType);
JUnitTestCase.assertSame(listType, provider.listType);
JUnitTestCase.assertSame(mapType, provider.mapType);
JUnitTestCase.assertSame(objectType, provider.objectType);
JUnitTestCase.assertSame(stackTraceType, provider.stackTraceType);
JUnitTestCase.assertSame(stringType, provider.stringType);
JUnitTestCase.assertSame(typeType, provider.typeType);
}
ClassElement classElement(String typeName, InterfaceType superclassType, List<String> parameterNames) {
ClassElementImpl element = new ClassElementImpl(ASTFactory.identifier3(typeName));
element.supertype = superclassType;
InterfaceTypeImpl type = new InterfaceTypeImpl.con1(element);
element.type = type;
int count = parameterNames.length;
if (count > 0) {
List<TypeVariableElementImpl> typeVariables = new List<TypeVariableElementImpl>(count);
List<TypeVariableTypeImpl> typeArguments = new List<TypeVariableTypeImpl>(count);
for (int i = 0; i < count; i++) {
TypeVariableElementImpl variable = new TypeVariableElementImpl(ASTFactory.identifier3(parameterNames[i]));
typeVariables[i] = variable;
typeArguments[i] = new TypeVariableTypeImpl(variable);
variable.type = typeArguments[i];
}
element.typeVariables = typeVariables;
type.typeArguments = typeArguments;
}
return element;
}
static dartSuite() {
_ut.group('TypeProviderImplTest', () {
_ut.test('test_creation', () {
final __test = new TypeProviderImplTest();
runJUnitTest(__test, __test.test_creation);
});
});
}
}
class CompileTimeErrorCodeTest extends ResolverTestCase {
void fail_ambiguousExport() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["library L;", "export 'lib1.dart';", "export 'lib2.dart';"]));
addSource("/lib1.dart", EngineTestCase.createSource(["class N {}"]));
addSource("/lib2.dart", EngineTestCase.createSource(["class N {}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.AMBIGUOUS_EXPORT]);
verify([source]);
}
void fail_ambiguousImport_function() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["library L;", "import 'lib1.dart';", "import 'lib2.dart';", "g() { return f(); }"]));
addSource("/lib1.dart", EngineTestCase.createSource(["f() {}"]));
addSource("/lib2.dart", EngineTestCase.createSource(["f() {}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.AMBIGUOUS_IMPORT]);
verify([source]);
}
void fail_ambiguousImport_typeAnnotation() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["library L;", "import 'lib1.dart';", "import 'lib2.dart';", "class A extends N {}"]));
addSource("/lib1.dart", EngineTestCase.createSource(["class N {}"]));
addSource("/lib2.dart", EngineTestCase.createSource(["class N {}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.AMBIGUOUS_IMPORT]);
verify([source]);
}
void fail_compileTimeConstantRaisesException() {
Source source = addSource("/test.dart", EngineTestCase.createSource([]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.COMPILE_TIME_CONSTANT_RAISES_EXCEPTION]);
verify([source]);
}
void fail_constWithNonConstantArgument() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class T {", " T(a) {};", "}", "f(p) { return const T(p); }"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.CONST_WITH_NON_CONSTANT_ARGUMENT]);
verify([source]);
}
void fail_constWithNonType() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["int A;", "f() {", " return const A();", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.CONST_WITH_NON_TYPE]);
verify([source]);
}
void fail_constWithTypeParameters() {
Source source = addSource("/test.dart", EngineTestCase.createSource([]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETERS]);
verify([source]);
}
void fail_constWithUndefinedConstructor() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " A(x) {}", "}", "f() {", " return const A(0);", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR]);
verify([source]);
}
void fail_duplicateDefinition() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {", " int m = 0;", " m(a) {}", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.DUPLICATE_DEFINITION]);
verify([source]);
}
void fail_duplicateMemberName() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " int x = 0;", " int x() {}", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.DUPLICATE_MEMBER_NAME]);
verify([source]);
}
void fail_duplicateMemberNameInstanceStatic() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " int x;", " static int x;", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.DUPLICATE_MEMBER_NAME_INSTANCE_STATIC]);
verify([source]);
}
void fail_duplicateNamedArgument() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["f({a, a}) {}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.DUPLICATE_NAMED_ARGUMENT]);
verify([source]);
}
void fail_extendsOrImplementsDisallowedClass_extends_null() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A extends Null {}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]);
verify([source]);
}
void fail_extendsOrImplementsDisallowedClass_implements_null() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A implements Null {}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]);
verify([source]);
}
void fail_finalNotInitialized_inConstructor() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " final int x;", " A() {}", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.FINAL_NOT_INITIALIZED]);
verify([source]);
}
void fail_getterAndMethodWithSameName() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " get x -> 0;", " x(y) {}", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.GETTER_AND_METHOD_WITH_SAME_NAME]);
verify([source]);
}
void fail_importDuplicatedLibraryName() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["library test;", "import 'lib1.dart';", "import 'lib2.dart';"]));
addSource("/lib1.dart", EngineTestCase.createSource(["library lib;"]));
addSource("/lib2.dart", EngineTestCase.createSource(["library lib;"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.IMPORT_DUPLICATED_LIBRARY_NAME]);
verify([source]);
}
void fail_invalidConstructorName() {
Source source = addSource("/test.dart", EngineTestCase.createSource([]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME]);
verify([source]);
}
void fail_invalidFactoryNameNotAClass() {
Source source = addSource("/test.dart", EngineTestCase.createSource([]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLASS]);
verify([source]);
}
void fail_invalidOverrideDefaultValue() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " m([a = 0]) {}", "}", "class B extends A {", " m([a = 1]) {}", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.INVALID_OVERRIDE_DEFAULT_VALUE]);
verify([source]);
}
void fail_invalidOverrideNamed() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " m({a, b}) {}", "}", "class B extends A {", " m({a}) {}", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.INVALID_OVERRIDE_NAMED]);
verify([source]);
}
void fail_invalidOverridePositional() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " m([a, b]) {}", "}", "class B extends A {", " m([a]) {}", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.INVALID_OVERRIDE_POSITIONAL]);
verify([source]);
}
void fail_invalidOverrideRequired() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " m(a) {}", "}", "class B extends A {", " m(a, b) {}", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.INVALID_OVERRIDE_REQUIRED]);
verify([source]);
}
void fail_invalidReferenceToThis_staticMethod() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " static m() { return this; }", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]);
verify([source]);
}
void fail_invalidReferenceToThis_topLevelFunction() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["f() { return this; }"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]);
verify([source]);
}
void fail_invalidReferenceToThis_variableInitializer() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["int x = this;"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]);
verify([source]);
}
void fail_invalidTypeArgumentInConstList() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A<E> {", " m() {", " return const <E>[]", " }", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_LIST]);
verify([source]);
}
void fail_invalidTypeArgumentInConstMap() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A<E> {", " m() {", " return const <String, E>{}", " }", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_MAP]);
verify([source]);
}
void fail_memberWithClassName() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " int A = 0;", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME]);
verify([source]);
}
void fail_mixinDeclaresConstructor() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " A() {}", "}", "class B extends Object mixin A {}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR]);
verify([source]);
}
void fail_mixinInheritsFromNotObject() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "class B extends A {}", "class C extends Object mixin B {}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]);
verify([source]);
}
void fail_mixinOfNonClass() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["var A;", "class B extends Object mixin A {}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.MIXIN_OF_NON_CLASS]);
verify([source]);
}
void fail_mixinOfNonMixin() {
Source source = addSource("/test.dart", EngineTestCase.createSource([]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.MIXIN_OF_NON_MIXIN]);
verify([source]);
}
void fail_mixinReferencesSuper() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " toString() -> super.toString();", "}", "class B extends Object mixin A {}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.MIXIN_REFERENCES_SUPER]);
verify([source]);
}
void fail_mixinWithNonClassSuperclass() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["int A;", "class B extends Object mixin A {}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.MIXIN_WITH_NON_CLASS_SUPERCLASS]);
verify([source]);
}
void fail_multipleSuperInitializers() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "class B extends A {", " B() : super(), super() {}", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.MULTIPLE_SUPER_INITIALIZERS]);
verify([source]);
}
void fail_nonConstantDefaultValue_named() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["f({x : 2 + 3}) {}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]);
verify([source]);
}
void fail_nonConstantDefaultValue_positional() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["f([x = 2 + 3]) {}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]);
verify([source]);
}
void fail_nonConstMapAsExpressionStatement() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {", " {'a' : 0, 'b' : 1};", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.NON_CONST_MAP_AS_EXPRESSION_STATEMENT]);
verify([source]);
}
void fail_nonConstMapKey() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["f(a) {", " return const {a : 0};", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.NON_CONSTANT_MAP_KEY]);
verify([source]);
}
void fail_nonConstValueInInitializer() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " static C;", " int a;", " A() : a = C {}", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER]);
verify([source]);
}
void fail_objectCannotExtendAnotherClass() {
Source source = addSource("/test.dart", EngineTestCase.createSource([]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.OBJECT_CANNOT_EXTEND_ANOTHER_CLASS]);
verify([source]);
}
void fail_optionalParameterInOperator() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " operator +([p]) {}", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.OPTIONAL_PARAMETER_IN_OPERATOR]);
verify([source]);
}
void fail_overrideMissingNamedParameters() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " m(a, {b}) {}", "}", "class B extends A {", " m(a) {}", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.OVERRIDE_MISSING_NAMED_PARAMETERS]);
verify([source]);
}
void fail_overrideMissingRequiredParameters() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " m(a) {}", "}", "class B extends A {", " m(a, b) {}", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.OVERRIDE_MISSING_REQUIRED_PARAMETERS]);
verify([source]);
}
void fail_prefixCollidesWithTopLevelMembers() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["import 'dart:uri' as uri;", "var uri = null;"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER]);
verify([source]);
}
void fail_privateOptionalParameter() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["f({_p : 0}) {}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER]);
verify([source]);
}
void fail_recursiveCompileTimeConstant() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["const x = y + 1;", "const y = x + 1;"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT]);
verify([source]);
}
void fail_recursiveFactoryRedirect() {
Source source = addSource("/test.dart", EngineTestCase.createSource([]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT]);
verify([source]);
}
void fail_recursiveFunctionTypeAlias_direct() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["typedef F(F f);"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.RECURSIVE_FUNCTION_TYPE_ALIAS]);
verify([source]);
}
void fail_recursiveFunctionTypeAlias_indirect() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["typedef F(G g);", "typedef G(F f);"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.RECURSIVE_FUNCTION_TYPE_ALIAS]);
verify([source]);
}
void fail_recursiveInterfaceInheritance_direct() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A implements A {}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE]);
verify([source]);
}
void fail_recursiveInterfaceInheritance_indirect() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A implements B {}", "class B implements A {}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE]);
verify([source]);
}
void fail_redirectToNonConstConstructor() {
Source source = addSource("/test.dart", EngineTestCase.createSource([]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.REDIRECT_TO_NON_CONST_CONSTRUCTOR]);
verify([source]);
}
void fail_referenceToDeclaredVariableInInitializer_getter() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {", " int x = x + 1;", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.REFERENCE_TO_DECLARED_VARIABLE_IN_INITIALIZER]);
verify([source]);
}
void fail_referenceToDeclaredVariableInInitializer_setter() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {", " int x = x++;", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.REFERENCE_TO_DECLARED_VARIABLE_IN_INITIALIZER]);
verify([source]);
}
void fail_reservedWordAsIdentifier() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["int class = 2;"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.RESERVED_WORD_AS_IDENTIFIER]);
verify([source]);
}
void fail_returnInGenerativeConstructor() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " A() { return 0; }", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONSTRUCTOR]);
verify([source]);
}
void fail_staticTopLevelFunction_topLevel() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["static f() {}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.STATIC_TOP_LEVEL_FUNCTION]);
verify([source]);
}
void fail_staticTopLevelVariable() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["static int x;"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.STATIC_TOP_LEVEL_VARIABLE]);
verify([source]);
}
void fail_superInInvalidContext_factoryConstructor() {
Source source = addSource("/test.dart", EngineTestCase.createSource([]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]);
verify([source]);
}
void fail_superInInvalidContext_instanceVariableInitializer() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " var a;", "}", "class B extends A {", " var b = super.a;", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]);
verify([source]);
}
void fail_superInInvalidContext_staticMethod() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " static m() {}", "}", "class B extends A {", " static n() { return super.m(); }", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]);
verify([source]);
}
void fail_superInInvalidContext_staticVariableInitializer() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " static a = 0;", "}", "class B extends A {", " static b = super.a;", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]);
verify([source]);
}
void fail_superInInvalidContext_topLevelFunction() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {", " super.f();", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]);
verify([source]);
}
void fail_superInInvalidContext_variableInitializer() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["var v = super.v;"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]);
verify([source]);
}
void fail_superInitializerInObject() {
Source source = addSource("/test.dart", EngineTestCase.createSource([]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.SUPER_INITIALIZER_IN_OBJECT]);
verify([source]);
}
void fail_typeArgumentsForNonGenericClass_creation_const() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "f(p) {", " return const A<int>();", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.TYPE_ARGUMENTS_FOR_NON_GENERIC_CLASS]);
verify([source]);
}
void fail_typeArgumentsForNonGenericClass_creation_new() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "f(p) {", " return new A<int>();", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.TYPE_ARGUMENTS_FOR_NON_GENERIC_CLASS]);
verify([source]);
}
void fail_typeArgumentsForNonGenericClass_typeCast() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "f(p) {", " return p as A<int>;", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.TYPE_ARGUMENTS_FOR_NON_GENERIC_CLASS]);
verify([source]);
}
void fail_undefinedConstructorInInitializer() {
Source source = addSource("/test.dart", EngineTestCase.createSource([]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER]);
verify([source]);
}
void fail_uninitializedFinalField() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " final int i;", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.UNINITIALIZED_FINAL_FIELD]);
verify([source]);
}
void fail_wrongNumberOfParametersForOperator() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " operator []=(i) {}", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR]);
verify([source]);
}
void fail_wrongNumberOfParametersForSetter_tooFew() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["set x() {}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER]);
verify([source]);
}
void fail_wrongNumberOfParametersForSetter_tooMany() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["set x(a, b) {}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER]);
verify([source]);
}
void fail_wrongNumberOfTypeArguments_creation_const_tooFew() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "class C<K, V> {}", "f(p) {", " return const C<A>();", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]);
verify([source]);
}
void fail_wrongNumberOfTypeArguments_creation_const_tooMany() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "class C<E> {}", "f(p) {", " return const C<A, A>();", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]);
verify([source]);
}
void fail_wrongNumberOfTypeArguments_creation_new_tooFew() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "class C<K, V> {}", "f(p) {", " return new C<A>();", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]);
verify([source]);
}
void fail_wrongNumberOfTypeArguments_creation_new_tooMany() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "class C<E> {}", "f(p) {", " return new C<A, A>();", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]);
verify([source]);
}
void fail_wrongNumberOfTypeArguments_typeTest_tooFew() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "class C<K, V> {}", "f(p) {", " return p is C<A>;", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]);
verify([source]);
}
void fail_wrongNumberOfTypeArguments_typeTest_tooMany() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "class C<E> {}", "f(p) {", " return p is C<A, A>;", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]);
verify([source]);
}
void test_argumentDefinitionTestNonParameter() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {", " var v = 0;", " return ?v;", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.ARGUMENT_DEFINITION_TEST_NON_PARAMETER]);
verify([source]);
}
void test_builtInIdentifierAsType() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {", " typedef x;", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE, StaticWarningCode.UNDEFINED_CLASS]);
verify([source]);
}
void test_builtInIdentifierAsTypedefName_classTypeAlias() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "class B {}", "typedef as = A with B;"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME]);
verify([source]);
}
void test_builtInIdentifierAsTypedefName_functionTypeAlias() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["typedef bool as();"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME]);
verify([source]);
}
void test_builtInIdentifierAsTypeName() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class as {}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_NAME]);
verify([source]);
}
void test_builtInIdentifierAsTypeVariableName() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A<as> {}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_VARIABLE_NAME]);
verify([source]);
}
void test_caseExpressionTypeImplementsEquals() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class IntWrapper {", " final int value;", " const IntWrapper(this.value);", " bool operator ==(IntWrapper x) {", " return value == x.value;", " }", "}", "", "f(IntWrapper a) {", " switch(a) {", " case(const IntWrapper(1)) : return 1;", " default: return 0;", " }", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS]);
verify([source]);
}
void test_conflictingConstructorNameAndMember_field() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " int x;", " A.x() {}", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_NAME_AND_FIELD]);
verify([source]);
}
void test_conflictingConstructorNameAndMember_method() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " const A.x() {}", " void x() {}", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_NAME_AND_METHOD]);
verify([source]);
}
void test_constConstructorWithNonFinalField() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " int x;", " const A() {}", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD]);
verify([source]);
}
void test_constEvalThrowsException() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class C {", " const C() { throw null; }", "}", "f() { return const C(); }"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION]);
verify([source]);
}
void test_constFormalParameter_fieldFormalParameter() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " var x;", " A(const this.x) {}", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.CONST_FORMAL_PARAMETER]);
verify([source]);
}
void test_constFormalParameter_simpleFormalParameter() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["f(const x) {}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.CONST_FORMAL_PARAMETER]);
verify([source]);
}
void test_constInitializedWithNonConstValue() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["f(p) {", " const C = p;", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]);
verify([source]);
}
void test_constWithInvalidTypeParameters() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " const A() {}", "}", "f() { return const A<A>(); }"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.CONST_WITH_INVALID_TYPE_PARAMETERS]);
verify([source]);
}
void test_constWithNonConst() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class T {", " T(a, b, {c, d}) {}", "}", "f() { return const T(0, 1, c: 2, d: 3); }"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.CONST_WITH_NON_CONST]);
verify([source]);
}
void test_defaultValueInFunctionTypeAlias() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["typedef F([x = 0]);"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPE_ALIAS]);
verify([source]);
}
void test_duplicateMemberError() {
Source librarySource = addSource("/lib.dart", EngineTestCase.createSource(["library lib;", "", "part 'a.dart';", "part 'b.dart';"]));
Source sourceA = addSource("/a.dart", EngineTestCase.createSource(["part of lib;", "", "class A {}"]));
Source sourceB = addSource("/b.dart", EngineTestCase.createSource(["part of lib;", "", "class A {}"]));
resolve(librarySource, [sourceA, sourceB]);
assertErrors([CompileTimeErrorCode.DUPLICATE_DEFINITION]);
verify([librarySource, sourceA, sourceB]);
}
void test_exportOfNonLibrary() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["library L;", "export 'lib1.dart';"]));
addSource("/lib1.dart", EngineTestCase.createSource(["part of lib;"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY]);
verify([source]);
}
void test_extendsNonClass_class() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["int A;", "class B extends A {}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.EXTENDS_NON_CLASS]);
verify([source]);
}
void test_extendsOrImplementsDisallowedClass_extends_bool() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A extends bool {}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]);
verify([source]);
}
void test_extendsOrImplementsDisallowedClass_extends_double() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A extends double {}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]);
verify([source]);
}
void test_extendsOrImplementsDisallowedClass_extends_int() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A extends int {}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]);
verify([source]);
}
void test_extendsOrImplementsDisallowedClass_extends_num() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A extends num {}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]);
verify([source]);
}
void test_extendsOrImplementsDisallowedClass_extends_String() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A extends String {}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]);
verify([source]);
}
void test_extendsOrImplementsDisallowedClass_implements_bool() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A implements bool {}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]);
verify([source]);
}
void test_extendsOrImplementsDisallowedClass_implements_double() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A implements double {}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]);
verify([source]);
}
void test_extendsOrImplementsDisallowedClass_implements_int() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A implements int {}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]);
verify([source]);
}
void test_extendsOrImplementsDisallowedClass_implements_num() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A implements num {}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]);
verify([source]);
}
void test_extendsOrImplementsDisallowedClass_implements_String() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A implements String {}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]);
verify([source]);
}
void test_fieldInitializedByMultipleInitializers() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " int x;", " A() : x = 0, x = 1 {}", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS]);
verify([source]);
}
void test_fieldInitializedByMultipleInitializers_multipleInits() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " int x;", " A() : x = 0, x = 1, x = 2 {}", "}"]));
resolve(source, []);
assertErrors([CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS, CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS]);
verify([source]);
}
void test_fieldInitializedByMultipleInitializers_multipleNames() {
Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " int x;", " int y;", " A() : x = 0, x