Skip to content

Commit a7213cc

Browse files
committed
Fix extension method search in implicit scope
The case where a scope contained only extension methods but no other givens was mishandled.
1 parent 3e89b56 commit a7213cc

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

compiler/src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,9 @@ object Implicits {
236236
}
237237

238238

239-
if (refs.isEmpty) Nil
240-
else {
239+
if refs.isEmpty && (!considerExtension || companionRefs.isEmpty) then
240+
Nil
241+
else
241242
val nestedCtx = ctx.fresh.addMode(Mode.TypevarsMissContext)
242243

243244
def matchingCandidate(ref: ImplicitRef, extensionOnly: Boolean): Option[Candidate] =
@@ -254,7 +255,6 @@ object Implicits {
254255
val implicitCandidates =
255256
refs.flatMap(matchingCandidate(_, extensionOnly = false))
256257
extensionCandidates ::: implicitCandidates
257-
}
258258
}
259259
}
260260

@@ -1652,6 +1652,8 @@ final class SearchRoot extends SearchHistory {
16521652
sealed class TermRefSet(using Context):
16531653
private val elems = new java.util.LinkedHashMap[TermSymbol, List[Type]]
16541654

1655+
def isEmpty = elems.size == 0
1656+
16551657
def += (ref: TermRef): Unit = {
16561658
val pre = ref.prefix
16571659
val sym = ref.symbol.asTerm

tests/pos/implicit-scope.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ object A {
99
type FlagSet = opaques.FlagSet
1010
def FlagSet(bits: Long): FlagSet = opaques.FlagSet(bits)
1111

12-
extension on (xs: FlagSet) {
12+
extension (xs: FlagSet) {
1313
def bits: Long = opaques.toBits(xs)
1414
def | (ys: FlagSet): FlagSet = FlagSet(xs.bits | ys.bits)
1515
}

0 commit comments

Comments
 (0)