Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(865)

Unified Diff: pkg/analyzer/test/generated/static_type_warning_code_test.dart

Issue 1780623002: Clean up some copy/paste in a test. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analyzer/test/generated/resolver_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/test/generated/static_type_warning_code_test.dart
diff --git a/pkg/analyzer/test/generated/static_type_warning_code_test.dart b/pkg/analyzer/test/generated/static_type_warning_code_test.dart
index 2354fb0bb2332a13a6f1fa625085c1823d307fb6..0f4f64a92b1edc381f9d38bd91eb00b86ac12797 100644
--- a/pkg/analyzer/test/generated/static_type_warning_code_test.dart
+++ b/pkg/analyzer/test/generated/static_type_warning_code_test.dart
@@ -23,17 +23,18 @@ main() {
@reflectiveTest
class StaticTypeWarningCodeTest extends ResolverTestCase {
void fail_inaccessibleSetter() {
- Source source = addSource(r'''
-''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.INACCESSIBLE_SETTER]);
- verify([source]);
+ // TODO(rnystrom): This doesn't look right.
Brian Wilkerson 2016/03/09 01:37:38 Note that the method's name is "fail", indicating
Bob Nystrom 2016/03/09 01:46:47 That's what I figured. :) Tests that are just expe
+ assertErrorsInCode(
+ r'''
+''',
+ [StaticTypeWarningCode.INACCESSIBLE_SETTER]);
}
void fail_method_lookup_mixin_of_extends() {
// See dartbug.com/25605
resetWithOptions(new AnalysisOptionsImpl()..enableSuperMixins = true);
- Source source = addSource('''
+ assertErrorsInUnverifiedCode(
+ '''
class A { a() => null; }
class B {}
abstract class M extends A {}
@@ -41,19 +42,19 @@ class T = B with M; // Warning: B does not extend A
main() {
new T().a(); // Warning: The method 'a' is not defined for the class 'T'
}
-''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [
- // TODO(paulberry): when dartbug.com/25614 is fixed, add static warning
- // code for "B does not extend A".
- StaticTypeWarningCode.UNDEFINED_METHOD
- ]);
+''',
+ [
+ // TODO(paulberry): when dartbug.com/25614 is fixed, add static warning
+ // code for "B does not extend A".
+ StaticTypeWarningCode.UNDEFINED_METHOD
+ ]);
}
void fail_method_lookup_mixin_of_implements() {
// See dartbug.com/25605
resetWithOptions(new AnalysisOptionsImpl()..enableSuperMixins = true);
- Source source = addSource('''
+ assertErrorsInUnverifiedCode(
+ '''
class A { a() => null; }
class B {}
abstract class M implements A {}
@@ -61,18 +62,18 @@ class T = B with M; // Warning: Missing concrete implementation of 'A.a'
main() {
new T().a(); // Warning: The method 'a' is not defined for the class 'T'
}
-''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [
- StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE,
- StaticTypeWarningCode.UNDEFINED_METHOD
- ]);
+''',
+ [
+ StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE,
+ StaticTypeWarningCode.UNDEFINED_METHOD
+ ]);
}
void fail_method_lookup_mixin_of_mixin() {
// See dartbug.com/25605
resetWithOptions(new AnalysisOptionsImpl()..enableSuperMixins = true);
- Source source = addSource('''
+ assertErrorsInUnverifiedCode(
+ '''
class A {}
class B { b() => null; }
class C {}
@@ -81,15 +82,15 @@ class T = C with M;
main() {
new T().b();
}
-''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_METHOD]);
+''',
+ [StaticTypeWarningCode.UNDEFINED_METHOD]);
}
void fail_method_lookup_mixin_of_mixin_application() {
// See dartbug.com/25605
resetWithOptions(new AnalysisOptionsImpl()..enableSuperMixins = true);
- Source source = addSource('''
+ assertErrorsInUnverifiedCode(
+ '''
class A { a() => null; }
class B {}
class C {}
@@ -98,21 +99,19 @@ class T = C with M;
main() {
new T().a();
}
-''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_METHOD]);
+''',
+ [StaticTypeWarningCode.UNDEFINED_METHOD]);
}
void fail_undefinedEnumConstant() {
// We need a way to set the parseEnum flag in the parser to true.
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
enum E { ONE }
E e() {
return E.TWO;
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_ENUM_CONSTANT]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.UNDEFINED_ENUM_CONSTANT]);
}
void test_ambiguousImport_function() {
@@ -141,7 +140,8 @@ f() {}''');
// dubious practice for the computation of an assert message to have side
// effects, since it is only evaluated if the assert fails).
resetWithOptions(new AnalysisOptionsImpl()..enableAssertMessage = true);
- Source source = addSource('''
+ assertErrorsInCode(
+ '''
class C {
void foo() {}
}
@@ -152,40 +152,38 @@ f(Object x) {
assert(true, () { x = new C(); return 'msg'; }());
}
}
-''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_METHOD]);
+''',
+ [StaticTypeWarningCode.UNDEFINED_METHOD]);
// Do not verify since `x.foo()` fails to resolve.
}
void test_await_flattened() {
- Source source = addSource('''
+ assertErrorsInCode(
+ '''
import 'dart:async';
Future<Future<int>> ffi() => null;
f() async {
Future<int> b = await ffi(); // Warning: int not assignable to Future<int>
}
-''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]);
- verify([source]);
+''',
+ [StaticTypeWarningCode.INVALID_ASSIGNMENT]);
}
void test_await_simple() {
- Source source = addSource('''
+ assertErrorsInCode(
+ '''
import 'dart:async';
Future<int> fi() => null;
f() async {
String a = await fi(); // Warning: int not assignable to String
}
-''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]);
- verify([source]);
+''',
+ [StaticTypeWarningCode.INVALID_ASSIGNMENT]);
}
void test_bug21912() {
- Source source = addSource('''
+ assertErrorsInCode(
+ '''
class A {}
class B extends A {}
@@ -204,120 +202,103 @@ void main() {
left = t2;
}
}
-''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [
- StaticTypeWarningCode.INVALID_ASSIGNMENT,
- StaticTypeWarningCode.INVALID_ASSIGNMENT
- ]);
- verify([source]);
+''',
+ [
+ StaticTypeWarningCode.INVALID_ASSIGNMENT,
+ StaticTypeWarningCode.INVALID_ASSIGNMENT
+ ]);
}
void test_expectedOneListTypeArgument() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
main() {
<int, int> [];
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(
- source, [StaticTypeWarningCode.EXPECTED_ONE_LIST_TYPE_ARGUMENTS]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.EXPECTED_ONE_LIST_TYPE_ARGUMENTS]);
}
void test_expectedTwoMapTypeArguments_one() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
main() {
<int> {};
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(
- source, [StaticTypeWarningCode.EXPECTED_TWO_MAP_TYPE_ARGUMENTS]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.EXPECTED_TWO_MAP_TYPE_ARGUMENTS]);
}
void test_expectedTwoMapTypeArguments_three() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
main() {
<int, int, int> {};
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(
- source, [StaticTypeWarningCode.EXPECTED_TWO_MAP_TYPE_ARGUMENTS]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.EXPECTED_TWO_MAP_TYPE_ARGUMENTS]);
}
void test_illegal_return_type_async_function() {
- Source source = addSource('''
+ assertErrorsInCode(
+ '''
int f() async {}
-''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [
- StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE,
- HintCode.MISSING_RETURN
- ]);
- verify([source]);
+''',
+ [
+ StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE,
+ HintCode.MISSING_RETURN
+ ]);
}
void test_illegal_return_type_async_generator_function() {
- Source source = addSource('''
+ assertErrorsInCode(
+ '''
int f() async* {}
-''');
- computeLibrarySourceErrors(source);
- assertErrors(
- source, [StaticTypeWarningCode.ILLEGAL_ASYNC_GENERATOR_RETURN_TYPE]);
- verify([source]);
+''',
+ [StaticTypeWarningCode.ILLEGAL_ASYNC_GENERATOR_RETURN_TYPE]);
}
void test_illegal_return_type_async_generator_method() {
- Source source = addSource('''
+ assertErrorsInCode(
+ '''
class C {
int f() async* {}
}
-''');
- computeLibrarySourceErrors(source);
- assertErrors(
- source, [StaticTypeWarningCode.ILLEGAL_ASYNC_GENERATOR_RETURN_TYPE]);
- verify([source]);
+''',
+ [StaticTypeWarningCode.ILLEGAL_ASYNC_GENERATOR_RETURN_TYPE]);
}
void test_illegal_return_type_async_method() {
- Source source = addSource('''
+ assertErrorsInCode(
+ '''
class C {
int f() async {}
}
-''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [
- StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE,
- HintCode.MISSING_RETURN
- ]);
- verify([source]);
+''',
+ [
+ StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE,
+ HintCode.MISSING_RETURN
+ ]);
}
void test_illegal_return_type_sync_generator_function() {
- Source source = addSource('''
+ assertErrorsInCode(
+ '''
int f() sync* {}
-''');
- computeLibrarySourceErrors(source);
- assertErrors(
- source, [StaticTypeWarningCode.ILLEGAL_SYNC_GENERATOR_RETURN_TYPE]);
- verify([source]);
+''',
+ [StaticTypeWarningCode.ILLEGAL_SYNC_GENERATOR_RETURN_TYPE]);
}
void test_illegal_return_type_sync_generator_method() {
- Source source = addSource('''
+ assertErrorsInCode(
+ '''
class C {
int f() sync* {}
}
-''');
- computeLibrarySourceErrors(source);
- assertErrors(
- source, [StaticTypeWarningCode.ILLEGAL_SYNC_GENERATOR_RETURN_TYPE]);
- verify([source]);
+''',
+ [StaticTypeWarningCode.ILLEGAL_SYNC_GENERATOR_RETURN_TYPE]);
}
void test_inconsistentMethodInheritance_paramCount() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
abstract class A {
int x();
}
@@ -325,115 +306,101 @@ abstract class B {
int x(int y);
}
class C implements A, B {
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(
- source, [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE]);
}
void test_inconsistentMethodInheritance_paramType() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
abstract class A {
x(int i);
}
abstract class B {
x(String s);
}
-abstract class C implements A, B {}''');
- computeLibrarySourceErrors(source);
- assertErrors(
- source, [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE]);
- verify([source]);
+abstract class C implements A, B {}
+''',
+ [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE]);
}
void test_inconsistentMethodInheritance_returnType() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
abstract class A {
int x();
}
abstract class B {
String x();
}
-abstract class C implements A, B {}''');
- computeLibrarySourceErrors(source);
- assertErrors(
- source, [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE]);
- verify([source]);
+abstract class C implements A, B {}
+''',
+ [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE]);
}
void test_instanceAccessToStaticMember_method_invocation() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {
static m() {}
}
main(A a) {
a.m();
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(
- source, [StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER]);
}
void test_instanceAccessToStaticMember_method_reference() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {
static m() {}
}
main(A a) {
a.m;
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(
- source, [StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER]);
}
void test_instanceAccessToStaticMember_propertyAccess_field() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {
static var f;
}
main(A a) {
a.f;
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(
- source, [StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER]);
}
void test_instanceAccessToStaticMember_propertyAccess_getter() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {
static get f => 42;
}
main(A a) {
a.f;
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(
- source, [StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER]);
}
void test_instanceAccessToStaticMember_propertyAccess_setter() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {
static set f(x) {}
}
main(A a) {
a.f = 42;
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(
- source, [StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER]);
}
void test_invalidAssignment_compoundAssignment() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class byte {
int _value;
byte(this._value);
@@ -443,152 +410,137 @@ class byte {
void main() {
byte b = new byte(52);
b += 3;
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.INVALID_ASSIGNMENT]);
}
void test_invalidAssignment_defaultValue_named() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
f({String x: 0}) {
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.INVALID_ASSIGNMENT]);
}
void test_invalidAssignment_defaultValue_optional() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
f([String x = 0]) {
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.INVALID_ASSIGNMENT]);
}
void test_invalidAssignment_dynamic() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
main() {
dynamic = 1;
}
-''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]);
- verify([source]);
+''',
+ [StaticTypeWarningCode.INVALID_ASSIGNMENT]);
}
void test_invalidAssignment_functionExpressionInvocation() {
- Source source = addSource('''
+ assertErrorsInCode(
+ '''
main() {
String x = (() => 5)();
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.INVALID_ASSIGNMENT]);
}
void test_invalidAssignment_ifNullAssignment() {
- Source source = addSource('''
+ assertErrorsInCode(
+ '''
void f(int i) {
double d;
d ??= i;
}
-''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]);
- verify([source]);
+''',
+ [StaticTypeWarningCode.INVALID_ASSIGNMENT]);
}
void test_invalidAssignment_instanceVariable() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {
int x;
}
f() {
A a;
a.x = '0';
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.INVALID_ASSIGNMENT]);
}
void test_invalidAssignment_localVariable() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
f() {
int x;
x = '0';
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.INVALID_ASSIGNMENT]);
}
void test_invalidAssignment_regressionInIssue18468Fix() {
// https://code.google.com/p/dart/issues/detail?id=18628
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class C<T> {
T t = int;
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.INVALID_ASSIGNMENT]);
}
void test_invalidAssignment_staticVariable() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {
static int x;
}
f() {
A.x = '0';
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.INVALID_ASSIGNMENT]);
}
void test_invalidAssignment_topLevelVariableDeclaration() {
- Source source = addSource("int x = 'string';");
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]);
- verify([source]);
+ assertErrorsInCode(
+ "int x = 'string';", [StaticTypeWarningCode.INVALID_ASSIGNMENT]);
}
void test_invalidAssignment_typeParameter() {
// 14221
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class B<T> {
T value;
void test(num n) {
value = n;
}
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.INVALID_ASSIGNMENT]);
}
void test_invalidAssignment_variableDeclaration() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {
int x = 'string';
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.INVALID_ASSIGNMENT]);
}
void test_invocationOfNonFunction_class() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {
void m() {
A();
}
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION]);
+}''',
+ [StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION]);
}
void test_invocationOfNonFunction_localGenericFunction() {
@@ -599,41 +551,39 @@ class A {
AnalysisOptionsImpl options = new AnalysisOptionsImpl();
options.enableStrictCallChecks = true;
resetWithOptions(options);
- Source source = addSource('''
+ assertErrorsInCode(
+ '''
f(Function f) {
return f();
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION]);
}
void test_invocationOfNonFunction_localObject() {
AnalysisOptionsImpl options = new AnalysisOptionsImpl();
options.enableStrictCallChecks = true;
resetWithOptions(options);
- Source source = addSource('''
+ assertErrorsInCode(
+ '''
f(Object o) {
return o();
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION]);
}
void test_invocationOfNonFunction_localVariable() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
f() {
int x;
return x();
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION]);
}
void test_invocationOfNonFunction_ordinaryInvocation() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {
static int x;
}
@@ -641,27 +591,27 @@ class B {
m() {
A.x();
}
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION]);
+}''',
+ [StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION]);
// A call to verify(source) fails as A.x() cannot be resolved.
}
void test_invocationOfNonFunction_staticInvocation() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {
static int get g => 0;
f() {
A.g();
}
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION]);
+}''',
+ [StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION]);
// A call to verify(source) fails as g() cannot be resolved.
}
void test_invocationOfNonFunction_superExpression() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {
int get g => 0;
}
@@ -669,282 +619,246 @@ class B extends A {
m() {
var v = super.g();
}
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION]);
}
void test_invocationOfNonFunctionExpression_literal() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
f() {
3(5);
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(
- source, [StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION_EXPRESSION]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION_EXPRESSION]);
}
void test_nonBoolCondition_conditional() {
- Source source = addSource("f() { return 3 ? 2 : 1; }");
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.NON_BOOL_CONDITION]);
- verify([source]);
+ assertErrorsInCode("f() { return 3 ? 2 : 1; }",
+ [StaticTypeWarningCode.NON_BOOL_CONDITION]);
}
void test_nonBoolCondition_do() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
f() {
do {} while (3);
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.NON_BOOL_CONDITION]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.NON_BOOL_CONDITION]);
}
void test_nonBoolCondition_for() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
f() {
for (;3;) {}
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.NON_BOOL_CONDITION]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.NON_BOOL_CONDITION]);
}
void test_nonBoolCondition_if() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
f() {
if (3) return 2; else return 1;
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.NON_BOOL_CONDITION]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.NON_BOOL_CONDITION]);
}
void test_nonBoolCondition_while() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
f() {
while (3) {}
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.NON_BOOL_CONDITION]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.NON_BOOL_CONDITION]);
}
void test_nonBoolExpression_functionType() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
int makeAssertion() => 1;
f() {
assert(makeAssertion);
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.NON_BOOL_EXPRESSION]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.NON_BOOL_EXPRESSION]);
}
void test_nonBoolExpression_interfaceType() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
f() {
assert(0);
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.NON_BOOL_EXPRESSION]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.NON_BOOL_EXPRESSION]);
}
void test_nonBoolNegationExpression() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
f() {
!42;
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.NON_BOOL_NEGATION_EXPRESSION]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.NON_BOOL_NEGATION_EXPRESSION]);
}
void test_nonBoolOperand_and_left() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
bool f(int left, bool right) {
return left && right;
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.NON_BOOL_OPERAND]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.NON_BOOL_OPERAND]);
}
void test_nonBoolOperand_and_right() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
bool f(bool left, String right) {
return left && right;
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.NON_BOOL_OPERAND]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.NON_BOOL_OPERAND]);
}
void test_nonBoolOperand_or_left() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
bool f(List<int> left, bool right) {
return left || right;
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.NON_BOOL_OPERAND]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.NON_BOOL_OPERAND]);
}
void test_nonBoolOperand_or_right() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
bool f(bool left, double right) {
return left || right;
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.NON_BOOL_OPERAND]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.NON_BOOL_OPERAND]);
}
void test_nonTypeAsTypeArgument_notAType() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
int A;
class B<E> {}
-f(B<A> b) {}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT]);
- verify([source]);
+f(B<A> b) {}''',
+ [StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT]);
}
void test_nonTypeAsTypeArgument_undefinedIdentifier() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class B<E> {}
-f(B<A> b) {}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT]);
- verify([source]);
+f(B<A> b) {}''',
+ [StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT]);
}
void test_returnOfInvalidType_async_future_int_mismatches_future_null() {
- Source source = addSource('''
+ assertErrorsInCode(
+ '''
import 'dart:async';
Future<Null> f() async {
return 5;
}
-''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]);
- verify([source]);
+''',
+ [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]);
}
void test_returnOfInvalidType_async_future_int_mismatches_future_string() {
- Source source = addSource('''
+ assertErrorsInCode(
+ '''
import 'dart:async';
Future<String> f() async {
return 5;
}
-''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]);
- verify([source]);
+''',
+ [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]);
}
void test_returnOfInvalidType_async_future_int_mismatches_int() {
- Source source = addSource('''
+ assertErrorsInCode(
+ '''
int f() async {
return 5;
}
-''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [
- StaticTypeWarningCode.RETURN_OF_INVALID_TYPE,
- StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE
- ]);
- verify([source]);
+''',
+ [
+ StaticTypeWarningCode.RETURN_OF_INVALID_TYPE,
+ StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE
+ ]);
}
void test_returnOfInvalidType_expressionFunctionBody_function() {
- Source source = addSource("int f() => '0';");
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]);
- verify([source]);
+ assertErrorsInCode(
+ "int f() => '0';", [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]);
}
void test_returnOfInvalidType_expressionFunctionBody_getter() {
- Source source = addSource("int get g => '0';");
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]);
- verify([source]);
+ assertErrorsInCode(
+ "int get g => '0';", [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]);
}
void test_returnOfInvalidType_expressionFunctionBody_localFunction() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {
String m() {
int f() => '0';
return '0';
}
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]);
}
void test_returnOfInvalidType_expressionFunctionBody_method() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {
int f() => '0';
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]);
}
void test_returnOfInvalidType_expressionFunctionBody_void() {
- Source source = addSource("void f() => 42;");
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]);
- verify([source]);
+ assertErrorsInCode(
+ "void f() => 42;", [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]);
}
void test_returnOfInvalidType_function() {
- Source source = addSource("int f() { return '0'; }");
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]);
- verify([source]);
+ assertErrorsInCode("int f() { return '0'; }",
+ [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]);
}
void test_returnOfInvalidType_getter() {
- Source source = addSource("int get g { return '0'; }");
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]);
- verify([source]);
+ assertErrorsInCode("int get g { return '0'; }",
+ [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]);
}
void test_returnOfInvalidType_localFunction() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {
String m() {
int f() { return '0'; }
return '0';
}
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]);
}
void test_returnOfInvalidType_method() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {
int f() { return '0'; }
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]);
}
// https://github.com/dart-lang/sdk/issues/24713
void test_returnOfInvalidType_not_issued_for_valid_generic_return() {
- Source source = addSource(r'''
+ assertNoErrorsInCode(r'''
abstract class F<T, U> {
U get value;
}
@@ -958,321 +872,296 @@ abstract class H<S> {
}
void main() { }''');
- computeLibrarySourceErrors(source);
- assertNoErrors(source);
- verify([source]);
}
void test_returnOfInvalidType_void() {
- Source source = addSource("void f() { return 42; }");
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]);
- verify([source]);
+ assertErrorsInCode("void f() { return 42; }",
+ [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]);
}
void test_typeArgumentNotMatchingBounds_classTypeAlias() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {}
class B {}
class C {}
class G<E extends A> {}
-class D = G<B> with C;''');
- computeLibrarySourceErrors(source);
- assertErrors(
- source, [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]);
- verify([source]);
+class D = G<B> with C;
+''',
+ [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]);
}
void test_typeArgumentNotMatchingBounds_extends() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {}
class B {}
class G<E extends A> {}
-class C extends G<B>{}''');
- computeLibrarySourceErrors(source);
- assertErrors(
- source, [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]);
- verify([source]);
+class C extends G<B>{}
+''',
+ [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]);
}
void test_typeArgumentNotMatchingBounds_extends_regressionInIssue18468Fix() {
// https://code.google.com/p/dart/issues/detail?id=18628
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class X<T extends Type> {}
-class Y<U> extends X<U> {}''');
- computeLibrarySourceErrors(source);
- assertErrors(
- source, [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]);
- verify([source]);
+class Y<U> extends X<U> {}
+''',
+ [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]);
}
void test_typeArgumentNotMatchingBounds_fieldFormalParameter() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {}
class B {}
class G<E extends A> {}
class C {
var f;
C(G<B> this.f) {}
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(
- source, [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]);
}
void test_typeArgumentNotMatchingBounds_functionReturnType() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {}
class B {}
class G<E extends A> {}
-G<B> f() { return null; }''');
- computeLibrarySourceErrors(source);
- assertErrors(
- source, [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]);
- verify([source]);
+G<B> f() { return null; }
+''',
+ [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]);
}
void test_typeArgumentNotMatchingBounds_functionTypeAlias() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {}
class B {}
class G<E extends A> {}
-typedef G<B> f();''');
- computeLibrarySourceErrors(source);
- assertErrors(
- source, [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]);
- verify([source]);
+typedef G<B> f();
+''',
+ [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]);
}
void test_typeArgumentNotMatchingBounds_functionTypedFormalParameter() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {}
class B {}
class G<E extends A> {}
-f(G<B> h()) {}''');
- computeLibrarySourceErrors(source);
- assertErrors(
- source, [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]);
- verify([source]);
+f(G<B> h()) {}
+''',
+ [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]);
}
void test_typeArgumentNotMatchingBounds_implements() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {}
class B {}
class G<E extends A> {}
-class C implements G<B>{}''');
- computeLibrarySourceErrors(source);
- assertErrors(
- source, [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]);
- verify([source]);
+class C implements G<B>{}
+''',
+ [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]);
}
void test_typeArgumentNotMatchingBounds_is() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {}
class B {}
class G<E extends A> {}
-var b = 1 is G<B>;''');
- computeLibrarySourceErrors(source);
- assertErrors(
- source, [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]);
- verify([source]);
+var b = 1 is G<B>;
+''',
+ [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]);
}
void test_typeArgumentNotMatchingBounds_methodReturnType() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {}
class B {}
class G<E extends A> {}
class C {
G<B> m() { return null; }
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(
- source, [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]);
}
void test_typeArgumentNotMatchingBounds_new() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {}
class B {}
class G<E extends A> {}
-f() { return new G<B>(); }''');
- computeLibrarySourceErrors(source);
- assertErrors(
- source, [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]);
- verify([source]);
+f() { return new G<B>(); }
+''',
+ [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]);
}
void test_typeArgumentNotMatchingBounds_new_superTypeOfUpperBound() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {}
class B extends A {}
class C extends B {}
class G<E extends B> {}
-f() { return new G<A>(); }''');
- computeLibrarySourceErrors(source);
- assertErrors(
- source, [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]);
- verify([source]);
+f() { return new G<A>(); }
+''',
+ [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]);
}
void test_typeArgumentNotMatchingBounds_parameter() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {}
class B {}
class G<E extends A> {}
-f(G<B> g) {}''');
- computeLibrarySourceErrors(source);
- assertErrors(
- source, [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]);
- verify([source]);
+f(G<B> g) {}
+''',
+ [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]);
}
void test_typeArgumentNotMatchingBounds_redirectingConstructor() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {}
class B {}
class X<T extends A> {
X(int x, int y) {}
factory X.name(int x, int y) = X<B>;
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [
- StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS,
- StaticWarningCode.REDIRECT_TO_INVALID_RETURN_TYPE
- ]);
- verify([source]);
+}''',
+ [
+ StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS,
+ StaticWarningCode.REDIRECT_TO_INVALID_RETURN_TYPE
+ ]);
}
void test_typeArgumentNotMatchingBounds_typeArgumentList() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {}
class B {}
class C<E> {}
class D<E extends A> {}
-C<D<B>> Var;''');
- computeLibrarySourceErrors(source);
- assertErrors(
- source, [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]);
- verify([source]);
+C<D<B>> Var;
+''',
+ [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]);
}
void test_typeArgumentNotMatchingBounds_typeParameter() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {}
class B {}
class C {}
class G<E extends A> {}
-class D<F extends G<B>> {}''');
- computeLibrarySourceErrors(source);
- assertErrors(
- source, [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]);
- verify([source]);
+class D<F extends G<B>> {}
+''',
+ [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]);
}
void test_typeArgumentNotMatchingBounds_variableDeclaration() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {}
class B {}
class G<E extends A> {}
-G<B> g;''');
- computeLibrarySourceErrors(source);
- assertErrors(
- source, [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]);
- verify([source]);
+G<B> g;
+''',
+ [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]);
}
void test_typeArgumentNotMatchingBounds_with() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {}
class B {}
class G<E extends A> {}
-class C extends Object with G<B>{}''');
- computeLibrarySourceErrors(source);
- assertErrors(
- source, [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]);
- verify([source]);
+class C extends Object with G<B>{}
+''',
+ [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]);
}
void test_typeParameterSupertypeOfItsBound() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A<T extends T> {
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(
- source, [StaticTypeWarningCode.TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND]);
- verify([source]);
+}
+''',
+ [StaticTypeWarningCode.TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND]);
}
void
test_typePromotion_booleanAnd_useInRight_accessedInClosureRight_mutated() {
- Source source = addSource(r'''
+ assertErrorsInUnverifiedCode(
+ r'''
callMe(f()) { f(); }
main(Object p) {
(p is String) && callMe(() { p.length; });
p = 0;
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_GETTER]);
+}''',
+ [StaticTypeWarningCode.UNDEFINED_GETTER]);
}
void test_typePromotion_booleanAnd_useInRight_mutatedInLeft() {
- Source source = addSource(r'''
+ assertErrorsInUnverifiedCode(
+ r'''
main(Object p) {
((p is String) && ((p = 42) == 42)) && p.length != 0;
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_GETTER]);
+}''',
+ [StaticTypeWarningCode.UNDEFINED_GETTER]);
}
void test_typePromotion_booleanAnd_useInRight_mutatedInRight() {
- Source source = addSource(r'''
+ assertErrorsInUnverifiedCode(
+ r'''
main(Object p) {
(p is String) && (((p = 42) == 42) && p.length != 0);
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_GETTER]);
+}''',
+ [StaticTypeWarningCode.UNDEFINED_GETTER]);
}
void
test_typePromotion_conditional_useInThen_accessedInClosure_hasAssignment_after() {
- Source source = addSource(r'''
+ assertErrorsInUnverifiedCode(
+ r'''
callMe(f()) { f(); }
main(Object p) {
p is String ? callMe(() { p.length; }) : 0;
p = 42;
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_GETTER]);
+}''',
+ [StaticTypeWarningCode.UNDEFINED_GETTER]);
}
void
test_typePromotion_conditional_useInThen_accessedInClosure_hasAssignment_before() {
- Source source = addSource(r'''
+ assertErrorsInUnverifiedCode(
+ r'''
callMe(f()) { f(); }
main(Object p) {
p = 42;
p is String ? callMe(() { p.length; }) : 0;
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_GETTER]);
+}''',
+ [StaticTypeWarningCode.UNDEFINED_GETTER]);
}
void test_typePromotion_conditional_useInThen_hasAssignment() {
- Source source = addSource(r'''
+ assertErrorsInUnverifiedCode(
+ r'''
main(Object p) {
p is String ? (p.length + (p = 42)) : 0;
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_GETTER]);
+}''',
+ [StaticTypeWarningCode.UNDEFINED_GETTER]);
}
void test_typePromotion_if_accessedInClosure_hasAssignment() {
- Source source = addSource(r'''
+ assertErrorsInUnverifiedCode(
+ r'''
callMe(f()) { f(); }
main(Object p) {
if (p is String) {
@@ -1281,24 +1170,24 @@ main(Object p) {
});
}
p = 0;
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_GETTER]);
+}''',
+ [StaticTypeWarningCode.UNDEFINED_GETTER]);
}
void test_typePromotion_if_and_right_hasAssignment() {
- Source source = addSource(r'''
+ assertErrorsInUnverifiedCode(
+ r'''
main(Object p) {
if (p is String && (p = null) == null) {
p.length;
}
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_GETTER]);
+}''',
+ [StaticTypeWarningCode.UNDEFINED_GETTER]);
}
void test_typePromotion_if_extends_notMoreSpecific_dynamic() {
- Source source = addSource(r'''
+ assertErrorsInUnverifiedCode(
+ r'''
class V {}
class A<T> {}
class B<S> extends A<S> {
@@ -1309,13 +1198,13 @@ main(A<V> p) {
if (p is B) {
p.b;
}
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_GETTER]);
+}''',
+ [StaticTypeWarningCode.UNDEFINED_GETTER]);
}
void test_typePromotion_if_extends_notMoreSpecific_notMoreSpecificTypeArg() {
- Source source = addSource(r'''
+ assertErrorsInUnverifiedCode(
+ r'''
class V {}
class A<T> {}
class B<S> extends A<S> {
@@ -1326,85 +1215,85 @@ main(A<V> p) {
if (p is B<int>) {
p.b;
}
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_GETTER]);
+}''',
+ [StaticTypeWarningCode.UNDEFINED_GETTER]);
}
void test_typePromotion_if_hasAssignment_after() {
- Source source = addSource(r'''
+ assertErrorsInUnverifiedCode(
+ r'''
main(Object p) {
if (p is String) {
p.length;
p = 0;
}
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_GETTER]);
+}''',
+ [StaticTypeWarningCode.UNDEFINED_GETTER]);
}
void test_typePromotion_if_hasAssignment_before() {
- Source source = addSource(r'''
+ assertErrorsInUnverifiedCode(
+ r'''
main(Object p) {
if (p is String) {
p = 0;
p.length;
}
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_GETTER]);
+}''',
+ [StaticTypeWarningCode.UNDEFINED_GETTER]);
}
void test_typePromotion_if_hasAssignment_inClosure_anonymous_after() {
- Source source = addSource(r'''
+ assertErrorsInUnverifiedCode(
+ r'''
main(Object p) {
if (p is String) {
p.length;
}
() {p = 0;};
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_GETTER]);
+}''',
+ [StaticTypeWarningCode.UNDEFINED_GETTER]);
}
void test_typePromotion_if_hasAssignment_inClosure_anonymous_before() {
- Source source = addSource(r'''
+ assertErrorsInUnverifiedCode(
+ r'''
main(Object p) {
() {p = 0;};
if (p is String) {
p.length;
}
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_GETTER]);
+}''',
+ [StaticTypeWarningCode.UNDEFINED_GETTER]);
}
void test_typePromotion_if_hasAssignment_inClosure_function_after() {
- Source source = addSource(r'''
+ assertErrorsInUnverifiedCode(
+ r'''
main(Object p) {
if (p is String) {
p.length;
}
f() {p = 0;};
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_GETTER]);
+}''',
+ [StaticTypeWarningCode.UNDEFINED_GETTER]);
}
void test_typePromotion_if_hasAssignment_inClosure_function_before() {
- Source source = addSource(r'''
+ assertErrorsInUnverifiedCode(
+ r'''
main(Object p) {
f() {p = 0;};
if (p is String) {
p.length;
}
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_GETTER]);
+}''',
+ [StaticTypeWarningCode.UNDEFINED_GETTER]);
}
void test_typePromotion_if_implements_notMoreSpecific_dynamic() {
- Source source = addSource(r'''
+ assertErrorsInUnverifiedCode(
+ r'''
class V {}
class A<T> {}
class B<S> implements A<S> {
@@ -1415,13 +1304,13 @@ main(A<V> p) {
if (p is B) {
p.b;
}
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_GETTER]);
+}''',
+ [StaticTypeWarningCode.UNDEFINED_GETTER]);
}
void test_typePromotion_if_with_notMoreSpecific_dynamic() {
- Source source = addSource(r'''
+ assertErrorsInUnverifiedCode(
+ r'''
class V {}
class A<T> {}
class B<S> extends Object with A<S> {
@@ -1432,30 +1321,29 @@ main(A<V> p) {
if (p is B) {
p.b;
}
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_GETTER]);
+}''',
+ [StaticTypeWarningCode.UNDEFINED_GETTER]);
}
void test_undefinedFunction() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
void f() {
g();
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_FUNCTION]);
+}''',
+ [StaticTypeWarningCode.UNDEFINED_FUNCTION]);
}
void test_undefinedFunction_inCatch() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
void f() {
try {
} on Object {
g();
}
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_FUNCTION]);
+}''',
+ [StaticTypeWarningCode.UNDEFINED_FUNCTION]);
}
void test_undefinedFunction_inImportedLib() {
@@ -1472,11 +1360,11 @@ h() {}''');
}
void test_undefinedGetter() {
- Source source = addSource(r'''
+ assertErrorsInUnverifiedCode(
+ r'''
class T {}
-f(T e) { return e.m; }''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_GETTER]);
+f(T e) { return e.m; }''',
+ [StaticTypeWarningCode.UNDEFINED_GETTER]);
}
void test_undefinedGetter_generic_function_call() {
@@ -1486,30 +1374,31 @@ f(T e) { return e.m; }''');
AnalysisOptionsImpl options = new AnalysisOptionsImpl();
options.enableStrictCallChecks = true;
resetWithOptions(options);
- Source source = addSource('''
+ assertErrorsInUnverifiedCode(
+ '''
f(Function f) {
return f.call;
}
-''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_GETTER]);
+''',
+ [StaticTypeWarningCode.UNDEFINED_GETTER]);
}
void test_undefinedGetter_object_call() {
AnalysisOptionsImpl options = new AnalysisOptionsImpl();
options.enableStrictCallChecks = true;
resetWithOptions(options);
- Source source = addSource('''
+ assertErrorsInUnverifiedCode(
+ '''
f(Object o) {
return o.call;
}
-''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_GETTER]);
+''',
+ [StaticTypeWarningCode.UNDEFINED_GETTER]);
}
void test_undefinedGetter_proxy_annotation_fakeProxy() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
library L;
class Fake {
const Fake();
@@ -1518,115 +1407,109 @@ const proxy = const Fake();
@proxy class PrefixProxy {}
main() {
new PrefixProxy().foo;
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_GETTER]);
+}''',
+ [StaticTypeWarningCode.UNDEFINED_GETTER]);
}
void test_undefinedGetter_static() {
- Source source = addSource(r'''
+ assertErrorsInUnverifiedCode(
+ r'''
class A {}
-var a = A.B;''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_GETTER]);
+var a = A.B;''',
+ [StaticTypeWarningCode.UNDEFINED_GETTER]);
}
void test_undefinedGetter_typeLiteral_cascadeTarget() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class T {
static int get foo => 42;
}
main() {
T..foo;
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_GETTER]);
+}''',
+ [StaticTypeWarningCode.UNDEFINED_GETTER]);
}
void test_undefinedGetter_typeLiteral_conditionalAccess() {
// When applied to a type literal, the conditional access operator '?.'
// cannot be used to access instance getters of Type.
- Source source = addSource('''
+ assertErrorsInCode(
+ '''
class A {}
f() => A?.hashCode;
-''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_GETTER]);
+''',
+ [StaticTypeWarningCode.UNDEFINED_GETTER]);
}
void test_undefinedGetter_void() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class T {
void m() {}
}
-f(T e) { return e.m().f; }''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_GETTER]);
+f(T e) { return e.m().f; }''',
+ [StaticTypeWarningCode.UNDEFINED_GETTER]);
}
void test_undefinedGetter_wrongNumberOfTypeArguments_tooLittle() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A<K, V> {
K element;
}
main(A<int> a) {
a.element.anyGetterExistsInDynamic;
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(
- source, [StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]);
}
void test_undefinedGetter_wrongNumberOfTypeArguments_tooMany() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A<E> {
E element;
}
main(A<int,int> a) {
a.element.anyGetterExistsInDynamic;
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(
- source, [StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]);
}
void test_undefinedGetter_wrongOfTypeArgument() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A<E> {
E element;
}
main(A<NoSuchType> a) {
a.element.anyGetterExistsInDynamic;
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT]);
}
void test_undefinedMethod() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {
void m() {
n();
}
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_METHOD]);
+}''',
+ [StaticTypeWarningCode.UNDEFINED_METHOD]);
}
void test_undefinedMethod_assignmentExpression() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {}
class B {
f(A a) {
A a2 = new A();
a += a2;
}
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_METHOD]);
+}''',
+ [StaticTypeWarningCode.UNDEFINED_METHOD]);
}
void test_undefinedMethod_generic_function_call() {
@@ -1636,17 +1519,18 @@ class B {
AnalysisOptionsImpl options = new AnalysisOptionsImpl();
options.enableStrictCallChecks = true;
resetWithOptions(options);
- Source source = addSource('''
+ assertErrorsInCode(
+ '''
f(Function f) {
f.call();
}
-''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_METHOD]);
+''',
+ [StaticTypeWarningCode.UNDEFINED_METHOD]);
}
void test_undefinedMethod_ignoreTypePropagation() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {}
class B extends A {
m() {}
@@ -1656,28 +1540,26 @@ class C {
A a = new B();
a.m();
}
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_METHOD]);
+}''',
+ [StaticTypeWarningCode.UNDEFINED_METHOD]);
}
void test_undefinedMethod_leastUpperBoundWithNull() {
- Source source = addSource('f(bool b, int i) => (b ? null : i).foo();');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_METHOD]);
+ assertErrorsInCode('f(bool b, int i) => (b ? null : i).foo();',
+ [StaticTypeWarningCode.UNDEFINED_METHOD]);
}
void test_undefinedMethod_object_call() {
AnalysisOptionsImpl options = new AnalysisOptionsImpl();
options.enableStrictCallChecks = true;
resetWithOptions(options);
- Source source = addSource('''
+ assertErrorsInCode(
+ '''
f(Object o) {
o.call();
}
-''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_METHOD]);
+''',
+ [StaticTypeWarningCode.UNDEFINED_METHOD]);
}
void test_undefinedMethod_private() {
@@ -1688,19 +1570,20 @@ library lib;
class A {
_foo() {}
}''');
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
import 'lib.dart';
class B extends A {
test() {
_foo();
}
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_METHOD]);
+}''',
+ [StaticTypeWarningCode.UNDEFINED_METHOD]);
}
void test_undefinedMethod_proxy_annotation_fakeProxy() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
library L;
class Fake {
const Fake();
@@ -1709,230 +1592,229 @@ const proxy = const Fake();
@proxy class PrefixProxy {}
main() {
new PrefixProxy().foo();
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_METHOD]);
+}''',
+ [StaticTypeWarningCode.UNDEFINED_METHOD]);
}
void test_undefinedMethod_typeLiteral_cascadeTarget() {
- Source source = addSource('''
+ assertErrorsInCode(
+ '''
class T {
static void foo() {}
}
main() {
T..foo();
}
-''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_METHOD]);
+''',
+ [StaticTypeWarningCode.UNDEFINED_METHOD]);
}
void test_undefinedMethod_typeLiteral_conditionalAccess() {
// When applied to a type literal, the conditional access operator '?.'
// cannot be used to access instance methods of Type.
- Source source = addSource('''
+ assertErrorsInCode(
+ '''
class A {}
f() => A?.toString();
-''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_METHOD]);
+''',
+ [StaticTypeWarningCode.UNDEFINED_METHOD]);
}
void test_undefinedMethodWithConstructor() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class C {
C.m();
}
f() {
C c = C.m();
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(
- source, [StaticTypeWarningCode.UNDEFINED_METHOD_WITH_CONSTRUCTOR]);
+}''',
+ [StaticTypeWarningCode.UNDEFINED_METHOD_WITH_CONSTRUCTOR]);
}
void test_undefinedOperator_indexBoth() {
- Source source = addSource(r'''
+ assertErrorsInUnverifiedCode(
+ r'''
class A {}
f(A a) {
a[0]++;
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
+}''',
+ [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
}
void test_undefinedOperator_indexGetter() {
- Source source = addSource(r'''
+ assertErrorsInUnverifiedCode(
+ r'''
class A {}
f(A a) {
a[0];
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
+}''',
+ [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
}
void test_undefinedOperator_indexSetter() {
- Source source = addSource(r'''
+ assertErrorsInUnverifiedCode(
+ r'''
class A {}
f(A a) {
a[0] = 1;
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
+}''',
+ [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
}
void test_undefinedOperator_plus() {
- Source source = addSource(r'''
+ assertErrorsInUnverifiedCode(
+ r'''
class A {}
f(A a) {
a + 1;
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
+}''',
+ [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
}
void test_undefinedOperator_postfixExpression() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {}
f(A a) {
a++;
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
+}''',
+ [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
}
void test_undefinedOperator_prefixExpression() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {}
f(A a) {
++a;
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
+}''',
+ [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
}
void test_undefinedSetter() {
- Source source = addSource(r'''
+ assertErrorsInUnverifiedCode(
+ r'''
class T {}
-f(T e1) { e1.m = 0; }''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_SETTER]);
+f(T e1) { e1.m = 0; }''',
+ [StaticTypeWarningCode.UNDEFINED_SETTER]);
}
void test_undefinedSetter_static() {
- Source source = addSource(r'''
+ assertErrorsInUnverifiedCode(
+ r'''
class A {}
-f() { A.B = 0;}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_SETTER]);
+f() { A.B = 0;}''',
+ [StaticTypeWarningCode.UNDEFINED_SETTER]);
}
void test_undefinedSetter_typeLiteral_cascadeTarget() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class T {
static void set foo(_) {}
}
main() {
T..foo = 42;
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_SETTER]);
+}''',
+ [StaticTypeWarningCode.UNDEFINED_SETTER]);
}
void test_undefinedSetter_void() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class T {
void m() {}
}
-f(T e) { e.m().f = 0; }''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_SETTER]);
+f(T e) { e.m().f = 0; }''',
+ [StaticTypeWarningCode.UNDEFINED_SETTER]);
}
void test_undefinedSuperGetter() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {}
class B extends A {
get g {
return super.g;
}
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_SUPER_GETTER]);
+}''',
+ [StaticTypeWarningCode.UNDEFINED_SUPER_GETTER]);
}
void test_undefinedSuperMethod() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {}
class B extends A {
m() { return super.m(); }
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_SUPER_METHOD]);
+}''',
+ [StaticTypeWarningCode.UNDEFINED_SUPER_METHOD]);
}
void test_undefinedSuperOperator_binaryExpression() {
- Source source = addSource(r'''
+ assertErrorsInUnverifiedCode(
+ r'''
class A {}
class B extends A {
operator +(value) {
return super + value;
}
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_SUPER_OPERATOR]);
+}''',
+ [StaticTypeWarningCode.UNDEFINED_SUPER_OPERATOR]);
}
void test_undefinedSuperOperator_indexBoth() {
- Source source = addSource(r'''
+ assertErrorsInUnverifiedCode(
+ r'''
class A {}
class B extends A {
operator [](index) {
return super[index]++;
}
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_SUPER_OPERATOR]);
+}''',
+ [StaticTypeWarningCode.UNDEFINED_SUPER_OPERATOR]);
}
void test_undefinedSuperOperator_indexGetter() {
- Source source = addSource(r'''
+ assertErrorsInUnverifiedCode(
+ r'''
class A {}
class B extends A {
operator [](index) {
return super[index + 1];
}
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_SUPER_OPERATOR]);
+}''',
+ [StaticTypeWarningCode.UNDEFINED_SUPER_OPERATOR]);
}
void test_undefinedSuperOperator_indexSetter() {
- Source source = addSource(r'''
+ assertErrorsInUnverifiedCode(
+ r'''
class A {}
class B extends A {
operator []=(index, value) {
return super[index] = 0;
}
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_SUPER_OPERATOR]);
+}''',
+ [StaticTypeWarningCode.UNDEFINED_SUPER_OPERATOR]);
}
void test_undefinedSuperSetter() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {}
class B extends A {
f() {
super.m = 0;
}
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.UNDEFINED_SUPER_SETTER]);
+}''',
+ [StaticTypeWarningCode.UNDEFINED_SUPER_SETTER]);
}
void test_unqualifiedReferenceToNonLocalStaticMember_getter() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {
static int get a => 0;
}
@@ -1940,16 +1822,15 @@ class B extends A {
int b() {
return a;
}
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [
- StaticTypeWarningCode.UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER
- ]);
- verify([source]);
+}''',
+ [
+ StaticTypeWarningCode.UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER
+ ]);
}
void test_unqualifiedReferenceToNonLocalStaticMember_method() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {
static void a() {}
}
@@ -1957,16 +1838,15 @@ class B extends A {
void b() {
a();
}
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [
- StaticTypeWarningCode.UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER
- ]);
- verify([source]);
+}''',
+ [
+ StaticTypeWarningCode.UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER
+ ]);
}
void test_unqualifiedReferenceToNonLocalStaticMember_setter() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {
static set a(x) {}
}
@@ -1974,94 +1854,88 @@ class B extends A {
b(y) {
a = y;
}
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [
- StaticTypeWarningCode.UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER
- ]);
- verify([source]);
+}''',
+ [
+ StaticTypeWarningCode.UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER
+ ]);
}
void test_wrongNumberOfTypeArguments_classAlias() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {}
class M {}
-class B<F extends num> = A<F> with M;''');
- computeLibrarySourceErrors(source);
- assertErrors(
- source, [StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]);
- verify([source]);
+class B<F extends num> = A<F> with M;''',
+ [StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]);
}
void test_wrongNumberOfTypeArguments_tooFew() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A<E, F> {}
-A<A> a = null;''');
- computeLibrarySourceErrors(source);
- assertErrors(
- source, [StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]);
- verify([source]);
+A<A> a = null;''',
+ [StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]);
}
void test_wrongNumberOfTypeArguments_tooMany() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A<E> {}
-A<A, A> a = null;''');
- computeLibrarySourceErrors(source);
- assertErrors(
- source, [StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]);
- verify([source]);
+A<A, A> a = null;''',
+ [StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]);
}
void test_wrongNumberOfTypeArguments_typeTest_tooFew() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {}
class C<K, V> {}
f(p) {
return p is C<A>;
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(
- source, [StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]);
}
void test_wrongNumberOfTypeArguments_typeTest_tooMany() {
- Source source = addSource(r'''
+ assertErrorsInCode(
+ r'''
class A {}
class C<E> {}
f(p) {
return p is C<A, A>;
-}''');
- computeLibrarySourceErrors(source);
- assertErrors(
- source, [StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]);
- verify([source]);
+}''',
+ [StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]);
}
void test_forIn_notIterable() {
- assertErrorsInCode('''
+ assertErrorsInCode(
+ '''
f() {
for (var i in true) {}
}
-''', [StaticTypeWarningCode.FOR_IN_OF_INVALID_TYPE]);
+''',
+ [StaticTypeWarningCode.FOR_IN_OF_INVALID_TYPE]);
}
void test_forIn_declaredVariableWrongType() {
- assertErrorsInCode('''
+ assertErrorsInCode(
+ '''
f() {
for (int i in <String>[]) {}
}
-''', [StaticTypeWarningCode.FOR_IN_OF_INVALID_ELEMENT_TYPE]);
+''',
+ [StaticTypeWarningCode.FOR_IN_OF_INVALID_ELEMENT_TYPE]);
}
void test_forIn_existingVariableWrongType() {
- assertErrorsInCode('''
+ assertErrorsInCode(
+ '''
f() {
int i;
for (i in <String>[]) {}
}
-''', [StaticTypeWarningCode.FOR_IN_OF_INVALID_ELEMENT_TYPE]);
+''',
+ [StaticTypeWarningCode.FOR_IN_OF_INVALID_ELEMENT_TYPE]);
}
void test_forIn_declaredVariableRightType() {
@@ -2123,13 +1997,15 @@ f() {
}
void test_forIn_typeBoundBad() {
- assertErrorsInCode('''
+ assertErrorsInCode(
+ '''
class Foo<T extends Iterable<int>> {
void method(T iterable) {
for (String i in iterable) {}
}
}
-''', [StaticTypeWarningCode.FOR_IN_OF_INVALID_ELEMENT_TYPE]);
+''',
+ [StaticTypeWarningCode.FOR_IN_OF_INVALID_ELEMENT_TYPE]);
}
void test_forIn_typeBoundGood() {
@@ -2143,32 +2019,38 @@ class Foo<T extends Iterable<int>> {
}
void test_awaitForIn_notStream() {
- assertErrorsInCode('''
+ assertErrorsInCode(
+ '''
f() async {
await for (var i in true) {}
}
-''', [StaticTypeWarningCode.FOR_IN_OF_INVALID_TYPE]);
+''',
+ [StaticTypeWarningCode.FOR_IN_OF_INVALID_TYPE]);
}
void test_awaitForIn_declaredVariableWrongType() {
- assertErrorsInCode('''
+ assertErrorsInCode(
+ '''
import 'dart:async';
f() async {
Stream<String> stream;
await for (int i in stream) {}
}
-''', [StaticTypeWarningCode.FOR_IN_OF_INVALID_ELEMENT_TYPE]);
+''',
+ [StaticTypeWarningCode.FOR_IN_OF_INVALID_ELEMENT_TYPE]);
}
void test_awaitForIn_existingVariableWrongType() {
- assertErrorsInCode('''
+ assertErrorsInCode(
+ '''
import 'dart:async';
f() async {
Stream<String> stream;
int i;
await for (i in stream) {}
}
-''', [StaticTypeWarningCode.FOR_IN_OF_INVALID_ELEMENT_TYPE]);
+''',
+ [StaticTypeWarningCode.FOR_IN_OF_INVALID_ELEMENT_TYPE]);
}
void test_awaitForIn_declaredVariableRightType() {
@@ -2242,130 +2124,120 @@ f() async {
}
void test_yield_async_to_basic_type() {
- Source source = addSource('''
+ assertErrorsInCode(
+ '''
int f() async* {
yield 3;
}
-''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [
- StaticTypeWarningCode.YIELD_OF_INVALID_TYPE,
- StaticTypeWarningCode.ILLEGAL_ASYNC_GENERATOR_RETURN_TYPE
- ]);
- verify([source]);
+''',
+ [
+ StaticTypeWarningCode.YIELD_OF_INVALID_TYPE,
+ StaticTypeWarningCode.ILLEGAL_ASYNC_GENERATOR_RETURN_TYPE
+ ]);
}
void test_yield_async_to_iterable() {
- Source source = addSource('''
+ assertErrorsInCode(
+ '''
Iterable<int> f() async* {
yield 3;
}
-''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [
- StaticTypeWarningCode.YIELD_OF_INVALID_TYPE,
- StaticTypeWarningCode.ILLEGAL_ASYNC_GENERATOR_RETURN_TYPE
- ]);
- verify([source]);
+''',
+ [
+ StaticTypeWarningCode.YIELD_OF_INVALID_TYPE,
+ StaticTypeWarningCode.ILLEGAL_ASYNC_GENERATOR_RETURN_TYPE
+ ]);
}
void test_yield_async_to_mistyped_stream() {
- Source source = addSource('''
+ assertErrorsInCode(
+ '''
import 'dart:async';
Stream<int> f() async* {
yield "foo";
}
-''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.YIELD_OF_INVALID_TYPE]);
- verify([source]);
+''',
+ [StaticTypeWarningCode.YIELD_OF_INVALID_TYPE]);
}
void test_yield_each_async_non_stream() {
- Source source = addSource('''
+ assertErrorsInCode(
+ '''
f() async* {
yield* 0;
}
-''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.YIELD_OF_INVALID_TYPE]);
- verify([source]);
+''',
+ [StaticTypeWarningCode.YIELD_OF_INVALID_TYPE]);
}
void test_yield_each_async_to_mistyped_stream() {
- Source source = addSource('''
+ assertErrorsInCode(
+ '''
import 'dart:async';
Stream<int> f() async* {
yield* g();
}
Stream<String> g() => null;
-''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.YIELD_OF_INVALID_TYPE]);
- verify([source]);
+''',
+ [StaticTypeWarningCode.YIELD_OF_INVALID_TYPE]);
}
void test_yield_each_sync_non_iterable() {
- Source source = addSource('''
+ assertErrorsInCode(
+ '''
f() sync* {
yield* 0;
}
-''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.YIELD_OF_INVALID_TYPE]);
- verify([source]);
+''',
+ [StaticTypeWarningCode.YIELD_OF_INVALID_TYPE]);
}
void test_yield_each_sync_to_mistyped_iterable() {
- Source source = addSource('''
+ assertErrorsInCode(
+ '''
Iterable<int> f() sync* {
yield* g();
}
Iterable<String> g() => null;
-''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.YIELD_OF_INVALID_TYPE]);
- verify([source]);
+''',
+ [StaticTypeWarningCode.YIELD_OF_INVALID_TYPE]);
}
void test_yield_sync_to_basic_type() {
- Source source = addSource('''
+ assertErrorsInCode(
+ '''
int f() sync* {
yield 3;
}
-''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [
- StaticTypeWarningCode.YIELD_OF_INVALID_TYPE,
- StaticTypeWarningCode.ILLEGAL_SYNC_GENERATOR_RETURN_TYPE
- ]);
- verify([source]);
+''',
+ [
+ StaticTypeWarningCode.YIELD_OF_INVALID_TYPE,
+ StaticTypeWarningCode.ILLEGAL_SYNC_GENERATOR_RETURN_TYPE
+ ]);
}
void test_yield_sync_to_mistyped_iterable() {
- Source source = addSource('''
+ assertErrorsInCode(
+ '''
Iterable<int> f() sync* {
yield "foo";
}
-''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [StaticTypeWarningCode.YIELD_OF_INVALID_TYPE]);
- verify([source]);
+''',
+ [StaticTypeWarningCode.YIELD_OF_INVALID_TYPE]);
}
void test_yield_sync_to_stream() {
- Source source = addSource('''
+ assertErrorsInCode(
+ '''
import 'dart:async';
Stream<int> f() sync* {
yield 3;
}
-''');
- computeLibrarySourceErrors(source);
- assertErrors(source, [
- StaticTypeWarningCode.YIELD_OF_INVALID_TYPE,
- StaticTypeWarningCode.ILLEGAL_SYNC_GENERATOR_RETURN_TYPE
- ]);
- verify([source]);
+''',
+ [
+ StaticTypeWarningCode.YIELD_OF_INVALID_TYPE,
+ StaticTypeWarningCode.ILLEGAL_SYNC_GENERATOR_RETURN_TYPE
+ ]);
}
}
« no previous file with comments | « pkg/analyzer/test/generated/resolver_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698