Skip to content

Crash in desugaring due to Thicket reaching a match unexpectedly #25682

@SolalPirelli

Description

@SolalPirelli

Compiler version

3.8.3-RC3

Minimized code

object Anno$ extends scala.annotation.StaticAnnotation {  
  def apply[T: reflect.ClassTag](x$0: String): T = macro Anno$$.macro$1
}
object Anno$$ {
 def macro$1(c: scala.reflect.macros.blackbox.Context)(x$0: c.Expr[String]): c.Expr[Any] = {
   import c.universe._
   c.Expr(q"""
     println("Hello World!")
     """)
   }
}
@Anno$(s"Hello World!")
class MaliciousClass

Output (click arrow to expand)

Details
Exception in thread "main" scala.MatchError: Thicket(TypeDef(T,TypeBoundsTree(EmptyTree,EmptyTree,EmptyTree)), ValDef(given_ClassTag_T,ContextBoundTypeTree(Select(Ident(reflect),ClassTag),T,),EmptyTree)) (of class dotty.tools.dotc.ast.Trees$Thicket)
	at dotty.tools.dotc.ast.desugar$.apply(Desugar.scala:2441)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3890)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3930)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:4017)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:4022)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:4134)
	at dotty.tools.dotc.typer.Namer.typedAheadExpr$$anonfun$1(Namer.scala:1831)
	at dotty.tools.dotc.typer.Namer.typedAhead(Namer.scala:1821)
	at dotty.tools.dotc.typer.Namer.typedAheadExpr(Namer.scala:1831)
	at dotty.tools.dotc.typer.Namer.$anonfun$33(Namer.scala:1987)
	at scala.collection.immutable.List.map(List.scala:240)
	at dotty.tools.dotc.typer.Namer.defDefSig(Namer.scala:1987)
	at dotty.tools.dotc.typer.Namer$Completer.typeSig(Namer.scala:847)
	at dotty.tools.dotc.typer.Namer$Completer.completeInCreationContext(Namer.scala:1013)
	at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:876)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:176)
	at dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:190)
	at dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:192)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:404)
	at dotty.tools.dotc.typer.Typer.retrieveSym(Typer.scala:3783)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3808)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3929)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:4017)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:4022)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:4044)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:4091)
	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:3482)
	at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3824)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3828)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3929)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:4017)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:4022)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:4044)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:4091)
	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:3482)
	at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3824)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3828)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3929)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:4017)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:4022)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:4044)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:4091)
	at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:3617)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3870)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3930)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:4017)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:4022)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:4134)
	at dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$1(TyperPhase.scala:47)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at dotty.tools.dotc.core.Phases$Phase.monitor(Phases.scala:539)
	at dotty.tools.dotc.typer.TyperPhase.typeCheck(TyperPhase.scala:53)
	at dotty.tools.dotc.typer.TyperPhase.$anonfun$4(TyperPhase.scala:99)
	at scala.collection.Iterator$$anon$6.hasNext(Iterator.scala:495)
	at scala.collection.Iterator$$anon$9.hasNext(Iterator.scala:597)
	at scala.collection.immutable.List.prependedAll(List.scala:156)
	at scala.collection.immutable.List$.from(List.scala:681)
	at scala.collection.immutable.List$.from(List.scala:681)
	at scala.collection.IterableOps$WithFilter.map(Iterable.scala:906)
	at dotty.tools.dotc.typer.TyperPhase.runOn(TyperPhase.scala:98)
	at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:380)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1324)
	at dotty.tools.dotc.Run.runPhases$1(Run.scala:373)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1$$anonfun$2(Run.scala:420)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1$$anonfun$adapted$1(Run.scala:420)
	at scala.Function0.apply$mcV$sp(Function0.scala:42)
	at dotty.tools.dotc.Run.showProgress(Run.scala:482)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:420)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:432)
	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:69)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:432)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:325)
	at dotty.tools.repl.ReplCompiler.compile(ReplCompiler.scala:90)
	at dotty.tools.repl.ReplDriver.compile(ReplDriver.scala:400)
	at dotty.tools.repl.ReplDriver.interpret(ReplDriver.scala:363)
	at dotty.tools.repl.ReplDriver.$anonfun$4(ReplDriver.scala:252)
	at dotty.tools.repl.JLineTerminal.withMonitoringCtrlC(JLineTerminal.scala:125)
	at dotty.tools.repl.ReplDriver.loop$1(ReplDriver.scala:253)
	at dotty.tools.repl.ReplDriver.runUntilQuit$$anonfun$1(ReplDriver.scala:259)
	at dotty.tools.repl.ReplDriver.withRedirectedOutput(ReplDriver.scala:293)
	at dotty.tools.repl.ReplDriver.runBody$$anonfun$1(ReplDriver.scala:267)
	at dotty.tools.repl.ScalaClassLoader$.asContext(ScalaClassLoader.scala:32)
	at dotty.tools.repl.ReplDriver.runBody(ReplDriver.scala:267)
	at dotty.tools.repl.ReplDriver.runUntilQuit(ReplDriver.scala:259)
	at dotty.tools.repl.ReplDriver.tryRunning(ReplDriver.scala:166)
	at dotty.tools.repl.Main$.main(Main.scala:8)
	at dotty.tools.repl.Main.main(Main.scala)

Thanks to OSTIF/Quarkslab for finding this

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions