Skip to content

Commit 2c5072e

Browse files
committed
Add scala.quoted.internal.ScopeException
1 parent d307a0b commit 2c5072e

File tree

7 files changed

+12
-7
lines changed

7 files changed

+12
-7
lines changed

compiler/src/scala/quoted/internal/Expr.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ final class Expr(val tree: tpd.Tree, val scopeId: Int) extends scala.quoted.Expr
2626

2727
def checkScopeId(expectedScopeId: Int): Unit =
2828
if expectedScopeId != scopeId then
29-
throw new Exception("Cannot call `scala.quoted.staging.run(...)` within a macro or another `run(...)`")
29+
throw new ScopeException("Cannot call `scala.quoted.staging.run(...)` within a macro or another `run(...)`")
3030

3131
override def hashCode: Int = tree.hashCode
3232
override def toString: String = "'{ ... }"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package scala.quoted.internal
2+
3+
class ScopeException(msg: String) extends Exception(msg)

compiler/src/scala/quoted/internal/Type.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ final class Type(val typeTree: tpd.Tree, val scopeId: Int) extends scala.quoted.
2121

2222
def checkScopeId(expectedScopeId: Int): Unit =
2323
if expectedScopeId != scopeId then
24-
throw new Exception("Cannot call `scala.quoted.staging.run(...)` within a macro or another `run(...)`")
24+
throw new ScopeException("Cannot call `scala.quoted.staging.run(...)` within a macro or another `run(...)`")
2525

2626
override def hashCode: Int = typeTree.hashCode
2727
override def toString: String = "'[ ... ]"

staging/src/scala/quoted/staging/Toolbox.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package staging
33

44
import scala.annotation.implicitNotFound
55

6+
import scala.quoted.internal.ScopeException
7+
68
@implicitNotFound("Could not find implicit scala.quoted.staging.Toolbox.\n\nDefault toolbox can be instantiated with:\n `given scala.quoted.staging.Toolbox = scala.quoted.staging.Toolbox.make(getClass.getClassLoader)`\n\n")
79
trait Toolbox:
810
def run[T](expr: QuoteContext => Expr[T]): T
@@ -31,7 +33,7 @@ object Toolbox:
3133
def run[T](exprBuilder: QuoteContext => Expr[T]): T = synchronized {
3234
try
3335
if (running) // detected nested run
34-
throw new Exception("Cannot call `scala.quoted.staging.run(...)` within a another `run(...)`")
36+
throw new ScopeException("Cannot call `scala.quoted.staging.run(...)` within a another `run(...)`")
3537
running = true
3638
driver.run(exprBuilder, settings)
3739
finally

tests/run-staging/i4730.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ object Test {
55
given Toolbox = Toolbox.make(getClass.getClassLoader)
66
def ret(using QuoteContext): Expr[Int => Int] = '{ (x: Int) =>
77
${
8-
val z = run('{x + 1}) // throws Exception("Cannot call `scala.quoted.staging.run(...)` within a another `run(...)`")
8+
val z = run('{x + 1}) // throws scala.quoted.internal.ScopeException =>
99
Expr(z)
1010
}
1111
}
@@ -21,7 +21,7 @@ package scala {
2121
run(Test.ret).apply(10)
2222
throw new Exception
2323
} catch {
24-
case ex: Exception if ex.getMessage == "Cannot call `scala.quoted.staging.run(...)` within a another `run(...)`" =>
24+
case ex: Exception if ex.getClass.getName == "scala.quoted.internal.ScopeException" =>
2525
// ok
2626
}
2727
}

tests/run-staging/i6754.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ package scala {
2222
throw new Exception
2323
} catch {
2424
case ex: java.lang.reflect.InvocationTargetException =>
25-
assert(ex.getTargetException.getMessage == "Cannot call `scala.quoted.staging.run(...)` within a another `run(...)`")
25+
assert(ex.getTargetException.getClass.getName == "scala.quoted.internal.ScopeException")
2626
}
2727
}
2828
}

tests/run-staging/i6992/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ package scala {
2525
case '{$x: Foo} => Expr(run(x).x)
2626
}
2727
} catch {
28-
case ex: Exception if ex.getMessage == "Cannot call `scala.quoted.staging.run(...)` within a macro or another `run(...)`" =>
28+
case ex: Exception if ex.getClass.getName == "scala.quoted.internal.ScopeException" =>
2929
'{"OK"}
3030
}
3131
}

0 commit comments

Comments
 (0)