Skip to content

"assertion failed: unexpected top splice outside quote" when splicing & quoting multiple times #12173

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

Closed
adamw opened this issue Apr 21, 2021 · 1 comment · Fixed by #12193
Closed
Assignees
Milestone

Comments

@adamw
Copy link
Contributor

adamw commented Apr 21, 2021

Compiler version

3.0.0-RC3

Minimized code

object TestMacro {
  inline def test[T](inline t: T): T = ${ '{ ${ 't } } }
}

object Test {
  TestMacro.test("x")
}

I know that splicing & quoting like this doesn't make much sense but this is a simplified example, and I think this should still work (or at least not give a compiler exception).

Output (click arrow to expand)

```scala [error] java.lang.AssertionError: assertion failed: unexpected top splice outside quote [error] scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8) [error] dotty.tools.dotc.transform.PickleQuotes$QuoteReifier.transformSplice(PickleQuotes.scala:315) [error] dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:130) [error] dotty.tools.dotc.transform.PickleQuotes$QuoteReifier.transform(PickleQuotes.scala:510) [error] dotty.tools.dotc.transform.PickleQuotes$QuoteReifier.transform(PickleQuotes.scala:481) [error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1367) [error] dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:120) [error] dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:90) [error] dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:155) [error] dotty.tools.dotc.transform.PickleQuotes$QuoteReifier.transform(PickleQuotes.scala:510) [error] dotty.tools.dotc.transform.PickleQuotes$QuoteReifier.transform(PickleQuotes.scala:481) [error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1341) [error] dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:120) [error] dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:90) [error] dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:155) [error] dotty.tools.dotc.transform.PickleQuotes$QuoteReifier.transform(PickleQuotes.scala:510) [error] dotty.tools.dotc.transform.PickleQuotes$QuoteReifier.transform(PickleQuotes.scala:481) [error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1367) [error] dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:120) [error] dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:90) [error] dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:155) [error] dotty.tools.dotc.transform.PickleQuotes$QuoteReifier.transform(PickleQuotes.scala:510) [error] dotty.tools.dotc.ast.TreeMapWithImplicits.traverse$1(TreeMapWithImplicits.scala:53) [error] dotty.tools.dotc.ast.TreeMapWithImplicits.transformStats(TreeMapWithImplicits.scala:60) [error] dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:111) [error] dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:90) [error] dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:155) [error] dotty.tools.dotc.transform.PickleQuotes$QuoteReifier.transform(PickleQuotes.scala:510) [error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1410) [error] dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:120) [error] dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:90) [error] dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:155) [error] dotty.tools.dotc.transform.PickleQuotes$QuoteReifier.transform(PickleQuotes.scala:510) [error] dotty.tools.dotc.ast.TreeMapWithImplicits.traverse$1(TreeMapWithImplicits.scala:53) [error] dotty.tools.dotc.ast.TreeMapWithImplicits.transformStats(TreeMapWithImplicits.scala:60) [error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1421) [error] dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:120) [error] dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:90) [error] dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:155) [error] dotty.tools.dotc.transform.PickleQuotes$QuoteReifier.transform(PickleQuotes.scala:510) [error] dotty.tools.dotc.transform.PickleQuotes$$anon$1.transform(PickleQuotes.scala:95) [error] dotty.tools.dotc.transform.MacroTransform.run(MacroTransform.scala:21) [error] dotty.tools.dotc.transform.PickleQuotes.run(PickleQuotes.scala:91) [error] dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:303) [error] scala.collection.immutable.List.map(List.scala:246) [error] dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:304) [error] dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:205) [error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15) [error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10) [error] scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323) [error] dotty.tools.dotc.Run.runPhases$5(Run.scala:215) [error] dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:223) [error] scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18) [error] dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:67) [error] dotty.tools.dotc.Run.compileUnits(Run.scala:230) [error] dotty.tools.dotc.Run.compileSources(Run.scala:166) [error] dotty.tools.dotc.Run.compile(Run.scala:150) [error] dotty.tools.dotc.Driver.doCompile(Driver.scala:39) [error] dotty.tools.xsbt.CompilerBridgeDriver.run(CompilerBridgeDriver.java:88) [error] dotty.tools.xsbt.CompilerBridge.run(CompilerBridge.java:22) [error] sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:91) [error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$7(MixedAnalyzingCompiler.scala:186) [error] scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23) [error] sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:241) [error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4(MixedAnalyzingCompiler.scala:176) [error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4$adapted(MixedAnalyzingCompiler.scala:157) [error] sbt.internal.inc.JarUtils$.withPreviousJar(JarUtils.scala:239) [error] sbt.internal.inc.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:157) [error] sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:204) [error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:528) [error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:528) [error] sbt.internal.inc.Incremental$.$anonfun$apply$5(Incremental.scala:174) [error] sbt.internal.inc.Incremental$.$anonfun$apply$5$adapted(Incremental.scala:172) [error] sbt.internal.inc.Incremental$$anon$2.run(Incremental.scala:457) [error] sbt.internal.inc.IncrementalCommon$CycleState.next(IncrementalCommon.scala:116) [error] sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:56) [error] sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:52) [error] sbt.internal.inc.IncrementalCommon.cycle(IncrementalCommon.scala:261) [error] sbt.internal.inc.Incremental$.$anonfun$incrementalCompile$8(Incremental.scala:412) [error] sbt.internal.inc.Incremental$.withClassfileManager(Incremental.scala:499) [error] sbt.internal.inc.Incremental$.incrementalCompile(Incremental.scala:399) [error] sbt.internal.inc.Incremental$.apply(Incremental.scala:166) [error] sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:528) [error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:482) [error] sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:332) [error] sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:420) [error] sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:137) [error] sbt.Defaults$.compileIncrementalTaskImpl(Defaults.scala:2346) [error] sbt.Defaults$.$anonfun$compileIncrementalTask$2(Defaults.scala:2303) [error] sbt.internal.io.Retry$.apply(Retry.scala:46) [error] sbt.internal.io.Retry$.apply(Retry.scala:28) [error] sbt.internal.io.Retry$.apply(Retry.scala:23) [error] sbt.internal.server.BspCompileTask$.compute(BspCompileTask.scala:31) [error] sbt.Defaults$.$anonfun$compileIncrementalTask$1(Defaults.scala:2299) [error] scala.Function1.$anonfun$compose$1(Function1.scala:49) [error] sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:62) [error] sbt.std.Transform$$anon$4.work(Transform.scala:68) [error] sbt.Execute.$anonfun$submit$2(Execute.scala:282) [error] sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:23) [error] sbt.Execute.work(Execute.scala:291) [error] sbt.Execute.$anonfun$submit$1(Execute.scala:282) [error] sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265) [error] sbt.CompletionService$$anon$2.call(CompletionService.scala:64) [error] java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) [error] java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [error] java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) [error] java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [error] java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [error] java.base/java.lang.Thread.run(Thread.java:834) ```
@adamw
Copy link
Contributor Author

adamw commented Apr 21, 2021

A work-around is to create a separate macro method:

import scala.quoted.*

object TestMacro {
  inline def test[T](inline t: T): T = ${ testImpl('t) }

  def testImpl[T](t: Expr[T])(using Quotes, Type[T]): Expr[T] = '{ ${ t } }
}

@nicolasstucki nicolasstucki self-assigned this Apr 21, 2021
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Apr 22, 2021
The last top level splice is handled by the Splicer

Fixes scala#12173
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Apr 26, 2021
The last top level splice is handled by the Splicer

Fixes scala#12173
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Apr 27, 2021
The last top level splice is handled by the Splicer

Fixes scala#12173
michelou pushed a commit to michelou/scala3 that referenced this issue Apr 27, 2021
The last top level splice is handled by the Splicer

Fixes scala#12173
@Kordyjan Kordyjan added this to the 3.0.1 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants