From 03614c9bb6f711dc9f83e52a617fc985ed3b0258 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Sun, 8 Nov 2020 11:26:29 +0100 Subject: [PATCH 1/2] Remove internal.quoted.ExprCastError --- library/src-bootstrapped/scala/quoted/Expr.scala | 4 ++-- library/src/scala/internal/quoted/ExprCastError.scala | 4 ---- 2 files changed, 2 insertions(+), 6 deletions(-) delete mode 100644 library/src/scala/internal/quoted/ExprCastError.scala diff --git a/library/src-bootstrapped/scala/quoted/Expr.scala b/library/src-bootstrapped/scala/quoted/Expr.scala index 1baab90f23d8..4b93adeefdb5 100644 --- a/library/src-bootstrapped/scala/quoted/Expr.scala +++ b/library/src-bootstrapped/scala/quoted/Expr.scala @@ -32,8 +32,8 @@ abstract class Expr[+T] private[scala] { if isExprOf[X] then this.asInstanceOf[scala.quoted.Expr[X]] else - throw new scala.internal.quoted.ExprCastError( - s"""Expr: ${this.show} + throw Exception( + s"""Expr cast exception: ${this.show} |of type: ${this.unseal.tpe.show} |did not conform to type: ${tp.unseal.tpe.show} |""".stripMargin diff --git a/library/src/scala/internal/quoted/ExprCastError.scala b/library/src/scala/internal/quoted/ExprCastError.scala deleted file mode 100644 index 75e7f8e6b6b9..000000000000 --- a/library/src/scala/internal/quoted/ExprCastError.scala +++ /dev/null @@ -1,4 +0,0 @@ -package scala.internal.quoted - -/** Exception thrown when an `Expr[?]` is casted to a `Expr[U]` and the expression is not of type `U` */ -private[scala] class ExprCastError(msg: String) extends Throwable(msg) From 27f7925c1578d00fe37a3a1fcb8c10aad9e27190 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Sun, 8 Nov 2020 11:33:20 +0100 Subject: [PATCH 2/2] Remove internal.quoted.ScopeException --- library/src-bootstrapped/scala/internal/quoted/Expr.scala | 2 +- library/src-bootstrapped/scala/internal/quoted/Type.scala | 2 +- library/src/scala/internal/quoted/ScopeException.scala | 4 ---- staging/src/scala/quoted/staging/Toolbox.scala | 2 +- tests/run-staging/i4730.scala | 4 ++-- tests/run-staging/i6754.scala | 2 +- tests/run-staging/i6992/Macro_1.scala | 2 +- 7 files changed, 7 insertions(+), 11 deletions(-) delete mode 100644 library/src/scala/internal/quoted/ScopeException.scala diff --git a/library/src-bootstrapped/scala/internal/quoted/Expr.scala b/library/src-bootstrapped/scala/internal/quoted/Expr.scala index 59155793c59d..dccb380155af 100644 --- a/library/src-bootstrapped/scala/internal/quoted/Expr.scala +++ b/library/src-bootstrapped/scala/internal/quoted/Expr.scala @@ -24,7 +24,7 @@ final class Expr[Tree](val tree: Tree, val scopeId: Int) extends scala.quoted.Ex def checkScopeId(expectedScopeId: Int): Unit = if expectedScopeId != scopeId then - throw new scala.internal.quoted.ScopeException("Cannot call `scala.quoted.staging.run(...)` within a macro or another `run(...)`") + throw new Exception("Cannot call `scala.quoted.staging.run(...)` within a macro or another `run(...)`") override def hashCode: Int = tree.hashCode override def toString: String = "'{ ... }" diff --git a/library/src-bootstrapped/scala/internal/quoted/Type.scala b/library/src-bootstrapped/scala/internal/quoted/Type.scala index 21df0a626978..0edab8fe4247 100644 --- a/library/src-bootstrapped/scala/internal/quoted/Type.scala +++ b/library/src-bootstrapped/scala/internal/quoted/Type.scala @@ -19,7 +19,7 @@ final class Type[Tree](val typeTree: Tree, val scopeId: Int) extends scala.quote def checkScopeId(expectedScopeId: Int): Unit = if expectedScopeId != scopeId then - throw new scala.internal.quoted.ScopeException("Cannot call `scala.quoted.staging.run(...)` within a macro or another `run(...)`") + throw new Exception("Cannot call `scala.quoted.staging.run(...)` within a macro or another `run(...)`") override def hashCode: Int = typeTree.hashCode override def toString: String = "'[ ... ]" diff --git a/library/src/scala/internal/quoted/ScopeException.scala b/library/src/scala/internal/quoted/ScopeException.scala deleted file mode 100644 index 30b23905eef3..000000000000 --- a/library/src/scala/internal/quoted/ScopeException.scala +++ /dev/null @@ -1,4 +0,0 @@ -package scala.internal.quoted - -/** Exception thrown when an Expr or Type is used ouside of the scope where it is valid */ -private[scala] class ScopeException(msg: String) extends Exception(msg) diff --git a/staging/src/scala/quoted/staging/Toolbox.scala b/staging/src/scala/quoted/staging/Toolbox.scala index 765ef0b29b99..c0128b151dcb 100644 --- a/staging/src/scala/quoted/staging/Toolbox.scala +++ b/staging/src/scala/quoted/staging/Toolbox.scala @@ -31,7 +31,7 @@ object Toolbox: def run[T](exprBuilder: QuoteContext => Expr[T]): T = synchronized { try if (running) // detected nested run - throw new scala.internal.quoted.ScopeException("Cannot call `scala.quoted.staging.run(...)` within a another `run(...)`") + throw new Exception("Cannot call `scala.quoted.staging.run(...)` within a another `run(...)`") running = true driver.run(exprBuilder, settings) finally diff --git a/tests/run-staging/i4730.scala b/tests/run-staging/i4730.scala index 19168431def1..36540d2c8082 100644 --- a/tests/run-staging/i4730.scala +++ b/tests/run-staging/i4730.scala @@ -5,7 +5,7 @@ object Test { given Toolbox = Toolbox.make(getClass.getClassLoader) def ret(using QuoteContext): Expr[Int => Int] = '{ (x: Int) => ${ - val z = run('{x + 1}) // throws a RunScopeException + val z = run('{x + 1}) // throws Exception("Cannot call `scala.quoted.staging.run(...)` within a another `run(...)`") Expr(z) } } @@ -21,7 +21,7 @@ package scala { run(Test.ret).apply(10) throw new Exception } catch { - case ex: scala.internal.quoted.ScopeException => + case ex: Exception if ex.getMessage == "Cannot call `scala.quoted.staging.run(...)` within a another `run(...)`" => // ok } } diff --git a/tests/run-staging/i6754.scala b/tests/run-staging/i6754.scala index 6530d297f122..1a228bfff698 100644 --- a/tests/run-staging/i6754.scala +++ b/tests/run-staging/i6754.scala @@ -22,7 +22,7 @@ package scala { throw new Exception } catch { case ex: java.lang.reflect.InvocationTargetException => - assert(ex.getTargetException.isInstanceOf[scala.internal.quoted.ScopeException]) + assert(ex.getTargetException.getMessage == "Cannot call `scala.quoted.staging.run(...)` within a another `run(...)`") } } } diff --git a/tests/run-staging/i6992/Macro_1.scala b/tests/run-staging/i6992/Macro_1.scala index 950ff8efc87e..b7b115cce1d2 100644 --- a/tests/run-staging/i6992/Macro_1.scala +++ b/tests/run-staging/i6992/Macro_1.scala @@ -25,7 +25,7 @@ package scala { case '{$x: Foo} => Expr(run(x).x) } } catch { - case ex: scala.internal.quoted.ScopeException => + case ex: Exception if ex.getMessage == "Cannot call `scala.quoted.staging.run(...)` within a macro or another `run(...)`" => '{"OK"} } }