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

Unified Diff: pkg/analyzer/test/src/summary/top_level_inference_test.dart

Issue 2782533002: Report errors for the new top-level inference rules. (Closed)
Patch Set: Update language_strong status for analyzer. Created 3 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/src/summary/resynthesize_ast_test.dart ('k') | pkg/analyzer/test/src/task/dart_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/test/src/summary/top_level_inference_test.dart
diff --git a/pkg/analyzer/test/src/summary/top_level_inference_test.dart b/pkg/analyzer/test/src/summary/top_level_inference_test.dart
index 7d2be5059875cc4443e6f82f9e91629f0e8eca61..999e1ceb2e3fffc6ce8d9b30fff3d7772f86d5a3 100644
--- a/pkg/analyzer/test/src/summary/top_level_inference_test.dart
+++ b/pkg/analyzer/test/src/summary/top_level_inference_test.dart
@@ -9,11 +9,13 @@ import 'package:analyzer/src/dart/analysis/driver.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../dart/analysis/base.dart';
+import '../task/strong/strong_test_helper.dart';
import 'element_text.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(TopLevelInferenceTest);
+ defineReflectiveTests(TopLevelInferenceErrorsTest);
// defineReflectiveTests(ApplyCheckElementTextReplacements);
});
}
@@ -26,6 +28,326 @@ class ApplyCheckElementTextReplacements {
}
@reflectiveTest
+class TopLevelInferenceErrorsTest extends AbstractStrongTest {
+ @override
+ bool get enableNewAnalysisDriver => true;
+
+ test_initializer_additive() async {
+ await _assertErrorOnlyLeft(['+', '-']);
+ }
+
+ test_initializer_assign() async {
+ var content = r'''
+var a = 1;
+var t1 = /*error:TOP_LEVEL_UNSUPPORTED*/a += 1;
+var t2 = (/*error:TOP_LEVEL_UNSUPPORTED*/a = 2);
+''';
+ await checkFile(content);
+ }
+
+ test_initializer_binary_onlyLeft() async {
+ var content = r'''
+var a = 1;
+var t = (/*error:TOP_LEVEL_UNSUPPORTED*/a = 1) + (a = 2);
+''';
+ await checkFile(content);
+ }
+
+ test_initializer_bitwise() async {
+ await _assertErrorOnlyLeft(['&', '|', '^']);
+ }
+
+ test_initializer_boolean() async {
+ var content = r'''
+var a = 1;
+var t1 = ((a = 1) == 0) || ((a = 2) == 0);
+var t2 = ((a = 1) == 0) && ((a = 2) == 0);
+var t3 = !((a = 1) == 0);
+''';
+ await checkFile(content);
+ }
+
+ test_initializer_cascade() async {
+ var content = r'''
+var a = 0;
+var t = (/*error:TOP_LEVEL_UNSUPPORTED*/a = 1)..isEven;
+''';
+ await checkFile(content);
+ }
+
+ test_initializer_classField_assign() async {
+ var content = r'''
+class A {
+ static var a = 1;
+ static var t = /*error:TOP_LEVEL_UNSUPPORTED*/a += 1;
+}
+''';
+ await checkFile(content);
+ }
+
+ test_initializer_conditional() async {
+ var content = r'''
+var a = 1;
+var b = true;
+var t = b ?
+ (/*error:TOP_LEVEL_UNSUPPORTED*/a = 1) :
+ (/*error:TOP_LEVEL_UNSUPPORTED*/a = 2);
+''';
+ await checkFile(content);
+ }
+
+ test_initializer_dependencyCycle() async {
+ var content = r'''
+var a = /*error:TOP_LEVEL_CYCLE*/b;
+var b = /*error:TOP_LEVEL_CYCLE*/a;
+''';
+ await checkFile(content);
+ }
+
+ test_initializer_equality() async {
+ var content = r'''
+var a = 1;
+var t1 = ((a = 1) == 0) == ((a = 2) == 0);
+var t2 = ((a = 1) == 0) != ((a = 2) == 0);
+''';
+ await checkFile(content);
+ }
+
+ test_initializer_functionLiteral_blockBody() async {
+ var content = r'''
+var t = /*error:TOP_LEVEL_FUNCTION_LITERAL_BLOCK*/
+ /*info:INFERRED_TYPE_CLOSURE*/
+ (int p) {};
+''';
+ await checkFile(content);
+ }
+
+ test_initializer_functionLiteral_expressionBody() async {
+ var content = r'''
+var a = 0;
+var t = (int p) => (/*error:TOP_LEVEL_UNSUPPORTED*/a = 1);
+''';
+ await checkFile(content);
+ }
+
+ test_initializer_functionLiteral_parameters_withoutType() async {
+ var content = r'''
+var t = (int a,
+ /*error:TOP_LEVEL_FUNCTION_LITERAL_PARAMETER*/b,
+ int c,
+ /*error:TOP_LEVEL_FUNCTION_LITERAL_PARAMETER*/d) => 0;
+''';
+ await checkFile(content);
+ }
+
+ test_initializer_hasTypeAnnotation() async {
+ var content = r'''
+var a = 1;
+int t = (a = 1);
+''';
+ await checkFile(content);
+ }
+
+ test_initializer_identifier() async {
+ var content = r'''
+int top_function() => 0;
+var top_variable = 0;
+int get top_getter => 0;
+class A {
+ static var static_field = 0;
+ static int get static_getter => 0;
+ static int static_method() => 0;
+ int instance_method() => 0;
+}
+var t1 = top_function;
+var t2 = top_variable;
+var t3 = top_getter;
+var t4 = A.static_field;
+var t5 = A.static_getter;
+var t6 = A.static_method;
+var t7 = new A().instance_method;
+''';
+ await checkFile(content);
+ }
+
+ test_initializer_identifier_error() async {
+ var content = r'''
+var a = 0;
+var b = (/*error:TOP_LEVEL_UNSUPPORTED*/a = 1);
+var c = /*error:TOP_LEVEL_IDENTIFIER_NO_TYPE*/b;
+''';
+ await checkFile(content);
+ }
+
+ test_initializer_ifNull() async {
+ var content = r'''
+var a = 1;
+var t = /*error:TOP_LEVEL_UNSUPPORTED*/a ?? 2;
+''';
+ await checkFile(content);
+ }
+
+ test_initializer_instanceCreation_withoutTypeParameters() async {
+ var content = r'''
+class A {}
+var t = new A();
+''';
+ await checkFile(content);
+ }
+
+ test_initializer_instanceCreation_withTypeParameters() async {
+ var content = r'''
+class A<T> {}
+var t1 = new /*error:TOP_LEVEL_TYPE_ARGUMENTS*/A();
+var t2 = new A<int>();
+''';
+ await checkFile(content);
+ }
+
+ test_initializer_instanceGetter() async {
+ var content = r'''
+class A {
+ int f = 1;
+}
+var a = new A()./*error:TOP_LEVEL_INSTANCE_GETTER*/f;
+''';
+ await checkFile(content);
+ }
+
+ test_initializer_methodInvocation_function() async {
+ var content = r'''
+int f1() => null;
+T f2<T>() => null;
+var t1 = f1();
+var t2 = /*error:TOP_LEVEL_TYPE_ARGUMENTS*/f2();
+var t3 = f2<int>();
+''';
+ await checkFile(content);
+ }
+
+ test_initializer_methodInvocation_method() async {
+ var content = r'''
+class A {
+ int m1() => null;
+ T m2<T>() => null;
+}
+var a = new A();
+var t1 = a.m1();
+var t2 = a./*error:TOP_LEVEL_TYPE_ARGUMENTS*/m2();
+var t3 = a.m2<int>();
+''';
+ await checkFile(content);
+ }
+
+ test_initializer_multiplicative() async {
+ await _assertErrorOnlyLeft(['*', '/', '%', '~/']);
+ }
+
+ test_initializer_postfixIncDec() async {
+ var content = r'''
+var a = 1;
+var t1 = a++;
+var t2 = a--;
+''';
+ await checkFile(content);
+ }
+
+ test_initializer_prefixIncDec() async {
+ var content = r'''
+var a = 1;
+var t1 = ++a;
+var t2 = --a;
+''';
+ await checkFile(content);
+ }
+
+ test_initializer_relational() async {
+ await _assertErrorOnlyLeft(['>', '>=', '<', '<=']);
+ }
+
+ test_initializer_shift() async {
+ await _assertErrorOnlyLeft(['<<', '>>']);
+ }
+
+ test_initializer_typedList() async {
+ var content = r'''
+var a = 1;
+var t = <int>[a = 1];
+''';
+ await checkFile(content);
+ }
+
+ test_initializer_typedMap() async {
+ var content = r'''
+var a = 1;
+var t = <int, int>{(a = 1) : (a = 2)};
+''';
+ await checkFile(content);
+ }
+
+ test_initializer_untypedList() async {
+ var content = r'''
+var a = 1;
+var t = /*info:INFERRED_TYPE_LITERAL*/[
+ /*error:TOP_LEVEL_UNSUPPORTED*/a = 1,
+ 2, 3];
+''';
+ await checkFile(content);
+ }
+
+ test_initializer_untypedMap() async {
+ var content = r'''
+var a = 1;
+var t = /*info:INFERRED_TYPE_LITERAL*/{
+ (/*error:TOP_LEVEL_UNSUPPORTED*/a = 1) :
+ (/*error:TOP_LEVEL_UNSUPPORTED*/a = 2)};
+''';
+ await checkFile(content);
+ }
+
+ test_override_conflictFieldType() async {
+ var content = r'''
+abstract class A {
+ int aaa;
+}
+abstract class B {
+ String aaa;
+}
+class C implements A, B {
+ /*error:INVALID_METHOD_OVERRIDE*/var aaa;
+}
+''';
+ await checkFile(content);
+ }
+
+ @failingTest
+ test_override_conflictParameterType_method() async {
+ var content = r'''
+abstract class A {
+ void mmm(int a);
+}
+abstract class B {
+ void mmm(String a);
+}
+class C implements A, B {
+ void mmm(/*error:TOP_LEVEL_INFERENCE_ERROR*/a) {}
+}
+''';
+ await checkFile(content);
+ }
+
+ Future<Null> _assertErrorOnlyLeft(List<String> operators) async {
+ var err = '/*error:TOP_LEVEL_UNSUPPORTED*/';
+ String code = 'var a = 1;\n';
+ for (var i = 0; i < operators.length; i++) {
+ String operator = operators[i];
+ code += 'var t$i = (${err}a = 1) $operator (a = 2);\n';
+ }
+ await checkFile(code);
+ }
+}
+
+@reflectiveTest
class TopLevelInferenceTest extends BaseAnalysisDriverTest {
void addFile(String path, String code) {
provider.newFile(_p(path), code);
@@ -139,6 +461,19 @@ num V;
''');
}
+ test_initializer_equality() async {
+ var library = await _encodeDecodeLibrary(r'''
+var vEq = 1 == 2;
+var vNotEq = 1 != 2;
+''');
+ checkElementText(
+ library,
+ r'''
+bool vEq;
+bool vNotEq;
+''');
+ }
+
test_initializer_error_assign() async {
var library = await _encodeDecodeLibrary(r'''
var a = 1;
@@ -930,6 +1265,22 @@ int vFloorDivide;
''');
}
+ @failingTest
+ test_initializer_onlyLeft() async {
+ var library = await _encodeDecodeLibrary(r'''
+var a = 1;
+var vEq = a == ((a = 2) == 0);
+var vNotEq = a != ((a = 2) == 0);
+''');
+ checkElementText(
+ library,
+ r'''
+int a;
+bool vEq;
+bool vNotEq;
+''');
+ }
+
test_initializer_parenthesized() async {
var library = await _encodeDecodeLibrary(r'''
var V = (42);
« no previous file with comments | « pkg/analyzer/test/src/summary/resynthesize_ast_test.dart ('k') | pkg/analyzer/test/src/task/dart_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698