Skip to content

Commit 8fbb053

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Issue 39021. Guard against invalid generic type alias, without function type.
[email protected] Bug: #39021 Change-Id: I0259ef04f95e1935ca273b5540aafb069c7ad455 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/125526 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent fe3fadb commit 8fbb053

4 files changed

Lines changed: 18 additions & 2 deletions

File tree

pkg/analysis_server/lib/src/services/completion/dart/type_member_contributor.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ class _LocalBestTypeVisitor extends LocalDeclarationVisitor {
184184
@override
185185
void declaredGenericTypeAlias(GenericTypeAlias declaration) {
186186
if (declaration.name.name == targetName) {
187-
TypeAnnotation typeName = declaration.functionType.returnType;
187+
TypeAnnotation typeName = declaration.functionType?.returnType;
188188
if (typeName != null) {
189189
typeFound = typeName.type;
190190
}

pkg/analysis_server/test/services/completion/dart/type_member_contributor_test.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2068,6 +2068,14 @@ void f(C<int> c) {
20682068
expect(suggestion.element.parameters, '(int value)');
20692069
}
20702070

2071+
test_genericTypeAlias_noFunctionType() async {
2072+
addTestSource('''
2073+
typedef F=;
2074+
g(F.^
2075+
''');
2076+
await computeSuggestions();
2077+
}
2078+
20712079
test_IfStatement() async {
20722080
// SimpleIdentifier IfStatement
20732081
addTestSource('''

pkg/analyzer_plugin/lib/utilities/completion/type_member_contributor.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ class _LocalBestTypeVisitor extends LocalDeclarationVisitor {
246246
@override
247247
void declaredGenericTypeAlias(GenericTypeAlias declaration) {
248248
if (declaration.name.name == targetName) {
249-
TypeAnnotation typeName = declaration.functionType.returnType;
249+
TypeAnnotation typeName = declaration.functionType?.returnType;
250250
if (typeName != null) {
251251
typeFound = typeName.type;
252252
}

pkg/analyzer_plugin/test/utilities/completion/type_member_contributor_test.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2070,6 +2070,14 @@ void f(C<int> c) {
20702070
expect(suggestion.element.parameters, '(int value)');
20712071
}
20722072

2073+
test_genericTypeAlias_noFunctionType() async {
2074+
addTestSource('''
2075+
typedef F=;
2076+
g(F.^
2077+
''');
2078+
await computeSuggestions();
2079+
}
2080+
20732081
test_IfStatement() async {
20742082
// SimpleIdentifier IfStatement
20752083
addTestSource('''

0 commit comments

Comments
 (0)