Skip to content

Cache only when the context corresponds to prefix #22982

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/CheckUnused.scala
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
def addCached(where: Context, result: Precedence): Unit =
if where.moreProperties ne null then
where.property(resolvedKey) match
case Some(resolved) =>
case Some(resolved) if where.owner.isLocalToBlock || where.owner.info =:= prefix =>
resolved.record(sym, name, prefix, result)
case none =>

Expand Down Expand Up @@ -361,7 +361,7 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
cur.property(resolvedKey) match
case Some(resolved) =>
// conservative, cache must be nested below the result context
if precedence.isNone then
if precedence.isNone && (cur.owner.isLocalToBlock || cur.owner.info =:= prefix) then
cachePoint = cur // no result yet, and future result could be cached here
resolved.hasRecord(sym, name, prefix)
case none => NoPrecedence
Expand Down
34 changes: 34 additions & 0 deletions tests/warn/i22971.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//> using options -Wunused:imports

package p:

trait Base
class Class extends Base

abstract class Entity[T: GetType]

class Thing extends Entity[Class]

trait GetType[T]

object GetType {
//implicit object GetTypeClass extends GetType[Class]
implicit val GetTypeClass: GetType[Class] = new GetType[Class] {}
}
object Main {
def main(args: Array[String]): Unit = {
import GetType.*
val e = GetTypeClass
}
}

package q:

class C:
def f =
import p.*
GetType.GetTypeClass
def g =
import p.GetType.*
GetTypeClass
class D extends p.Entity[p.Class]
Loading