Skip to content

Commit edd366b

Browse files
Fix #30147 partially applied function crash.
Occurs when there are both bounds and also partially provided type args. Attempt to still perform substitution analysis even during partial application, so long as the partial application warning is still provided. Bug: 30147 Change-Id: I25a6dabe458494ee9fd6c53aeba75883c3143816 Reviewed-on: https://dart-review.googlesource.com/26040 Commit-Queue: Mike Fairhurst <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent b53e4e4 commit edd366b

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

pkg/analyzer/lib/src/generated/error_verifier.dart

+8-3
Original file line numberDiff line numberDiff line change
@@ -6246,9 +6246,14 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
62466246
TypeParameterTypeImpl.getTypes(genericType.typeFormals);
62476247
var typeArgs = typeArgumentList.map((t) => t.type).toList();
62486248

6249-
for (int i = 0, len = math.min(typeArgs.length, fnTypeParams.length);
6250-
i < len;
6251-
i++) {
6249+
// If the amount mismatches, clean up the lists to be substitutable. The
6250+
// mismatch in size is reported elsewhere, but we must successfully
6251+
// perform substitution to validate bounds on mismatched lists.
6252+
final providedLength = math.min(typeArgs.length, fnTypeParams.length);
6253+
fnTypeParams = fnTypeParams.sublist(0, providedLength);
6254+
typeArgs = typeArgs.sublist(0, providedLength);
6255+
6256+
for (int i = 0; i < providedLength; i++) {
62526257
// Check the `extends` clause for the type parameter, if any.
62536258
//
62546259
// Also substitute to handle cases like this:

pkg/analyzer/test/generated/strong_mode_test.dart

+16
Original file line numberDiff line numberDiff line change
@@ -3441,6 +3441,22 @@ void test<S>(T pf<T>(T e)) {
34413441
expectIdentifierType('paramTearOff', "<T>(T) → T");
34423442
}
34433443

3444+
test_genericMethod_partiallyAppliedErrorWithBound() async {
3445+
await resolveTestUnit(r'''
3446+
void f<X extends List, Y>() => null;
3447+
3448+
void test() {
3449+
f<int>();
3450+
}
3451+
''', noErrors: false);
3452+
assertErrors(testSource, [
3453+
// Make sure to catch both the missing parameter:
3454+
StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS_METHOD,
3455+
// And the incorrect parameter:
3456+
StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS
3457+
]);
3458+
}
3459+
34443460
test_genericMethod_then() async {
34453461
String code = r'''
34463462
import 'dart:async';

0 commit comments

Comments
 (0)