Skip to content

Commit d9aa755

Browse files
tgodzikWojciechMazur
authored andcommitted
Fix regressions in asSeenFrom introduced in 3.7
The body of isLegalPrefix used to read: pre.isStable || !ctx.phase.isTyper but was changed to drop the second condition in #21954 (originally included in 3.6.4-RC1, reverted from 3.6.4 final but back in 3.7). This has led to a number of regressions, the last ones discussed in #23423. To make the testcases added in #21594 pass, this PR proposes a less drastic change: relax isLegalPrefix as before, unless we're doing an implicit search. This should dramatically reduce the possibility for regressions. Fixes #23423. Fixes #22676. [Cherry-picked 2e4bc0a]
1 parent 18357c7 commit d9aa755

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

compiler/src/dotty/tools/dotc/interactive/Completion.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,15 +324,15 @@ object Completion:
324324
* 8. symbol is not a constructor proxy module when in type completion mode
325325
* 9. have same term/type kind as name prefix given so far
326326
*/
327-
def isValidCompletionSymbol(sym: Symbol, completionMode: Mode, isNew: Boolean)(using Context): Boolean =
328-
327+
def isValidCompletionSymbol(sym: Symbol, completionMode: Mode, isNew: Boolean)(using Context): Boolean = try
329328
lazy val isEnum = sym.is(Enum) ||
330329
(sym.companionClass.exists && sym.companionClass.is(Enum))
331330

332331
sym.exists &&
333332
!sym.isAbsent(canForce = false) &&
334333
!sym.isPrimaryConstructor &&
335-
sym.sourceSymbol.exists &&
334+
// running sourceSymbol on ExportedTerm will force a lot of computation from collectSubTrees
335+
(sym.is(ExportedTerm) || sym.sourceSymbol.exists) &&
336336
(!sym.is(Package) || sym.is(ModuleClass)) &&
337337
!sym.isAllOf(Mutable | Accessor) &&
338338
!sym.isPackageObject &&
@@ -343,6 +343,9 @@ object Completion:
343343
(completionMode.is(Mode.Term) && (sym.isTerm || sym.is(ModuleClass))
344344
|| (completionMode.is(Mode.Type) && (sym.isType || sym.isStableMember)))
345345
)
346+
catch
347+
case NonFatal(ex) =>
348+
false
346349
end isValidCompletionSymbol
347350

348351
given ScopeOrdering(using Context): Ordering[Seq[SingleDenotation]] with

0 commit comments

Comments
 (0)