blob: fa6a747221da370a1830b9e22b2b7aa0bba7569b [file] [log] [blame]
// Copyright (c) 2020, 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 The definitions of least and greatest closure are changed in null
* safe libraries to substitute [Never] in positions where previously [Null
* would have been substituted, and [Object?] in positions where previously
* [Object] or [dynamic] would have been substituted.
* @description Check statically that correct type is substituted for generic
* [void Function<T>()] typedef.
* @note Read more about the least and greatest closure test template:
* https://github.com/dart-lang/co19/issues/575#issuecomment-613542349
*
* @author iarkh@unipro.ru
*/
// SharedOptions=--enable-experiment=generic-metadata
import "../../Utils/expect.dart";
typedef check = void Function<T>();
void main() {
void f(check Function<T>() g) => g();
// Verify that we can call the function with the specified arguments.
f(<T>() => captureTypeArgument()..call());
// Verify that a couple of wrong argument lists are rejected.
f(<T>() => captureTypeArgument()..call(throw 1));
// ^
// [analyzer] unspecified
// [cfe] unspecified
f(<T>() => captureTypeArgument()..call('Hello'));
// ^
// [analyzer] unspecified
// [cfe] unspecified
f(<T>() => captureTypeArgument()..call(arg: 'Hello'));
// ^
// [analyzer] unspecified
// [cfe] unspecified
// Verify that the return type is `void`: Returned value not usable,
// not even to access a member of `Object`.
f(<T>() => captureTypeArgument()..call().toString());
// ^
// [analyzer] unspecified
// [cfe] unspecified
}