blob: d7c2b729882c9e0a91a7a7164bb0c785ac4f3462 [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 a compile-time error to return a future
* when the future value type is not a suitable future
* @author sgrekhov@unipro.ru
*/
Future<Future<int>> f1() async {
return new Future<num>.value(42);
// ^^^^^^^^^^^^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
main() {
f1();
}