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

Unified Diff: tests/language/conditional_property_access_test.dart

Issue 1255293005: Fix analyzer interpretation of 'ClassName?.staticMember'. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 5 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: tests/language/conditional_property_access_test.dart
diff --git a/tests/language/conditional_property_access_test.dart b/tests/language/conditional_property_access_test.dart
index ca44f2d9ab30fdd92f2e6de4a92f9ca289cedae3..b5dfa85f432833e9be14bc897a34428c8d7b882e 100644
--- a/tests/language/conditional_property_access_test.dart
+++ b/tests/language/conditional_property_access_test.dart
@@ -15,7 +15,7 @@ class B {}
class C extends B {
int v;
C(this.v);
- static var staticField;
+ static int staticInt;
}
C nullC() => null;
@@ -29,9 +29,17 @@ main() {
Expect.equals(null, nullC()?.v); /// 01: ok
Expect.equals(1, new C(1)?.v); /// 02: ok
+ // C?.id is equivalent to C.id.
+ { C.staticInt = 1; Expect.equals(1, C?.staticInt); } /// 12: ok
+ { h.C.staticInt = 1; Expect.equals(1, h.C?.staticInt); } /// 13: ok
+
// The static type of e1?.d is the static type of e1.id.
{ int i = new C(1)?.v; Expect.equals(1, i); } /// 03: ok
{ String s = new C(null)?.v; Expect.equals(null, s); } /// 04: static type warning
+ { C.staticInt = 1; int i = C?.staticInt; Expect.equals(1, i); } /// 14: ok
+ { h.C.staticInt = 1; int i = h.C?.staticInt; Expect.equals(1, i); } /// 15: ok
+ { C.staticInt = null; String s = C?.staticInt; Expect.equals(null, s); } /// 16: static type warning
+ { h.C.staticInt = null; String s = h.C?.staticInt; Expect.equals(null, s); } /// 17: static type warning
// Let T be the static type of e1 and let y be a fresh variable of type T.
// Exactly the same static warnings that would be caused by y.id are also
@@ -39,15 +47,11 @@ main() {
Expect.equals(null, nullC()?.bad); /// 05: static type warning
{ B b = new C(1); Expect.equals(1, b?.v); } /// 06: static type warning
- // Consequently, '?.' cannot be used to access static properties of classes.
- Expect.throws(() => C?.staticField, noMethod); /// 07: static type warning
- Expect.throws(() => h.C?.staticField, noMethod); /// 08: static type warning
-
- // Nor can it be used to access toplevel properties in libraries imported via
+ // '?.' cannot be used to access toplevel properties in libraries imported via
// prefix.
var x = h?.topLevelVar; /// 09: compile-time error
- // However, '?.' can be used to access the hashCode getter on the class Type.
- Expect.equals(C?.hashCode, (C).hashCode); /// 10: ok
- Expect.equals(h.C?.hashCode, (h.C).hashCode); /// 11: ok
+ // Nor can it be used to access the hashCode getter on the class Type.
+ Expect.throws(() => C?.hashCode, noMethod); /// 10: static type warning
+ Expect.throws(() => h.C?.hashCode, noMethod); /// 11: static type warning
}
« no previous file with comments | « tests/language/conditional_method_invocation_test.dart ('k') | tests/language/conditional_property_assignment_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698