OLD | NEW |
| (Empty) |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | |
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. | |
4 | |
5 // Tests that `void` accepts any value and won't throw on non-`null` values. | |
6 // The test is set up in a way that `--trust-type-annotations` and type | |
7 // propagation must not assume that `void` is `null` either. | |
8 | |
9 import 'package:expect/expect.dart'; | |
10 | |
11 class A { | |
12 void foo() { | |
13 return bar(); | |
14 } | |
15 | |
16 void bar() {} | |
17 } | |
18 | |
19 class B extends A { | |
20 int bar() => 42; | |
21 } | |
22 | |
23 // Makes the typing cleaner: the return type here is `dynamic` and we are | |
24 // guaranteed that there won't be any warnings. | |
25 // Dart2js can still infer the type by itself. | |
26 @NoInline() | |
27 callFoo(A a) => a.foo(); | |
28 | |
29 main() { | |
30 var a = new A(); | |
31 var b = new B(); | |
32 // The following line is not throwing, even though `a.foo()` (inside | |
33 // `callFoo`) is supposedly `void`. | |
34 callFoo(b).abs(); | |
35 Expect.isNull(callFoo(a)); | |
36 Expect.equals(42, callFoo(b)); | |
37 } | |
OLD | NEW |