Skip to content

Commit 8e6f43e

Browse files
committed
Drill into QuotePattern bindings symbol info
1 parent 2f32850 commit 8e6f43e

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

compiler/src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,11 +741,11 @@ object Trees {
741741
}
742742

743743
/** A tree representing a quote pattern `'{ type binding1; ...; body }` or `'[ type binding1; ...; body ]`.
744-
* `QuotePattern`s are created the type checker when typing an `untpd.Quote` in a pattern context.
744+
* `QuotePattern`s are created by the type checker when typing an `untpd.Quote` in a pattern context.
745745
*
746746
* `QuotePattern`s are checked are encoded into `unapply`s in the `staging` phase.
747747
*
748-
* The `bindings` contain the list of quote pattern type variable definitions (`Bind`s) in the oreder in
748+
* The `bindings` contain the list of quote pattern type variable definitions (`Bind`s) in the order in
749749
* which they are defined in the source.
750750
*
751751
* @param bindings Type variable definitions (`Bind` tree)

compiler/src/dotty/tools/dotc/transform/CheckUnused.scala

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,19 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
154154
override def prepareForBind(tree: Bind)(using Context): Context =
155155
refInfos.register(tree)
156156
ctx
157+
/* cf QuotePattern
158+
override def transformBind(tree: Bind)(using Context): tree.type =
159+
tree.symbol.info match
160+
case TypeBounds(lo, hi) =>
161+
def resolve(tpe: Type): Unit =
162+
val sym = tpe.typeSymbol
163+
if sym.exists then
164+
resolveUsage(sym, sym.name, NoPrefix)
165+
resolve(lo)
166+
resolve(hi)
167+
case _ =>
168+
tree
169+
*/
157170

158171
override def prepareForValDef(tree: ValDef)(using Context): Context =
159172
if !tree.symbol.is(Deferred) && tree.rhs.symbol != defn.Predef_undefined then
@@ -250,7 +263,17 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
250263
case Splice(expr) =>
251264
transformAllDeep(expr)
252265
case QuotePattern(bindings, body, quotes) =>
253-
bindings.foreach(transformAllDeep)
266+
bindings.foreach:
267+
case b @ Bind(_, _) =>
268+
b.symbol.info match
269+
case TypeBounds(lo, hi) =>
270+
def resolve(tpe: Type): Unit =
271+
val sym = tpe.typeSymbol
272+
if sym.exists then
273+
resolveUsage(sym, sym.name, NoPrefix)
274+
resolve(lo)
275+
resolve(hi)
276+
case _ =>
254277
transformAllDeep(body)
255278
transformAllDeep(quotes)
256279
case SplicePattern(body, typeargs, args) =>

tests/warn/i22981.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//> using options -Werror -Wunused:all
2+
import scala.quoted.*
3+
4+
object test {
5+
import scala.concurrent.duration.FiniteDuration
6+
7+
def applyImpl[A: Type](using Quotes): Expr[Unit] =
8+
Type.of[A] match { case '[type d <: FiniteDuration; d] => '{ () } }
9+
}

0 commit comments

Comments
 (0)