5222bfd90c
This CL moves the bounds checking into the TypeBuilder instead of
performing it from the outside on the computed DartType node.
This solves several problems:
1) Errors are now reported on the type in the code instead of the
declaration which holds the type.
2) Checking of type aliases (both function and nonfunction type
aliases) is now handled correctly in all cases. This achieved by
computed the aliased type (containing TypedefType nodes)
internally and performing the checking on this type, and only
convert the type into the unaliased version (without TypedefType
nodes) after checks have been performed. Previously this handled
through the FunctionType.typedefType property for function type
aliases and through and incomplete work-around for nonfunction
type aliases.
3) With 2) FunctionType.typedefType is no longer needed and is
removed.
TEST=general/bounds_*
Change-Id: I7653bca5ccb0ebf4b3553828a298d1ad918ef235
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/243722
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
31 lines
902 B
Dart
31 lines
902 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 = 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>() {
|
|
// [error column 1]
|
|
// [cfe] A generic function type can't be used as a type argument.
|
|
// ^^^^^^^^^^^^^^^^^^^^^^^
|
|
// [analyzer] COMPILE_TIME_ERROR.GENERIC_FUNCTION_TYPE_CANNOT_BE_TYPE_ARGUMENT
|
|
return <int Function<T>(S, int)>[foo, foo];
|
|
}
|
|
|
|
void main() {
|
|
var list = bar<int>();
|
|
print(list[0].runtimeType);
|
|
Expect.equals(123, list[1](100, 23));
|
|
}
|