Files
sdk/tests/language_2/generic_methods/generic_function_result_test.dart
T
Nate Bosch 71fc33e427 Enable experiment generic_metadata
Change-Id: Iff050e6a2a1c0c2b8baca211a523f9dd77cfbd4a
TEST=Existing tests for the feature.
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193748
Reviewed-by: Leaf Petersen <leafp@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Commit-Queue: Leaf Petersen <leafp@google.com>
2021-04-27 20:16:08 +00:00

33 lines
1.0 KiB
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 = 2.9
// Verify that function type parameter S can be resolved in bar's result type.
// Verify that generic function types are not allowed as type arguments.
// @dart=2.11
import "package:expect/expect.dart";
int foo
<T>
(int i, int j) => i + j;
List<int Function<T>(S, int)> bar<S extends int>() {
// ^^^^^^^^^^^^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.GENERIC_FUNCTION_TYPE_CANNOT_BE_TYPE_ARGUMENT
// ^
// [cfe] A generic function type can't be used as a type argument.
return <int Function<T>(S, int)>[foo, foo];
}
void main() {
var list = bar<int>();
// ^
// [cfe] Generic function type 'int Function<T>(int, int)' inferred as a type argument.
print(list[0].runtimeType);
Expect.equals(123, list[1](100, 23));
}