Chromium Code Reviews| Index: tests/language/void_type5_test.dart |
| diff --git a/tests/language/void_type5_test.dart b/tests/language/void_type5_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..50275ec5f30010463024f8d54f03b62ffd795adc |
| --- /dev/null |
| +++ b/tests/language/void_type5_test.dart |
| @@ -0,0 +1,37 @@ |
| +// 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. |
| + |
| +// Dart test for type checks involving the void type. |
| + |
| +import 'package:expect/expect.dart'; |
| + |
| +class A<T> { |
| + T x; |
| + foo(T x) {} |
| + T bar(T f()) { |
| + T tmp = f(); |
| + return tmp; |
| + } |
| + |
| + gee(T f()) { |
| + x = bar(f); |
| + } |
| + |
| + Object xAsObject() => x; |
| +} |
| + |
| +void voidFun() => 499; |
| +int intFun() => 42; |
| + |
| +main() { |
| + var a = new A<void>(); |
|
Lasse Reichstein Nielsen
2017/02/21 09:37:04
var a = ... -> A<void> a = ...
floitsch
2017/02/22 14:44:43
Done.
|
| + a.foo(a.x); /// 00: error |
| + a.bar(voidFun); |
| + Expect.equals(null, a.xAsObject()); |
| + var t = a.bar(voidFun); /// 01: error |
| + a.gee(voidFun); // But we can do it through `gee`. |
| + Expect.equals(499, a.xAsObject()); |
| + a.gee(intFun); // We can also pass in an int function. |
| + Expect.equals(42, a.xAsObject()); |
| +} |