Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing error messages to asserts in QuotesImpl #21852

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala
Original file line number Diff line number Diff line change
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)
assert(sym.isTerm, s"expected a term symbol but received $sym")
KacperFKorban marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -1162,7 +1162,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler

object TypeIdent extends TypeIdentModule:
def apply(sym: Symbol): TypeTree =
assert(sym.isType)
assert(sym.isType, s"Expected a type symbol, but got $sym")
withDefaultPos(tpd.ref(sym).asInstanceOf[tpd.TypeTree])
def copy(original: Tree)(name: String): TypeIdent =
tpd.cpy.Ident(original)(name.toTypeName)
Expand Down
18 changes: 18 additions & 0 deletions tests/neg/i20946.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

-- Error: tests/neg/i20946/Test_2.scala:5:29 ---------------------------------------------------------------------------
5 | macroWithAssertFailing[Int](123) // error
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| Exception occurred while executing macro expansion.
| java.lang.AssertionError: assertion failed: expected a term symbol but received class Int
| at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
| at scala.quoted.runtime.impl.QuotesImpl$reflect$Ref$.apply(QuotesImpl.scala:475)
| at scala.quoted.runtime.impl.QuotesImpl$reflect$Ref$.apply(QuotesImpl.scala:474)
| at Macro_1$package$.macroWithAssertFailingImpl(Macro_1.scala:6)
|
|---------------------------------------------------------------------------------------------------------------------
|Inline stack trace
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|This location contains code that was inlined from Test_2.scala:1
1 |inline def macroWithAssertFailing[T](t: T): Unit = ${ macroWithAssertFailingImpl[T]('t) }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
---------------------------------------------------------------------------------------------------------------------
10 changes: 10 additions & 0 deletions tests/neg/i20946/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import scala.quoted.*

def macroWithAssertFailingImpl[T: Type](t: Expr[T])(using Quotes): Expr[Unit] = {
import quotes.reflect.*

Ref(TypeRepr.of[T].typeSymbol)

'{()}
}

6 changes: 6 additions & 0 deletions tests/neg/i20946/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
inline def macroWithAssertFailing[T](t: T): Unit = ${ macroWithAssertFailingImpl[T]('t) }

@main
def run =
macroWithAssertFailing[Int](123) // error

18 changes: 18 additions & 0 deletions tests/neg/i20946a.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

-- Error: tests/neg/i20946a/Test_2.scala:5:29 --------------------------------------------------------------------------
5 | macroWithAssertFailing[Int](123) // error
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| Exception occurred while executing macro expansion.
| java.lang.AssertionError: assertion failed: Expected a type symbol, but got val <none>
| at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
| at scala.quoted.runtime.impl.QuotesImpl$reflect$TypeIdent$.apply(QuotesImpl.scala:1165)
| at scala.quoted.runtime.impl.QuotesImpl$reflect$TypeIdent$.apply(QuotesImpl.scala:1164)
| at Macro_1$package$.macroWithAssertFailingImpl(Macro_1.scala:6)
|
|---------------------------------------------------------------------------------------------------------------------
|Inline stack trace
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|This location contains code that was inlined from Test_2.scala:1
1 |inline def macroWithAssertFailing[T](t: T): Unit = ${ macroWithAssertFailingImpl[T]('t) }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
---------------------------------------------------------------------------------------------------------------------
10 changes: 10 additions & 0 deletions tests/neg/i20946a/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import scala.quoted.*

def macroWithAssertFailingImpl[T: Type](t: Expr[T])(using Quotes): Expr[Unit] = {
import quotes.reflect.*

TypeIdent(t.asTerm.symbol)

'{()}
}

6 changes: 6 additions & 0 deletions tests/neg/i20946a/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
inline def macroWithAssertFailing[T](t: T): Unit = ${ macroWithAssertFailingImpl[T]('t) }

@main
def run =
macroWithAssertFailing[Int](123) // error

Loading