Skip to content

Commit

Permalink
Change tests for i20946 to only check the assert message in code
Browse files Browse the repository at this point in the history
  • Loading branch information
KacperFKorban committed Nov 1, 2024
1 parent 39d45dc commit 014d0db
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 45 deletions.
6 changes: 3 additions & 3 deletions compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler

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

Expand Down
18 changes: 0 additions & 18 deletions tests/neg/i20946.check

This file was deleted.

8 changes: 6 additions & 2 deletions tests/neg/i20946/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ import scala.quoted.*
def macroWithAssertFailingImpl[T: Type](t: Expr[T])(using Quotes): Expr[Unit] = {
import quotes.reflect.*

Ref(TypeRepr.of[T].typeSymbol)
try
Ref(TypeRepr.of[T].typeSymbol)
catch
case ex: Throwable =>
if ex.getMessage().contains("expected a term symbol, but received ") then
throw ex

'{()}
}

1 change: 0 additions & 1 deletion tests/neg/i20946/Test_2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ inline def macroWithAssertFailing[T](t: T): Unit = ${ macroWithAssertFailingImpl
@main
def run =
macroWithAssertFailing[Int](123) // error

18 changes: 0 additions & 18 deletions tests/neg/i20946a.check

This file was deleted.

8 changes: 6 additions & 2 deletions tests/neg/i20946a/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ import scala.quoted.*
def macroWithAssertFailingImpl[T: Type](t: Expr[T])(using Quotes): Expr[Unit] = {
import quotes.reflect.*

TypeIdent(t.asTerm.symbol)
try
TypeIdent(t.asTerm.symbol)
catch
case ex: Throwable =>
if ex.getMessage().contains("Expected a type symbol, but got ") then
throw ex

'{()}
}

1 change: 0 additions & 1 deletion tests/neg/i20946a/Test_2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ inline def macroWithAssertFailing[T](t: T): Unit = ${ macroWithAssertFailingImpl
@main
def run =
macroWithAssertFailing[Int](123) // error

0 comments on commit 014d0db

Please sign in to comment.