Version 1.23.0-dev.11.10
Cherry-pick 63a6f83739cbc96f7423bba1ffdd093357775baa into dev
diff --git a/pkg/analyzer/lib/src/dart/element/element.dart b/pkg/analyzer/lib/src/dart/element/element.dart
index d3432fe..5521ee3 100644
--- a/pkg/analyzer/lib/src/dart/element/element.dart
+++ b/pkg/analyzer/lib/src/dart/element/element.dart
@@ -5236,6 +5236,10 @@
* `dynamic` will be used in place of each of the type arguments.
*/
FunctionType typeAfterSubstitution(List<DartType> typeArguments) {
+ GenericFunctionTypeElement function = this.function;
+ if (function == null) {
+ return null;
+ }
FunctionType functionType = function.type;
List<TypeParameterElement> parameterElements = typeParameters;
List<DartType> parameterTypes =
diff --git a/pkg/analyzer/lib/src/generated/resolver.dart b/pkg/analyzer/lib/src/generated/resolver.dart
index 502fddf6..af75cca 100644
--- a/pkg/analyzer/lib/src/generated/resolver.dart
+++ b/pkg/analyzer/lib/src/generated/resolver.dart
@@ -8410,9 +8410,17 @@
typeArguments[i] = dynamicType;
}
}
- type = typeSystem.instantiateType(type, typeArguments);
+ if (element is GenericTypeAliasElementImpl) {
+ type = element.typeAfterSubstitution(typeArguments) ?? dynamicType;
+ } else {
+ type = typeSystem.instantiateType(type, typeArguments);
+ }
} else {
- type = typeSystem.instantiateToBounds(type);
+ if (element is GenericTypeAliasElementImpl) {
+ type = element.typeAfterSubstitution(null) ?? dynamicType;
+ } else {
+ type = typeSystem.instantiateToBounds(type);
+ }
}
typeName.staticType = type;
node.type = type;
@@ -8477,7 +8485,7 @@
typeArguments[i] = _getType(arguments[i]);
}
}
- return element.typeAfterSubstitution(typeArguments);
+ return element.typeAfterSubstitution(typeArguments) ?? dynamicType;
}
}
return type;
diff --git a/pkg/analyzer/test/generated/non_error_resolver_test.dart b/pkg/analyzer/test/generated/non_error_resolver_test.dart
index e516d5d..b282b37 100644
--- a/pkg/analyzer/test/generated/non_error_resolver_test.dart
+++ b/pkg/analyzer/test/generated/non_error_resolver_test.dart
@@ -2158,6 +2158,42 @@
verify([source]);
}
+ test_genericTypeAlias_castsAndTypeChecks_hasTypeParameters() async {
+ Source source = addSource('''
+typedef Foo<S> = S Function<T>(T x);
+
+main(Object p) {
+ (p as Foo)<int>(3);
+ if (p is Foo) {
+ p<int>(3);
+ }
+ (p as Foo<String>)<int>(3);
+ if (p is Foo<String>) {
+ p<int>(3);
+ }
+}
+''');
+ await computeAnalysisResult(source);
+ assertNoErrors(source);
+ verify([source]);
+ }
+
+ test_genericTypeAlias_castsAndTypeChecks_noTypeParameters() async {
+ Source source = addSource('''
+typedef Foo = T Function<T>(T x);
+
+main(Object p) {
+ (p as Foo)<int>(3);
+ if (p is Foo) {
+ p<int>(3);
+ }
+}
+''');
+ await computeAnalysisResult(source);
+ assertNoErrors(source);
+ verify([source]);
+ }
+
test_genericTypeAlias_fieldAndReturnType_noTypeParameters() async {
Source source = addSource(r'''
typedef Foo = int Function<T>(T x);
@@ -2221,6 +2257,19 @@
verify([source]);
}
+ test_genericTypeAlias_invalidGenericFunctionType() async {
+ Source source = addSource('''
+typedef F = int;
+main(p) {
+ p is F;
+}
+''');
+ await computeAnalysisResult(source);
+ // There is a parse error, but no crashes.
+ assertErrors(source, [ParserErrorCode.INVALID_GENERIC_FUNCTION_TYPE]);
+ verify([source]);
+ }
+
test_genericTypeAlias_noTypeParameters() async {
Source source = addSource(r'''
typedef Foo = int Function<T>(T x);
diff --git a/tools/VERSION b/tools/VERSION
index 7427601..11dbf70 100644
--- a/tools/VERSION
+++ b/tools/VERSION
@@ -28,4 +28,4 @@
MINOR 23
PATCH 0
PRERELEASE 11
-PRERELEASE_PATCH 9
+PRERELEASE_PATCH 10