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

Unified Diff: pkg/analyzer/test/src/task/strong/inferred_type_test.dart

Issue 2012023002: Fix AST-based type inference via interfaces. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 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
Index: pkg/analyzer/test/src/task/strong/inferred_type_test.dart
diff --git a/pkg/analyzer/test/src/task/strong/inferred_type_test.dart b/pkg/analyzer/test/src/task/strong/inferred_type_test.dart
index a4bc6b7a6edb0a56a50eb8084de9829cd19b5d69..a6867401c46e215cccf90efd503112723a0e5bcb 100644
--- a/pkg/analyzer/test/src/task/strong/inferred_type_test.dart
+++ b/pkg/analyzer/test/src/task/strong/inferred_type_test.dart
@@ -2318,6 +2318,168 @@ var f = () {};
expect(f.type.toString(), '() → dynamic');
}
+ void test_inferredType_customBinaryOp() {
+ var mainUnit = checkFile('''
+class C {
+ bool operator*(C other) => true;
+}
+C c;
+var x = c*c;
+''');
+ var x = mainUnit.topLevelVariables[1];
+ expect(x.name, 'x');
+ expect(x.type.toString(), 'bool');
+ }
+
+ void test_inferredType_customBinaryOp_viaInterface() {
+ var mainUnit = checkFile('''
+class I {
+ bool operator*(C other) => true;
+}
+abstract class C implements I {}
+C c;
+var x = c*c;
+''');
+ var x = mainUnit.topLevelVariables[1];
+ expect(x.name, 'x');
+ expect(x.type.toString(), 'bool');
+ }
+
+ void test_inferredType_customIndexOp() {
+ var mainUnit = checkFile('''
+class C {
+ bool operator[](int index) => true;
+}
+C c;
+var x = c[0];
+''');
+ var x = mainUnit.topLevelVariables[1];
+ expect(x.name, 'x');
+ expect(x.type.toString(), 'bool');
+ }
+
+ void test_inferredType_customIndexOp_viaInterface() {
+ var mainUnit = checkFile('''
+class I {
+ bool operator[](int index) => true;
+}
+abstract class C implements I {}
+C c;
+var x = c[0];
+''');
+ var x = mainUnit.topLevelVariables[1];
+ expect(x.name, 'x');
+ expect(x.type.toString(), 'bool');
+ }
+
+ void test_inferredType_customUnaryOp() {
+ var mainUnit = checkFile('''
+class C {
+ bool operator-() => true;
+}
+C c;
+var x = -c;
+''');
+ var x = mainUnit.topLevelVariables[1];
+ expect(x.name, 'x');
+ expect(x.type.toString(), 'bool');
+ }
+
+ void test_inferredType_customUnaryOp_viaInterface() {
+ var mainUnit = checkFile('''
+class I {
+ bool operator-() => true;
+}
+abstract class C implements I {}
+C c;
+var x = -c;
+''');
+ var x = mainUnit.topLevelVariables[1];
+ expect(x.name, 'x');
+ expect(x.type.toString(), 'bool');
+ }
+
+ void test_inferredType_extractMethodTearOff() {
+ var mainUnit = checkFile('''
+class C {
+ bool g() => true;
+}
+C f() => null;
+var x = f().g;
+''');
+ var x = mainUnit.topLevelVariables[0];
+ expect(x.name, 'x');
+ expect(x.type.toString(), '() → bool');
+ }
+
+ void test_inferredType_extractMethodTearOff_viaInterface() {
+ var mainUnit = checkFile('''
+class I {
+ bool g() => true;
+}
+abstract class C implements I {}
+C f() => null;
+var x = f().g;
+''');
+ var x = mainUnit.topLevelVariables[0];
+ expect(x.name, 'x');
+ expect(x.type.toString(), '() → bool');
+ }
+
+ void test_inferredType_extractProperty() {
+ var mainUnit = checkFile('''
+class C {
+ bool b;
+}
+C f() => null;
+var x = f().b;
+''');
+ var x = mainUnit.topLevelVariables[0];
+ expect(x.name, 'x');
+ expect(x.type.toString(), 'bool');
+ }
+
+ void test_inferredType_extractProperty_prefixedIdentifier() {
+ var mainUnit = checkFile('''
+class C {
+ bool b;
+}
+C c;
+var x = c.b;
+''');
+ var x = mainUnit.topLevelVariables[1];
+ expect(x.name, 'x');
+ expect(x.type.toString(), 'bool');
+ }
+
+ void test_inferredType_extractProperty_prefixedIdentifier_viaInterface() {
+ var mainUnit = checkFile('''
+class I {
+ bool b;
+}
+abstract class C implements I {}
+C c;
+var x = c.b;
+''');
+ var x = mainUnit.topLevelVariables[1];
+ expect(x.name, 'x');
+ expect(x.type.toString(), 'bool');
+ }
+
+ void test_inferredType_extractProperty_viaInterface() {
+ var mainUnit = checkFile('''
+class I {
+ bool b;
+}
+abstract class C implements I {}
+C f() => null;
+var x = f().b;
+''');
+ var x = mainUnit.topLevelVariables[0];
+ expect(x.name, 'x');
+ expect(x.type.toString(), 'bool');
+ }
+
void test_inferredType_fromTopLevelExecutableTearoff() {
var mainUnit = checkFile('''
var v = print;
@@ -2326,6 +2488,33 @@ var v = print;
expect(v.type.toString(), '(Object) → void');
}
+ void test_inferredType_invokeMethod() {
+ var mainUnit = checkFile('''
+class C {
+ bool g() => true;
+}
+C f() => null;
+var x = f().g();
+''');
+ var x = mainUnit.topLevelVariables[0];
+ expect(x.name, 'x');
+ expect(x.type.toString(), 'bool');
+ }
+
+ void test_inferredType_invokeMethod_viaInterface() {
+ var mainUnit = checkFile('''
+class I {
+ bool g() => true;
+}
+abstract class C implements I {}
+C f() => null;
+var x = f().g();
+''');
+ var x = mainUnit.topLevelVariables[0];
+ expect(x.name, 'x');
+ expect(x.type.toString(), 'bool');
+ }
+
void test_inferredType_isEnum() {
var mainUnit = checkFile('''
enum E { v1 }
@@ -2362,6 +2551,60 @@ final x = <String, F<int>>{};
expect(x.type.toString(), 'Map<String, () → int>');
}
+ void test_inferredType_opAssignToProperty_prefixedIdentifier() {
+ var mainUnit = checkFile('''
+class C {
+ num n;
+}
+C c;
+var x = (c.n *= null);
+''');
+ var x = mainUnit.topLevelVariables[1];
+ expect(x.name, 'x');
+ expect(x.type.toString(), 'num');
+ }
+
+ void test_inferredType_opAssignToProperty_prefixedIdentifier_viaInterface() {
+ var mainUnit = checkFile('''
+class I {
+ num n;
+}
+abstract class C implements I {}
+C c;
+var x = (c.n *= null);
+''');
+ var x = mainUnit.topLevelVariables[1];
+ expect(x.name, 'x');
+ expect(x.type.toString(), 'num');
+ }
+
+ void test_inferredType_opAssignToProperty() {
+ var mainUnit = checkFile('''
+class C {
+ num n;
+}
+C f() => null;
+var x = (f().n *= null);
+''');
+ var x = mainUnit.topLevelVariables[0];
+ expect(x.name, 'x');
+ expect(x.type.toString(), 'num');
+ }
+
+ void test_inferredType_opAssignToProperty_viaInterface() {
+ var mainUnit = checkFile('''
+class I {
+ num n;
+}
+abstract class C implements I {}
+C f() => null;
+var x = (f().n *= null);
+''');
+ var x = mainUnit.topLevelVariables[0];
+ expect(x.name, 'x');
+ expect(x.type.toString(), 'num');
+ }
+
void test_inferStaticsTransitively() {
addFile(
'''

Powered by Google App Engine
This is Rietveld 408576698