Skip to content

Commit 4826b64

Browse files
committed
Don't consider implicits in package prefixes
Don't consider implicits in package prefixes to be in the implicit scope of a type unless under -language:Scala2.
1 parent cd774b2 commit 4826b64

File tree

5 files changed

+32
-27
lines changed

5 files changed

+32
-27
lines changed

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

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -520,27 +520,32 @@ trait ImplicitRunInfo { self: Run =>
520520
val comps = new TermRefSet
521521
tp match {
522522
case tp: NamedType =>
523-
val pre = tp.prefix
524-
comps ++= iscopeRefs(pre)
525-
def addRef(companion: TermRef): Unit = {
526-
val compSym = companion.symbol
527-
if (compSym is Package)
528-
addRef(companion.select(nme.PACKAGE))
529-
else if (compSym.exists)
530-
comps += companion.asSeenFrom(pre, compSym.owner).asInstanceOf[TermRef]
531-
}
532-
def addCompanionOf(sym: Symbol) = {
533-
val companion = sym.companionModule
534-
if (companion.exists) addRef(companion.termRef)
535-
}
536-
def addClassScope(cls: ClassSymbol): Unit = {
537-
addCompanionOf(cls)
538-
for (parent <- cls.classParents; ref <- iscopeRefs(tp.baseType(parent.classSymbol)))
539-
addRef(ref)
523+
if (!tp.symbol.is(Package) || ctx.scala2Mode) {
524+
// Don't consider implicits in package prefixes unless under -language:Scala2
525+
val pre = tp.prefix
526+
comps ++= iscopeRefs(pre)
527+
def addRef(companion: TermRef): Unit = {
528+
val compSym = companion.symbol
529+
if (compSym is Package) {
530+
assert(ctx.scala2Mode)
531+
addRef(companion.select(nme.PACKAGE))
532+
}
533+
else if (compSym.exists)
534+
comps += companion.asSeenFrom(pre, compSym.owner).asInstanceOf[TermRef]
535+
}
536+
def addCompanionOf(sym: Symbol) = {
537+
val companion = sym.companionModule
538+
if (companion.exists) addRef(companion.termRef)
539+
}
540+
def addClassScope(cls: ClassSymbol): Unit = {
541+
addCompanionOf(cls)
542+
for (parent <- cls.classParents; ref <- iscopeRefs(tp.baseType(parent.classSymbol)))
543+
addRef(ref)
544+
}
545+
val underlyingTypeSym = tp.widen.typeSymbol
546+
if (underlyingTypeSym.isOpaqueAlias) addCompanionOf(underlyingTypeSym)
547+
else tp.classSymbols(liftingCtx).foreach(addClassScope)
540548
}
541-
val underlyingTypeSym = tp.widen.typeSymbol
542-
if (underlyingTypeSym.isOpaqueAlias) addCompanionOf(underlyingTypeSym)
543-
else tp.classSymbols(liftingCtx).foreach(addClassScope)
544549
case _ =>
545550
for (part <- tp.namedPartsWith(_.isType)) comps ++= iscopeRefs(part)
546551
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package t1000647.bar
2+
3+
import t1000647.foo.{ScalaActorRef}
4+
5+
object DataFlow {
6+
def foo(ref: ScalaActorRef) = ref.stop() // error: value stop is not a member of ...
7+
}

tests/new/package-implicit/DataFlow.scala

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)