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

Unified Diff: tests/language/conditional_method_invocation_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
« no previous file with comments | « tests/language/conditional_access_helper.dart ('k') | tests/language/conditional_property_access_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/language/conditional_method_invocation_test.dart
diff --git a/tests/language/conditional_method_invocation_test.dart b/tests/language/conditional_method_invocation_test.dart
index cfe0545a2c19ca7a090d0978ddfac6f0eb74f953..0dd219deea717962cecca65d4c22ff91b6505aef 100644
--- a/tests/language/conditional_method_invocation_test.dart
+++ b/tests/language/conditional_method_invocation_test.dart
@@ -18,7 +18,8 @@ class B {}
class C extends B {
f(callback()) => callback();
int g(int callback()) => callback();
- static void staticMethod() {}
+ static staticF(callback()) => callback();
+ static int staticG(int callback()) => callback();
}
C nullC() => null;
@@ -32,12 +33,20 @@ main() {
Expect.equals(null, nullC()?.f(bad())); /// 01: ok
Expect.equals(1, new C()?.f(() => 1)); /// 02: ok
+ // C?.m(...) is equivalent to C.m(...).
+ Expect.equals(1, C?.staticF(() => 1)); /// 14: ok
+ Expect.equals(1, h.C?.staticF(() => 1)); /// 15: ok
+
// The static type of o?.m(...) is the same as the static type of
// o.m(...).
{ int i = nullC()?.g(bad()); Expect.equals(null, i); } /// 03: ok
{ int i = new C()?.g(() => 1); Expect.equals(1, i); } /// 04: ok
{ String s = nullC()?.g(bad()); Expect.equals(null, s); } /// 05: static type warning
{ String s = new C()?.g(() => null); Expect.equals(null, s); } /// 06: static type warning
+ { int i = C?.staticG(() => 1); Expect.equals(1, i); } /// 16: ok
+ { int i = h.C?.staticG(() => 1); Expect.equals(1, i); } /// 17: ok
+ { String s = C?.staticG(() => null); Expect.equals(null, s); } /// 18: static type warning
+ { String s = h.C?.staticG(() => null); Expect.equals(null, s); } /// 19: static type warning
// Let T be the static type of o and let y be a fresh variable of type T.
// Exactly the same static warnings that would be caused by y.m(...) are also
@@ -45,15 +54,11 @@ main() {
{ B b = new C(); Expect.equals(1, b?.f(() => 1)); } /// 07: static type warning
{ int i = 1; Expect.equals(null, nullC()?.f(i)); } /// 08: static type warning
- // Consequently, '?.' cannot be used to invoke static methods of classes.
- Expect.throws(() => C?.staticMethod(), noMethod); /// 09: static type warning
- Expect.throws(() => h.C?.staticMethod(), noMethod); /// 10: static type warning
-
- // Nor can it be used to access toplevel functions in libraries imported via
+ // '?.' can't be used to access toplevel functions in libraries imported via
// prefix.
h?.topLevelFunction(); /// 11: compile-time error
- // However, '?.' can be used to access the toString method on the class Type.
- Expect.equals(C?.toString(), (C).toString()); /// 12: ok
- Expect.equals(h.C?.toString(), (h.C).toString()); /// 13: ok
+ // Nor can it be used to access the toString method on the class Type.
+ Expect.throws(() => C?.toString(), noMethod); /// 12: static type warning
+ Expect.throws(() => h.C?.toString(), noMethod); /// 13: static type warning
}
« no previous file with comments | « tests/language/conditional_access_helper.dart ('k') | tests/language/conditional_property_access_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698