diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index d7b836923471..bd4289f8d502 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -1949,9 +1949,12 @@ class Typer extends Namer */ def typedQuote(tree: untpd.Quote, pt: Type)(implicit ctx: Context): Tree = track("typedQuote") { tree.quoted match { - case untpd.Splice(innerExpr) => + case untpd.Splice(innerExpr) if tree.isTerm => ctx.warning("Canceled splice directly inside a quote. '{ ${ XYZ } } is equivalent to XYZ.", tree.sourcePos) typed(innerExpr, pt) + case untpd.TypSplice(innerType) if tree.isType => + ctx.warning("Canceled splice directly inside a quote. '[ ${ XYZ } ] is equivalent to XYZ.", tree.sourcePos) + typed(innerType, pt) case quoted if quoted.isType => ctx.compilationUnit.needsStaging = true typedTypeApply(untpd.TypeApply(untpd.ref(defn.InternalQuoted_typeQuoteR), quoted :: Nil), pt)(quoteContext).withSpan(tree.span) @@ -2027,7 +2030,7 @@ class Typer extends Namer def typedSplice(tree: untpd.Splice, pt: Type)(implicit ctx: Context): Tree = track("typedSplice") { checkSpliceOutsideQuote(tree) tree.expr match { - case untpd.Quote(innerExpr) => + case untpd.Quote(innerExpr) if innerExpr.isTerm => ctx.warning("Canceled quote directly inside a splice. ${ '{ XYZ } } is equivalent to XYZ.", tree.sourcePos) typed(innerExpr, pt) case expr => @@ -2062,7 +2065,13 @@ class Typer extends Namer def typedTypSplice(tree: untpd.TypSplice, pt: Type)(implicit ctx: Context): Tree = track("typedTypSplice") { ctx.compilationUnit.needsStaging = true checkSpliceOutsideQuote(tree) - typedSelect(untpd.Select(tree.expr, tpnme.splice), pt)(spliceContext).withSpan(tree.span) + tree.expr match { + case untpd.Quote(innerType) if innerType.isType => + ctx.warning("Canceled quote directly inside a splice. ${ '[ XYZ ] } is equivalent to XYZ.", tree.sourcePos) + typed(innerType, pt) + case expr => + typedSelect(untpd.Select(tree.expr, tpnme.splice), pt)(spliceContext).withSpan(tree.span) + } } private def checkSpliceOutsideQuote(tree: untpd.Tree)(implicit ctx: Context): Unit = { diff --git a/tests/neg/i6530.check b/tests/neg/i6530.check new file mode 100644 index 000000000000..2934daac1448 --- /dev/null +++ b/tests/neg/i6530.check @@ -0,0 +1,5 @@ +-- [E007] Type Mismatch Error: tests/neg/i6530.scala:2:26 -------------------------------------------------------------- +2 | inline def q : Int = ${ '[ Int ] } // error + | ^^^^^^^^ + | Found: quoted.Type[Int] + | Required: quoted.Expr[Int] diff --git a/tests/neg/i6530.scala b/tests/neg/i6530.scala new file mode 100644 index 000000000000..09aac71901f7 --- /dev/null +++ b/tests/neg/i6530.scala @@ -0,0 +1,4 @@ +object Macros { + inline def q : Int = ${ '[ Int ] } // error + val x : Int = 1 + q +} diff --git a/tests/neg/i6530b.scala b/tests/neg/i6530b.scala new file mode 100644 index 000000000000..bff75eba2b07 --- /dev/null +++ b/tests/neg/i6530b.scala @@ -0,0 +1,11 @@ +object Foo { + val program = '{ + val tpe: quoted.Type[Int] = ??? + val expr: quoted.Expr[Int] = ??? + + val a: quoted.Expr[Int] = ${ '[Int] } // error + val b: quoted.Expr[Int] = '{ $tpe } // error + val c: ${ '{ 43 } } = ??? // error + val d: quoted.Type[Int] = '[ $expr ] // error + } +}