@@ -8,6 +8,7 @@ import dotty.tools.dotc.quoted.QuotesCache
88import dotty .tools .io .{AbstractFile , Directory , PlainDirectory , VirtualDirectory }
99import dotty .tools .repl .AbstractFileClassLoader
1010import dotty .tools .dotc .reporting ._
11+ import dotty .tools .dotc .config .Settings .Setting .value
1112import dotty .tools .dotc .util .ClasspathFromClassloader
1213import scala .quoted ._
1314import scala .quoted .staging .Compiler
@@ -40,7 +41,20 @@ private class QuoteDriver(appClassloader: ClassLoader) extends Driver:
4041 setCompilerSettings(ctx1.fresh.setSetting(ctx1.settings.outputDir, outDir), settings)
4142 }
4243
43- new QuoteCompiler ().newRun(ctx).compileExpr(exprBuilder) match
44+ val compiledExpr =
45+ try
46+ new QuoteCompiler ().newRun(ctx).compileExpr(exprBuilder)
47+ catch case ex =>
48+ val enrichedMessage =
49+ s """ An unhandled exception was thrown in the staging compiler.
50+ |This might be caused by using an incorrect classloader
51+ |when creating the `staging.Compiler` instance with `staging.Compiler.make`.
52+ |For details, please refer to the documentation.
53+ |For non-enriched exceptions, compile with -Yno-enrich-error-messages. """ .stripMargin
54+ if ctx.settings.YnoEnrichErrorMessages .value(using ctx) then throw ex
55+ else throw new Exception (enrichStagingErrorMessage(), ex)
56+
57+ compiledExpr match
4458 case Right (value) =>
4559 value.asInstanceOf [T ]
4660
@@ -59,14 +73,13 @@ private class QuoteDriver(appClassloader: ClassLoader) extends Driver:
5973 case _ : java.lang.NoClassDefFoundError =>
6074 throw new Exception (
6175 s """ `scala.quoted.staging.run` failed to load a class.
62- |The classloader used for the `staging.Compiler` instance might not be the correct one.
63- |Make sure that this classloader is the one that loaded the missing class.
64- |Note that the classloader that loads the standard library might not be the same as
65- |the one that loaded the application classes. """ .stripMargin,
76+ |The classloader used for the `staging.Compiler` instance might not be the correct one.
77+ |Make sure that this classloader is the one that loaded the missing class.
78+ |Note that the classloader that loads the standard library might not be the same as
79+ |the one that loaded the application classes. """ .stripMargin,
6680 ex)
6781
6882 case _ => throw ex
69- end match
7083
7184 end run
7285
0 commit comments