Skip to content

Drill into QuotePattern bindings symbol info #22987

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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/ast/Trees.scala
Original file line number Diff line number Diff line change
Expand Up @@ -741,11 +741,11 @@ object Trees {
}

/** A tree representing a quote pattern `'{ type binding1; ...; body }` or `'[ type binding1; ...; body ]`.
* `QuotePattern`s are created the type checker when typing an `untpd.Quote` in a pattern context.
* `QuotePattern`s are created by the type checker when typing an `untpd.Quote` in a pattern context.
*
* `QuotePattern`s are checked are encoded into `unapply`s in the `staging` phase.
*
* The `bindings` contain the list of quote pattern type variable definitions (`Bind`s) in the oreder in
* The `bindings` contain the list of quote pattern type variable definitions (`Bind`s) in the order in
* which they are defined in the source.
*
* @param bindings Type variable definitions (`Bind` tree)
Expand Down
25 changes: 24 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/CheckUnused.scala
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,19 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
override def prepareForBind(tree: Bind)(using Context): Context =
refInfos.register(tree)
ctx
/* cf QuotePattern
override def transformBind(tree: Bind)(using Context): tree.type =
tree.symbol.info match
case TypeBounds(lo, hi) =>
def resolve(tpe: Type): Unit =
val sym = tpe.typeSymbol
if sym.exists then
resolveUsage(sym, sym.name, NoPrefix)
resolve(lo)
resolve(hi)
case _ =>
tree
*/

override def prepareForValDef(tree: ValDef)(using Context): Context =
if !tree.symbol.is(Deferred) && tree.rhs.symbol != defn.Predef_undefined then
Expand Down Expand Up @@ -250,7 +263,17 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
case Splice(expr) =>
transformAllDeep(expr)
case QuotePattern(bindings, body, quotes) =>
bindings.foreach(transformAllDeep)
bindings.foreach:
case b @ Bind(_, _) =>
b.symbol.info match
case TypeBounds(lo, hi) =>
def resolve(tpe: Type): Unit =
val sym = tpe.typeSymbol
if sym.exists then
resolveUsage(sym, sym.name, NoPrefix)
resolve(lo)
resolve(hi)
case _ =>
transformAllDeep(body)
transformAllDeep(quotes)
case SplicePattern(body, typeargs, args) =>
Expand Down
9 changes: 9 additions & 0 deletions tests/warn/i22981.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//> using options -Werror -Wunused:all
import scala.quoted.*

object test {
import scala.concurrent.duration.FiniteDuration

def applyImpl[A: Type](using Quotes): Expr[Unit] =
Type.of[A] match { case '[type d <: FiniteDuration; d] => '{ () } }
}
Loading