Completion. Issue 54870. Suggest members of non-nullable extensions for nullable targets.

Bug: https://github.com/dart-lang/sdk/issues/54870
Change-Id: I58f26e59002da6b76d8d3a88ffdb9b47e0c5794a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/355509
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov 2024-03-04 23:53:28 +00:00 committed by Commit Queue
parent 4b21b557e4
commit c83c1aab9d
2 changed files with 21 additions and 7 deletions

View file

@ -82,13 +82,10 @@ class ExtensionMemberContributor extends DartCompletionContributor {
// to ensure that we can return the suggestions from other providers.
return;
}
var containingNode = request.target.containingNode;
if (containingNode is PropertyAccess &&
containingNode.operator.lexeme == '?.') {
// After a null-safe operator we know that the member will only be
// invoked on a non-null value.
type = containingLibrary.typeSystem.promoteToNonNull(type);
}
// Ignore nullability, consistent with non-extension members.
type = containingLibrary.typeSystem.promoteToNonNull(type);
_addExtensionMembers(extensions, defaultKind, type);
expression.staticType;
}

View file

@ -383,6 +383,23 @@ suggestions
''');
}
Future<void> test_propertyAccess_matches_ignoreNullability() async {
await computeSuggestions('''
extension E on int {
int get a0 => 0;
}
void f(int? x) {
x.^
}
''');
assertResponse(r'''
suggestions
a0
kind: getter
''');
}
Future<void> test_propertyAccess_matches_partial() async {
await computeSuggestions('''
extension E on int {