Skip to content

Commit 71bb0ee

Browse files
committed
Hide quote related exceptions from users
Users should never throw or catch these exceptions.
1 parent c5dfa75 commit 71bb0ee

File tree

13 files changed

+15
-14
lines changed

13 files changed

+15
-14
lines changed

compiler/src/dotty/tools/dotc/quoted/QuoteContextImpl.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ object QuoteContextImpl {
3636

3737
private[dotty] def checkScopeId(id: ScopeId)(using Context): Unit =
3838
if (id != scopeId)
39-
throw new scala.quoted.ScopeException("Cannot call `scala.quoted.staging.run(...)` within a macro or another `run(...)`")
39+
throw new scala.internal.quoted.ScopeException("Cannot call `scala.quoted.staging.run(...)` within a macro or another `run(...)`")
4040

4141
// TODO Explore more fine grained scope ids.
4242
// This id can only differentiate scope extrusion from one compiler instance to another.

library/src-bootstrapped/scala/internal/quoted/Expr.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import scala.internal.quoted.CompilerInterface.quoteContextWithCompilerInterface
2121

2222
def unseal(using qctx: QuoteContext): qctx.reflect.Term =
2323
if (qctx.hashCode != scopeId)
24-
throw new scala.quoted.ScopeException("Cannot call `scala.quoted.staging.run(...)` within a macro or another `run(...)`")
24+
throw new scala.internal.quoted.ScopeException("Cannot call `scala.quoted.staging.run(...)` within a macro or another `run(...)`")
2525
tree.asInstanceOf[qctx.reflect.Term]
2626

2727
override def hashCode: Int = tree.hashCode

library/src-bootstrapped/scala/internal/quoted/Type.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ final class Type[Tree](val typeTree: Tree, val scopeId: Int) extends scala.quote
1616
/** View this expression `quoted.Type[T]` as a `TypeTree` */
1717
def unseal(using qctx: QuoteContext): qctx.reflect.TypeTree =
1818
if (qctx.hashCode != scopeId)
19-
throw new scala.quoted.ScopeException("Cannot call `scala.quoted.staging.run(...)` within a macro or another `run(...)`")
19+
throw new scala.internal.quoted.ScopeException("Cannot call `scala.quoted.staging.run(...)` within a macro or another `run(...)`")
2020
typeTree.asInstanceOf[qctx.reflect.TypeTree]
2121

2222
override def hashCode: Int = typeTree.hashCode

library/src-bootstrapped/scala/quoted/Expr.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ abstract class Expr[+T] private[scala] {
3232
if isExprOf[X] then
3333
this.asInstanceOf[scala.quoted.Expr[X]]
3434
else
35-
throw new tasty.reflect.ExprCastError(
35+
throw new scala.internal.quoted.ExprCastError(
3636
s"""Expr: ${this.show}
3737
|of type: ${this.unseal.tpe.show}
3838
|did not conform to type: ${tp.unseal.tpe.show}

library/src-non-bootstrapped/scala/internal/quoted/Expr.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import scala.quoted._
2020

2121
def unseal(using qctx: QuoteContext): qctx.reflect.Term =
2222
if (qctx.hashCode != scopeId)
23-
throw new scala.quoted.ScopeException("Cannot call `scala.quoted.staging.run(...)` within a macro or another `run(...)`")
23+
throw new scala.internal.quoted.ScopeException("Cannot call `scala.quoted.staging.run(...)` within a macro or another `run(...)`")
2424
tree.asInstanceOf[qctx.reflect.Term]
2525

2626
override def hashCode: Int = tree.hashCode

library/src-non-bootstrapped/scala/internal/quoted/Type.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ final class Type[Tree](val typeTree: Tree, val scopeId: Int) extends scala.quote
1515
/** View this expression `quoted.Type[T]` as a `TypeTree` */
1616
def unseal(using qctx: QuoteContext): qctx.reflect.TypeTree =
1717
if (qctx.hashCode != scopeId)
18-
throw new scala.quoted.ScopeException("Cannot call `scala.quoted.staging.run(...)` within a macro or another `run(...)`")
18+
throw new scala.internal.quoted.ScopeException("Cannot call `scala.quoted.staging.run(...)` within a macro or another `run(...)`")
1919
typeTree.asInstanceOf[qctx.reflect.TypeTree]
2020

2121
override def hashCode: Int = typeTree.hashCode
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package scala.internal.quoted
2+
3+
/** Exception thrown when an `Expr[?]` is casted to a `Expr[U]` and the expression is not of type `U` */
4+
class ExprCastError(msg: String) extends Throwable(msg)
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package scala.quoted
1+
package scala.internal.quoted
22

33
/** Exception thrown when an Expr or Type is used ouside of the scope where it is valid */
44
class ScopeException(msg: String) extends Exception(msg)

library/src/scala/tasty/reflect/ExprCastError.scala

Lines changed: 0 additions & 3 deletions
This file was deleted.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ object Toolbox:
3131
def run[T](exprBuilder: QuoteContext => Expr[T]): T = synchronized {
3232
try
3333
if (running) // detected nested run
34-
throw new ScopeException("Cannot call `scala.quoted.staging.run(...)` within a another `run(...)`")
34+
throw new scala.internal.quoted.ScopeException("Cannot call `scala.quoted.staging.run(...)` within a another `run(...)`")
3535
running = true
3636
driver.run(exprBuilder, settings)
3737
finally

tests/run-staging/i4730.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ object Test {
1414
run(ret).apply(10)
1515
throw new Exception
1616
} catch {
17-
case ex: scala.quoted.ScopeException =>
17+
case ex: scala.internal.quoted.ScopeException =>
1818
// ok
1919
}
2020
}

tests/run-staging/i6754.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ object Test {
1616
throw new Exception
1717
} catch {
1818
case ex: java.lang.reflect.InvocationTargetException =>
19-
assert(ex.getTargetException.isInstanceOf[scala.quoted.ScopeException])
19+
assert(ex.getTargetException.isInstanceOf[scala.internal.quoted.ScopeException])
2020
}
2121
}
2222
}

tests/run-staging/i6992/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ object macros {
1616
case '{$x: Foo} => Expr(run(x).x)
1717
}
1818
} catch {
19-
case ex: scala.quoted.ScopeException =>
19+
case ex: scala.internal.quoted.ScopeException =>
2020
'{"OK"}
2121
}
2222
}

0 commit comments

Comments
 (0)