8e01f69305
In checked mode, `void` now accepts any value. Fixes #28937. Fixes #28938. BUG= http://dartbug.com/28937 BUG= http://dartbug.com/28938 R=johnniwinther@google.com, kmillikin@google.com, lrn@google.com, regis@google.com Committed: https://github.com/dart-lang/sdk/commit/521dc6620fd2c4591aa975745c14b304428f17eb Reverted: https://github.com/dart-lang/sdk/commit/a3c0cb65af4bbbdde756208dcccdcdf896902b5b Committed: https://github.com/dart-lang/sdk/commit/4e52c457a9ac412b6b0a3a350020998c7e2f7d9a Reverted: https://github.com/dart-lang/sdk/commit/4b35d3995b2b273728751c19976ece0edca0eddc Committed: https://github.com/dart-lang/sdk/commit/6caf9ef4439e20ea726d8a5383ed34d42b02c84b Reverted: https://github.com/dart-lang/sdk/commit/30d9bf2ed3225f04c52d999a1a5c61e63a90578d Review-Url: https://codereview.chromium.org/2718513002 .
38 lines
1022 B
Dart
38 lines
1022 B
Dart
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
// Tests that `void` accepts any value and won't throw on non-`null` values.
|
|
// The test is set up in a way that `--trust-type-annotations` and type
|
|
// propagation must not assume that `void` is `null` either.
|
|
|
|
import 'package:expect/expect.dart';
|
|
|
|
class A {
|
|
void foo() {
|
|
return bar();
|
|
}
|
|
|
|
void bar() {}
|
|
}
|
|
|
|
class B extends A {
|
|
int bar() => 42;
|
|
}
|
|
|
|
// Makes the typing cleaner: the return type here is `dynamic` and we are
|
|
// guaranteed that there won't be any warnings.
|
|
// Dart2js can still infer the type by itself.
|
|
@NoInline()
|
|
callFoo(A a) => a.foo();
|
|
|
|
main() {
|
|
var a = new A();
|
|
var b = new B();
|
|
// The following line is not throwing, even though `a.foo()` (inside
|
|
// `callFoo`) is supposedly `void`.
|
|
callFoo(b).abs();
|
|
Expect.isNull(callFoo(a));
|
|
Expect.equals(42, callFoo(b));
|
|
}
|