Skip to content

Commit 4f61e8b

Browse files
KacperFKorbantgodzik
authored andcommitted
Change tests for i20946 to only check the assert message in code
[Cherry-picked 014d0db]
1 parent 317d759 commit 4f61e8b

File tree

7 files changed

+15
-45
lines changed

7 files changed

+15
-45
lines changed

compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
282282

283283
object DefDef extends DefDefModule:
284284
def apply(symbol: Symbol, rhsFn: List[List[Tree]] => Option[Term]): DefDef =
285-
xCheckMacroAssert(symbol.isTerm, s"expected a term symbol but received $symbol")
285+
xCheckMacroAssert(symbol.isTerm, s"expected a term symbol, but received $symbol")
286286
xCheckMacroAssert(symbol.flags.is(Flags.Method), "expected a symbol with `Method` flag set")
287287
withDefaultPos(tpd.DefDef(symbol.asTerm, prefss =>
288288
xCheckedMacroOwners(xCheckMacroValidExpr(rhsFn(prefss)), symbol).getOrElse(tpd.EmptyTree)
@@ -453,7 +453,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
453453
def term(tp: TermRef): Ref =
454454
withDefaultPos(tpd.ref(tp).asInstanceOf[tpd.RefTree])
455455
def apply(sym: Symbol): Ref =
456-
assert(sym.isTerm, s"expected a term symbol but received $sym")
456+
assert(sym.isTerm, s"expected a term symbol, but received $sym")
457457
val refTree = tpd.ref(sym) match
458458
case t @ tpd.This(ident) => // not a RefTree, so we need to work around this - issue #19732
459459
// ident in `This` can be a TypeIdent of sym, so we manually prepare the ref here,
@@ -1105,7 +1105,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
11051105
def of[T <: AnyKind](using tp: scala.quoted.Type[T]): TypeTree =
11061106
tp.asInstanceOf[TypeImpl].typeTree
11071107
def ref(sym: Symbol): TypeTree =
1108-
assert(sym.isType, "Expected a type symbol, but got " + sym)
1108+
assert(sym.isType, s"Expected a type symbol, but got $sym")
11091109
tpd.ref(sym)
11101110
end TypeTree
11111111

tests/neg/i20946.check

-18
This file was deleted.

tests/neg/i20946/Macro_1.scala

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ import scala.quoted.*
33
def macroWithAssertFailingImpl[T: Type](t: Expr[T])(using Quotes): Expr[Unit] = {
44
import quotes.reflect.*
55

6-
Ref(TypeRepr.of[T].typeSymbol)
6+
try
7+
Ref(TypeRepr.of[T].typeSymbol)
8+
catch
9+
case ex: Throwable =>
10+
if ex.getMessage().contains("expected a term symbol, but received ") then
11+
throw ex
712

813
'{()}
914
}
10-

tests/neg/i20946/Test_2.scala

-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@ inline def macroWithAssertFailing[T](t: T): Unit = ${ macroWithAssertFailingImpl
33
@main
44
def run =
55
macroWithAssertFailing[Int](123) // error
6-

tests/neg/i20946a.check

-18
This file was deleted.

tests/neg/i20946a/Macro_1.scala

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ import scala.quoted.*
33
def macroWithAssertFailingImpl[T: Type](t: Expr[T])(using Quotes): Expr[Unit] = {
44
import quotes.reflect.*
55

6-
TypeIdent(t.asTerm.symbol)
6+
try
7+
TypeIdent(t.asTerm.symbol)
8+
catch
9+
case ex: Throwable =>
10+
if ex.getMessage().contains("Expected a type symbol, but got ") then
11+
throw ex
712

813
'{()}
914
}
10-

tests/neg/i20946a/Test_2.scala

-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@ inline def macroWithAssertFailing[T](t: T): Unit = ${ macroWithAssertFailingImpl
33
@main
44
def run =
55
macroWithAssertFailing[Int](123) // error
6-

0 commit comments

Comments
 (0)