Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(323)

Unified Diff: tests/language/void_check_test.dart

Issue 2718513002: Void is not required to be `null` anymore. (Closed)
Patch Set: Update Kernel code. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/language/return_type_test.dart ('k') | tests/language/void_type_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/language/void_check_test.dart
diff --git a/tests/language/void_check_test.dart b/tests/language/void_check_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..2e42a255359314afe3a5121c17b269bef0311c89
--- /dev/null
+++ b/tests/language/void_check_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.
+
+// 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));
+}
« no previous file with comments | « tests/language/return_type_test.dart ('k') | tests/language/void_type_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698