Skip to content

Commit 9a02627

Browse files
committed
Consider opaque companions in implicit scope
1 parent 9c9f46a commit 9a02627

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

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

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -421,15 +421,15 @@ trait ImplicitRunInfo { self: Run =>
421421
override implicit protected val ctx: Context = liftingCtx
422422
override def stopAtStatic = true
423423
def apply(tp: Type) = tp match {
424-
case tp: TypeRef if tp.symbol.isAbstractOrAliasType =>
424+
case tp: TypeRef if !tp.symbol.canHaveCompanion =>
425425
val pre = tp.prefix
426426
def joinClass(tp: Type, cls: ClassSymbol) =
427427
AndType.make(tp, cls.typeRef.asSeenFrom(pre, cls.owner))
428428
val lead = if (tp.prefix eq NoPrefix) defn.AnyType else apply(tp.prefix)
429429
(lead /: tp.classSymbols)(joinClass)
430430
case tp: TypeVar =>
431431
apply(tp.underlying)
432-
case tp: AppliedType if !tp.tycon.typeSymbol.isClass =>
432+
case tp: AppliedType if !tp.tycon.typeSymbol.canHaveCompanion =>
433433
def applyArg(arg: Type) = arg match {
434434
case TypeBounds(lo, hi) => AndType.make(lo, hi)
435435
case WildcardType(TypeBounds(lo, hi)) => AndType.make(lo, hi)
@@ -467,21 +467,24 @@ trait ImplicitRunInfo { self: Run =>
467467
case tp: NamedType =>
468468
val pre = tp.prefix
469469
comps ++= iscopeRefs(pre)
470-
def addClassScope(cls: ClassSymbol): Unit = {
471-
def addRef(companion: TermRef): Unit = {
472-
val compSym = companion.symbol
473-
if (compSym is Package)
474-
addRef(companion.select(nme.PACKAGE))
475-
else if (compSym.exists)
476-
comps += companion.asSeenFrom(pre, compSym.owner).asInstanceOf[TermRef]
477-
}
478-
def addParentScope(parent: Type): Unit =
479-
iscopeRefs(tp.baseType(parent.classSymbol)) foreach addRef
480-
val companion = cls.companionModule
470+
def addRef(companion: TermRef): Unit = {
471+
val compSym = companion.symbol
472+
if (compSym is Package)
473+
addRef(companion.select(nme.PACKAGE))
474+
else if (compSym.exists)
475+
comps += companion.asSeenFrom(pre, compSym.owner).asInstanceOf[TermRef]
476+
}
477+
def addCompanionOf(sym: Symbol) = {
478+
val companion = sym.companionModule
481479
if (companion.exists) addRef(companion.termRef)
482-
cls.classParents foreach addParentScope
483480
}
484-
tp.classSymbols(liftingCtx) foreach addClassScope
481+
def addClassScope(cls: ClassSymbol): Unit = {
482+
addCompanionOf(cls)
483+
for (parent <- cls.classParents; ref <- iscopeRefs(tp.baseType(parent.classSymbol)))
484+
addRef(ref)
485+
}
486+
if (tp.widen.typeSymbol.isOpaqueAlias) addCompanionOf(tp.widen.typeSymbol)
487+
else tp.classSymbols(liftingCtx).foreach(addClassScope)
485488
case _ =>
486489
for (part <- tp.namedPartsWith(_.isType)) comps ++= iscopeRefs(part)
487490
}

0 commit comments

Comments
 (0)