dart-sdk/tests/language/void/void_type_callbacks_test.dart
Lasse Reichstein Holst Nielsen c10e96ba2f Migrate void tests to Null Safety.
Change-Id: I9daeebde586a00169bdaf069c7dc2fdc5d3d97f2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/147160
Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
2020-06-03 13:22:10 +00:00

42 lines
786 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.
// Dart test for type checks involving callbacks and the type void.
import 'package:expect/expect.dart';
class A<T> {
T x;
A(this.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() {
A<void> a = new A<void>(null);
a.foo(a.x);
a.bar(voidFun);
Expect.equals(null, a.xAsObject());
a.x = a.bar(voidFun);
a.gee(voidFun);
Expect.equals(499, a.xAsObject());
a.gee(intFun);
Expect.equals(42, a.xAsObject());
}