Skip to content

Commit 1d77824

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Issue 25538. Fix for overriding invisible private members.
[email protected] Bug: dart-lang#25538 Change-Id: I61904881c602f373df839bc546b1e65665997bb9 Reviewed-on: https://dart-review.googlesource.com/c/86480 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 6d33d03 commit 1d77824

File tree

2 files changed

+67
-4
lines changed

2 files changed

+67
-4
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,15 @@ class OverrideContributor implements DartCompletionContributor {
206206
*/
207207
List<Name> _namesToOverride(
208208
ClassElement classElement, Iterable<Name> interfaceNames) {
209-
var notDefinedNames = <Name>[];
209+
var libraryUri = classElement.library.source.uri;
210+
var namesToOverride = <Name>[];
210211
for (var name in interfaceNames) {
211-
if (!_hasMember(classElement, name.name)) {
212-
notDefinedNames.add(name);
212+
if (name.isAccessibleFor(libraryUri)) {
213+
if (!_hasMember(classElement, name.name)) {
214+
namesToOverride.add(name);
215+
}
213216
}
214217
}
215-
return notDefinedNames;
218+
return namesToOverride;
216219
}
217220
}

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

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,62 @@ method() {
175175
selectionLength: 22);
176176
}
177177

178+
test_private_otherLibrary() async {
179+
addSource('/lib.dart', '''
180+
class A {
181+
void foo() {}
182+
void _bar() {}
183+
}
184+
''');
185+
addTestSource(r'''
186+
import 'lib.dart';
187+
188+
class B extends A {
189+
f^
190+
}
191+
''');
192+
await computeSuggestions();
193+
194+
_assertOverride('''
195+
@override
196+
void foo() {
197+
// TODO: implement foo
198+
super.foo();
199+
}''', displayText: 'foo() { … }', selectionOffset: 56, selectionLength: 12);
200+
201+
expect(suggestions, _notSuggestedPredicate((suggestion) {
202+
return suggestion.completion.contains('void _bar()');
203+
}));
204+
}
205+
206+
test_private_thisLibrary() async {
207+
addTestSource(r'''
208+
class A {
209+
void foo() {}
210+
void _bar() {}
211+
}
212+
213+
class B extends A {
214+
f^
215+
}
216+
''');
217+
await computeSuggestions();
218+
219+
_assertOverride('''
220+
@override
221+
void foo() {
222+
// TODO: implement foo
223+
super.foo();
224+
}''', displayText: 'foo() { … }', selectionOffset: 56, selectionLength: 12);
225+
226+
_assertOverride('''
227+
@override
228+
void _bar() {
229+
// TODO: implement _bar
230+
super._bar();
231+
}''', displayText: '_bar() { … }', selectionOffset: 58, selectionLength: 13);
232+
}
233+
178234
test_withExistingOverride() async {
179235
addTestSource('''
180236
class A {
@@ -244,4 +300,8 @@ method() {
244300
expect(cs.displayText, displayText);
245301
return cs;
246302
}
303+
304+
static Matcher _notSuggestedPredicate(bool Function(CompletionSuggestion) f) {
305+
return isNot(contains(predicate(f)));
306+
}
247307
}

0 commit comments

Comments
 (0)