Skip to content

Commit ed2f893

Browse files
johnniwintherCommit Queue
authored andcommitted
[analyzer] Handle display for type parameters without name
The ElementDisplayStringBuilder crash when encountering a type parameter without a name. This chance handles the case by using the empty string as the name in the computation of unique type parameters. Fixes b/418755155 Change-Id: I4fd1a6df64a31614e0c4548963d0c5507cc94ca8 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/429640 Commit-Queue: Johnni Winther <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
1 parent f927877 commit ed2f893

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

pkg/analyzer/lib/src/dart/element/display_string_builder.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,8 @@ class ElementDisplayStringBuilder {
623623

624624
var newTypeParameters = <TypeParameterElementImpl2>[];
625625
for (var typeParameter in type.typeParameters) {
626-
var name = typeParameter.name3!;
626+
// The type parameter name can be null in erroneous cases.
627+
var name = typeParameter.name3 ?? '';
627628
for (var counter = 0; !namesToAvoid.add(name); counter++) {
628629
const unicodeSubscriptZero = 0x2080;
629630
const unicodeZero = 0x30;

pkg/analyzer/test/src/dart/resolution/assignment_test.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,23 @@ AssignmentExpression
863863
''');
864864
}
865865

866+
test_indexExpression_unresolved_missing_type_parameter_name() async {
867+
await assertErrorsInCode(
868+
r'''
869+
abstract class A {
870+
void b< extends int>();
871+
}
872+
void f(A a) {
873+
a.b[0] = 0;
874+
}
875+
''',
876+
[
877+
error(ParserErrorCode.MISSING_IDENTIFIER, 30, 7),
878+
error(CompileTimeErrorCode.UNDEFINED_OPERATOR, 67, 3),
879+
],
880+
);
881+
}
882+
866883
test_indexExpression_unresolvedTarget_compound() async {
867884
await assertErrorsInCode(
868885
r'''

pkg/analyzer/test/src/dart/resolution/function_type_alias_test.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ NamedType
3838
alias: <testLibrary>::@typeAlias::G
3939
typeArguments
4040
int
41+
''');
42+
}
43+
44+
test_type_missing_type_parameter_name() async {
45+
await resolveTestCode(r'''
46+
typedef F = void Function< extends int>();
4147
''');
4248
}
4349
}

0 commit comments

Comments
 (0)