Skip to content

Compiler crash with type annotations in quotes #7521

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
biboudis opened this issue Nov 8, 2019 · 2 comments · Fixed by #8342
Closed

Compiler crash with type annotations in quotes #7521

biboudis opened this issue Nov 8, 2019 · 2 comments · Fixed by #8342

Comments

@biboudis
Copy link
Contributor

biboudis commented Nov 8, 2019

minimized code

import scala.quoted._
import scala.annotation.StaticAnnotation

object Test {
  inline def quote[T]: Unit = ${ quoteImpl[T] }
  def quoteImpl[T: Type](given qctx: QuoteContext): Expr[Unit] = '{
     class Annot extends StaticAnnotation
     var test: T @Annot = ???
  }
}

note: annotation is put inside the quote to avoid bug #7519

Stack trace
Fatal compiler crash when compiling: tests/run-macros/test:
assertion failed
dotty.DottyPredef$.assertFail(DottyPredef.scala:16)
dotty.tools.dotc.typer.TypeAssigner.assignType(TypeAssigner.scala:620)
dotty.tools.dotc.typer.Typer.assignType(Typer.scala:83)
dotty.tools.dotc.ast.tpd$TypedTreeCopier.Annotated(tpd.scala:698)
dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1338)
dotty.tools.dotc.ast.TreeTypeMap.transform(TreeTypeMap.scala:127)
dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1330)
dotty.tools.dotc.ast.TreeTypeMap.transform(TreeTypeMap.scala:127)
dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform$$anonfun$2(Trees.scala:1350)
scala.collection.immutable.List.mapConserve(List.scala:444)
dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1350)
dotty.tools.dotc.ast.Trees$Instance$TreeMap.transformSub(Trees.scala:1354)
dotty.tools.dotc.ast.TreeTypeMap.transformDefs(TreeTypeMap.scala:136)
dotty.tools.dotc.ast.TreeTypeMap.transform(TreeTypeMap.scala:106)
dotty.tools.dotc.ast.TreeTypeMap.apply(TreeTypeMap.scala:148)
dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.addTags(ReifyQuotes.scala:165)
dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.splitQuote(ReifyQuotes.scala:369)
dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transformQuotation(ReifyQuotes.scala:189)
dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:93)
dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:413)
dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1254)
dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:117)
dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:76)
dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:126)
dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:413)
dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1260)
dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:117)
dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:76)
dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:126)
dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:413)
dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:97)
dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:76)
dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:126)
dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:413)
dotty.tools.dotc.ast.TreeMapWithImplicits.traverse$1(TreeMapWithImplicits.scala:51)
dotty.tools.dotc.ast.TreeMapWithImplicits.transformStats(TreeMapWithImplicits.scala:58)
dotty.tools.dotc.ast.TreeMapWithImplicits.recur$1(TreeMapWithImplicits.scala:33)
dotty.tools.dotc.ast.TreeMapWithImplicits.recur$1(TreeMapWithImplicits.scala:39)
dotty.tools.dotc.ast.TreeMapWithImplicits.recur$1(TreeMapWithImplicits.scala:39)
dotty.tools.dotc.ast.TreeMapWithImplicits.traverse$1(TreeMapWithImplicits.scala:52)
dotty.tools.dotc.ast.TreeMapWithImplicits.transformStats(TreeMapWithImplicits.scala:58)
dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:108)
dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:76)
dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:126)
dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:413)
dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1330)
dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:101)
dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:76)
dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:126)
dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:413)
dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform$$anonfun$2(Trees.scala:1350)
scala.collection.immutable.List.mapConserve(List.scala:444)
dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1350)
dotty.tools.dotc.ast.Trees$Instance$TreeMap.transformStats(Trees.scala:1348)
dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1336)
dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:101)
dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:76)
dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:126)
dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:413)
dotty.tools.dotc.transform.ReifyQuotes$$anon$1.transform(ReifyQuotes.scala:93)
dotty.tools.dotc.transform.MacroTransform.run(MacroTransform.scala:21)
dotty.tools.dotc.transform.ReifyQuotes.run(ReifyQuotes.scala:89)
dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:315)
scala.collection.immutable.List.map(List.scala:219)
dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:316)
dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:162)
dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
dotty.tools.dotc.Run.runPhases$5(Run.scala:172)
dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:180)
dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:65)
dotty.tools.dotc.Run.compileUnits(Run.scala:187)
dotty.tools.dotc.Run.compileSources(Run.scala:124)
dotty.tools.dotc.Run.compile(Run.scala:107)
dotty.tools.dotc.Driver.doCompile(Driver.scala:36)
dotty.tools.dotc.Driver.process(Driver.scala:189)
dotty.tools.dotc.Driver.process(Driver.scala:158)
dotty.tools.vulpix.ParallelTesting$Test.compile(ParallelTesting.scala:479)
dotty.tools.vulpix.ParallelTesting$CompilationLogic.compileTestSource$$anonfun$2$$anonfun$1(ParallelTesting.scala:204)
scala.collection.immutable.List.map(List.scala:219)
dotty.tools.vulpix.ParallelTesting$CompilationLogic.compileTestSource$$anonfun$1(ParallelTesting.scala:204)
scala.util.Try$.apply(Try.scala:210)
dotty.tools.vulpix.ParallelTesting$CompilationLogic.dotty$tools$vulpix$ParallelTesting$CompilationLogic$$compileTestSource(ParallelTesting.scala:205)
dotty.tools.vulpix.ParallelTesting$$anon$2.checkTestSource$$anonfun$1(ParallelTesting.scala:248)
dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
dotty.tools.vulpix.ParallelTesting$Test.tryCompile(ParallelTesting.scala:420)
dotty.tools.vulpix.ParallelTesting$$anon$2.checkTestSource(ParallelTesting.scala:251)
dotty.tools.vulpix.ParallelTesting$Test$LoggedRunnable.run(ParallelTesting.scala:319)
dotty.tools.vulpix.ParallelTesting$$anon$2.run(ParallelTesting.scala:246)
java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1386)
java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)```
</details>
@nicolasstucki
Copy link
Contributor

This pattern should be rejected as the StaticAnnotation is not really static.

@nicolasstucki
Copy link
Contributor

#7531 fixes this particular crash but encounters another one while pickling the contents of the quote.

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 19, 2020
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 19, 2020
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 19, 2020
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 20, 2020
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 20, 2020
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 20, 2020
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 22, 2020
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 24, 2020
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.

2 participants