Skip to content

Commit f081910

Browse files
Merge pull request #9952 from dotty-staging/warn-users-on-non-canonical
Warn users on non canonical type references
2 parents f630a18 + 580b6fd commit f081910

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ trait QuotesAndSplices {
5757
val tree1 =
5858
if ctx.mode.is(Mode.Pattern) then
5959
typedQuotePattern(tree, pt, qctx)
60-
else if (tree.quoted.isType)
60+
else if tree.quoted.isType then
61+
report.warning(em"Consider using canonical type constructor scala.quoted.Type[${tree.quoted}] instead", tree.srcPos)
6162
typedTypeApply(untpd.TypeApply(untpd.ref(defn.QuotedTypeModule_apply.termRef), tree.quoted :: Nil), pt)(using quoteContext).select(nme.apply).appliedTo(qctx)
6263
else
6364
typedApply(untpd.Apply(untpd.ref(defn.InternalQuoted_exprQuote.termRef), tree.quoted), pt)(using pushQuoteContext(qctx)).select(nme.apply).appliedTo(qctx)
@@ -171,7 +172,9 @@ trait QuotesAndSplices {
171172
using spliceContext.retractMode(Mode.QuotedPattern).withOwner(spliceOwner(ctx)))
172173
pat.select(tpnme.spliceType)
173174
else
174-
typedSelect(untpd.Select(tree.expr, tpnme.spliceType), pt)(using spliceContext).withSpan(tree.span)
175+
val tree1 = typedSelect(untpd.Select(tree.expr, tpnme.spliceType), pt)(using spliceContext).withSpan(tree.span)
176+
report.warning(em"Consider using canonical type reference ${tree1.tpe.show} instead", tree.srcPos)
177+
tree1
175178
}
176179

177180
private def checkSpliceOutsideQuote(tree: untpd.Tree)(using Context): Unit =

tests/patmat/i9489.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import scala.quoted._
22

3-
def summonTypedType[T : Type](using QuoteContext): String = '[T] match {
3+
def summonTypedType[T : Type](using QuoteContext): String = Type[T] match {
44
case '[Boolean] => "Boolean"
55
case '[Byte] => "Byte"
66
case _ => "Other"

tests/patmat/i9489b.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import scala.quoted._
2+
3+
def summonTypedType[T : Type](using QuoteContext): String = '{ ??? : T } match {
4+
case '{ $_ : Boolean } => "Boolean"
5+
case '{ $_ : Byte } => "Byte"
6+
case _ => "Other"
7+
}

0 commit comments

Comments
 (0)