Skip to content

Commit bcc074d

Browse files
committed
Test for legitimate NoClassDefFoundError in Splicer
1 parent 69e8f19 commit bcc074d

File tree

7 files changed

+51
-2
lines changed

7 files changed

+51
-2
lines changed

compiler/src/dotty/tools/dotc/transform/Splicer.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,11 @@ object Splicer {
372372
private object MissingClassDefinedInCurrentRun {
373373
def unapply(targetException: NoClassDefFoundError)(given ctx: Context): Option[Symbol] = {
374374
val className = targetException.getMessage
375-
val sym = ctx.base.staticRef(className.toTypeName).symbol
376-
if (sym.isDefinedInCurrentRun) Some(sym) else None
375+
if (className eq null) None
376+
else {
377+
val sym = ctx.base.staticRef(className.toTypeName).symbol
378+
if (sym.isDefinedInCurrentRun) Some(sym) else None
379+
}
377380
}
378381
}
379382

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- Error: tests/neg-macros/macro-class-not-found-1/Bar.scala:4:13 ------------------------------------------------------
2+
4 | Foo.myMacro() // error
3+
| ^^^^^^^^^^^^^
4+
| Exception occurred while executing macro expansion.
5+
| java.lang.NoClassDefFoundError
6+
| at Foo$.aMacroImplementation(Foo.scala:8)
7+
|
8+
| This location is in code that was inlined at Bar.scala:4
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import scala.quoted._
2+
3+
object Bar {
4+
Foo.myMacro() // error
5+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import scala.quoted._
2+
3+
object Foo {
4+
5+
inline def myMacro(): Unit = ${ aMacroImplementation }
6+
7+
def aMacroImplementation(given QuoteContext): Expr[Unit] =
8+
throw new NoClassDefFoundError()
9+
10+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- Error: tests/neg-macros/macro-class-not-found-2/Bar.scala:4:13 ------------------------------------------------------
2+
4 | Foo.myMacro() // error
3+
| ^^^^^^^^^^^^^
4+
| Exception occurred while executing macro expansion.
5+
| java.lang.NoClassDefFoundError: this.is.not.a.Class
6+
| at Foo$.aMacroImplementation(Foo.scala:8)
7+
|
8+
| This location is in code that was inlined at Bar.scala:4
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import scala.quoted._
2+
3+
object Bar {
4+
Foo.myMacro() // error
5+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import scala.quoted._
2+
3+
object Foo {
4+
5+
inline def myMacro(): Unit = ${ aMacroImplementation }
6+
7+
def aMacroImplementation(given QuoteContext): Expr[Unit] =
8+
throw new NoClassDefFoundError("this.is.not.a.Class")
9+
10+
}

0 commit comments

Comments
 (0)