OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 // Dart test for testing the ternary operator. | 4 // Dart test for testing the ternary operator. |
5 | 5 |
6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
7 | 7 |
8 // Test that `Null` acts like the bottom type - less than any other type. | 8 // Test that `Null` acts like the bottom type - less than any other type. |
9 | 9 |
10 bool isCheckedMode = () { bool c = false; assert(c = true); return c; } (); | 10 bool isCheckedMode = () { bool c = false; assert(c = true); return c; } (); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 Expect.isTrue(((int _) => null) is Fun<int, Null>); | 106 Expect.isTrue(((int _) => null) is Fun<int, Null>); |
107 | 107 |
108 Null fun(int x) => null; | 108 Null fun(int x) => null; |
109 Fun<Null, int> fun2 = fun; // Safe assignment. | 109 Fun<Null, int> fun2 = fun; // Safe assignment. |
110 if (fun2 is Fun<int, Null>) { | 110 if (fun2 is Fun<int, Null>) { |
111 // If int->Null is *subtype* of Null->int (which it should be), | 111 // If int->Null is *subtype* of Null->int (which it should be), |
112 // then type promotion succeeds. | 112 // then type promotion succeeds. |
113 // If type promotion succeeds, the static type is int->Null, otherwise | 113 // If type promotion succeeds, the static type is int->Null, otherwise |
114 // it's Null->int. | 114 // it's Null->int. |
115 fun2(42); // Should not give a warning after type promotion. | 115 fun2(42); // Should not give a warning after type promotion. |
116 fun2(null).abs(); /// 03: static type warning, runtime error | 116 fun2(null).abs(); /// 03: runtime error |
117 } | 117 } |
118 } | 118 } |
119 | 119 |
120 class T1 { | 120 class T1 { |
121 Null foo(int x) => null; | 121 Null foo(int x) => null; |
122 int bar(Null x) => null; | 122 int bar(Null x) => null; |
123 Null baz(int x) => null; | 123 Null baz(int x) => null; |
124 int qux(Null x) => null; | 124 int qux(Null x) => null; |
125 } | 125 } |
126 | 126 |
127 class T2 extends T1 { | 127 class T2 extends T1 { |
128 Null foo(Null x) => null; /// 01: static type warning | 128 Null foo(Null x) => null; |
129 Null bar(Null x) => null; | 129 Null bar(Null x) => null; |
130 int baz(int x) => x; /// 02: static type warning | 130 int baz(int x) => x; |
131 int qux(int x) => x; | 131 int qux(int x) => x; |
132 } | 132 } |
133 | 133 |
134 // Avoid "variable not used" warnings. | 134 // Avoid "variable not used" warnings. |
135 use(x) { | 135 use(x) { |
136 return identical(x, x); | 136 return identical(x, x); |
137 } | 137 } |
OLD | NEW |