Chromium Code Reviews| 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(); | |
|
Lasse Reichstein Nielsen
2017/03/02 07:21:49
indentation is off.
regis
2017/03/22 16:29:32
This line hurts my eyes, and it is not because of
regis
2017/03/22 16:33:48
Ignore this comment. It was saved as a draft and p
| |
| 14 } | |
| 15 void bar() {} | |
| 16 } | |
| 17 | |
| 18 class B extends A { | |
| 19 int bar() => 42; | |
| 20 } | |
| 21 | |
| 22 // Makes the typing cleaner: the return type here is `dynamic` and we are | |
| 23 // guaranteed that there won't be any warnings. | |
| 24 // Dart2js can still infer the type by itself. | |
| 25 @NoInline() | |
| 26 callFoo(A a) => a.foo(); | |
| 27 | |
| 28 main() { | |
| 29 var a = new A(); | |
| 30 var b = new B(); | |
| 31 // The following line is not throwing, even though `a.foo()` (inside | |
| 32 // `callFoo`) is supposedly `void`. | |
| 33 callFoo(b).abs(); | |
| 34 Expect.isNull(callFoo(a)); | |
| 35 Expect.equals(42, callFoo(b)); | |
| 36 } | |
| OLD | NEW |