Skip to content

Commit ea0e48a

Browse files
bwilkersoncommit-bot@chromium.org
authored andcommitted
Guard against an NPE in completion code (issue 36788)
Change-Id: I05fc48ac7ad495820c5e3f7efdb6db2096108e54 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107306 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent 89e2118 commit ea0e48a

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ class _LocalVisitor extends LocalDeclarationVisitor {
234234
_addLocalSuggestion_includeTypeNameSuggestions(
235235
declaration.documentationComment,
236236
declaration.name,
237-
declaration.functionType.returnType,
237+
declaration.functionType?.returnType,
238238
protocol.ElementKind.FUNCTION_TYPE_ALIAS,
239239
isAbstract: true,
240240
isDeprecated: isDeprecated(declaration));

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2921,6 +2921,17 @@ main() {
29212921
assertSuggestFunctionTypeAlias('F', 'void');
29222922
}
29232923

2924+
test_functionTypeAlias_genericTypeAlias_incomplete() async {
2925+
addTestSource(r'''
2926+
typedef F = int;
2927+
main() {
2928+
^
2929+
}
2930+
''');
2931+
await computeSuggestions();
2932+
assertSuggestFunctionTypeAlias('F', 'dynamic');
2933+
}
2934+
29242935
test_functionTypeAlias_old() async {
29252936
addTestSource(r'''
29262937
typedef void F();

pkg/analyzer_plugin/lib/src/utilities/visitors/local_declaration_visitor.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ abstract class LocalDeclarationVisitor extends GeneralizingAstVisitor {
131131
_visitTypeParameters(declaration, declaration.typeParameters);
132132
_visitTypeParameters(
133133
declaration.functionType,
134-
declaration.functionType.typeParameters,
134+
declaration.functionType?.typeParameters,
135135
);
136136
} else if (declaration is MixinDeclaration) {
137137
declaredMixin(declaration);

0 commit comments

Comments
 (0)