blob: 517c7ee361b45af369b317e9a997f38039811a57 [file] [log] [blame]
/*
* Copyright (c) 2021, 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.
*/
/**
* @assertion At this location about an asynchronous non-generator function with
* future value type $T_v$, the text is changed as follows:
*
* It is a compile-time error if $s$ is \code{\RETURN{};},
* unless $T_v$
* is \VOID, \DYNAMIC, or \code{Null}.
* %
* It is a compile-time error if $s$ is \code{\RETURN{} $e$;},
* $T_v$ is \VOID,
* and \flatten{S} is neither \VOID, \DYNAMIC, \code{Null}.
* %
* It is a compile-time error if $s$ is \code{\RETURN{} $e$;},
* $T_v$ is neither \VOID{} nor \DYNAMIC,
* and \flatten{S} is \VOID.
* %
* It is a compile-time error if $s$ is \code{\RETURN{} $e$;},
* \flatten{S} is not \VOID,
* $S$ is not assignable to $T_v$,
* and flatten{S} is not a subtype of $T_v$.
* Comparing to Dart before null-safety, this means that it is no longer
* allowed to return an expression whose flattened static type is void in an
* async function with future value type Null; nor is it allowed, in an async
* function with future value type void, to return an expression whose
* flattened static type is not void, void*, dynamic, or Null. Conversely, it
* is allowed to return a future when the future value type is a suitable
* future; for instance, we can have return Future<int>.value(42) in an async
* function with declared return type Future<Future<int>>. Finally, let S be
* Future<dynamic> or FutureOr<dynamic>; it is then no longer allowed to return
* an expression with static type S, unless the future value type is a
* supertype of S. This differs from Dart before null-safety in that it was
* allowed to return an expression of these types with a declared return type
* of the form Future<T> for any T.
*
* @description Check that it is not a compile-time error in an async function
* with future value type void, to return an expression whose flattened static
* type is void, dynamic, or Null
* @author sgrekhov@unipro.ru
*/
// Requirements=nnbd-strong
void v1() {}
dynamic d1() {
return 42;
}
Null n1() {
return null;
}
Future<void> f1() async {
return v1();
}
Future<void> f2() async {
return d1();
}
Future<void> f3() async {
return n1();
}
main() {
f1();
f2();
f3();
}