Skip to content

Remove internal.quoted.{ExprCastError, ScopeException} #10229

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion library/src-bootstrapped/scala/internal/quoted/Expr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "'{ ... }"
Expand Down
2 changes: 1 addition & 1 deletion library/src-bootstrapped/scala/internal/quoted/Type.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "'[ ... ]"
Expand Down
4 changes: 2 additions & 2 deletions library/src-bootstrapped/scala/quoted/Expr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions library/src/scala/internal/quoted/ExprCastError.scala

This file was deleted.

4 changes: 0 additions & 4 deletions library/src/scala/internal/quoted/ScopeException.scala

This file was deleted.

2 changes: 1 addition & 1 deletion staging/src/scala/quoted/staging/Toolbox.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/run-staging/i4730.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand All @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/run-staging/i6754.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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(...)`")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/run-staging/i6992/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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(...)`" =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test is a little brittle. I guess it is temporary given the other refactoring is in process.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I manage to create the exception class in the compiler code. Then the tests would need to have the compiler in the classpath to know that exception type. For this I must first move the implementation of scala.internal.quoted.Expr into the compiler which is in process.

'{"OK"}
}
}
Expand Down