Closed
Description
Compiler version
Crashes in 3.3.2-RC1-bin-20230705-13f877b-NIGHTLY
No crash in 3.3.1-RC3
Minimized code
Macro.scala
:
import scala.quoted.*
object Macro:
transparent inline def foo: Any = ${ fooImpl }
def fooImpl(using Quotes): Expr[Any] =
import quotes.reflect.*
'{
val xxx = ${
Type.of[Int] match
case '[tpe] =>
Typed(Expr(1).asTerm, TypeTree.of[tpe]).asExpr
}
xxx
}
MacroMain.scala
:
@main def run() =
println(Macro.foo)
Output (click arrow to expand)
Exception in thread "main" java.lang.AssertionError: assertion failed: position not set for Int # -1 of class dotty.tools.dotc.ast.Trees$TypeTree in Macro.scala
at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
at dotty.tools.dotc.typer.Typer$.assertPositioned(Typer.scala:72)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3250)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3259)
at dotty.tools.dotc.typer.Typer.typedType(Typer.scala:3374)
at dotty.tools.dotc.typer.ReTyper.typedTyped(ReTyper.scala:61)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3117)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3179)
at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:165)
at dotty.tools.dotc.inlines.Inliner$InlineTyper.typedUnadapted(Inliner.scala:915)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3255)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3259)
at dotty.tools.dotc.typer.Typer.typedInlined(Typer.scala:2096)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3135)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3179)
at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:165)
at dotty.tools.dotc.inlines.Inliner$InlineTyper.typedUnadapted(Inliner.scala:915)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3255)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3259)
at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3371)
at dotty.tools.dotc.typer.Typer.typedValDef(Typer.scala:2485)
at dotty.tools.dotc.inlines.Inliner$InlineTyper.typedValDef(Inliner.scala:816)
at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3085)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3178)
at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:165)
at dotty.tools.dotc.inlines.Inliner$InlineTyper.typedUnadapted(Inliner.scala:915)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3255)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3259)
at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3281)
at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3327)
at dotty.tools.dotc.typer.Typer.typedBlockStats(Typer.scala:1162)
at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:1166)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3120)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3179)
at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:165)
at dotty.tools.dotc.inlines.Inliner$InlineTyper.typedUnadapted(Inliner.scala:915)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3255)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3259)
at dotty.tools.dotc.typer.Typer.typedInlined(Typer.scala:2096)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3135)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3179)
at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:165)
at dotty.tools.dotc.inlines.Inliner$InlineTyper.typedUnadapted(Inliner.scala:915)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3255)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3252)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3259)
at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3371)
at dotty.tools.dotc.inlines.Inliner$InlineTyper.typedSplice(Inliner.scala:841)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3157)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3179)
at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:165)
at dotty.tools.dotc.inlines.Inliner$InlineTyper.typedUnadapted(Inliner.scala:915)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3255)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3252)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3259)
at dotty.tools.dotc.inlines.Inliner.inlined(Inliner.scala:681)
at dotty.tools.dotc.inlines.Inlines$InlineCall.expand(Inlines.scala:444)
at dotty.tools.dotc.inlines.Inlines$.inlineCall(Inlines.scala:152)
at dotty.tools.dotc.typer.Typer.adaptNoArgsOther$1(Typer.scala:4030)
at dotty.tools.dotc.typer.Typer.adaptNoArgs$1(Typer.scala:4136)
at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:4342)
at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3658)
at dotty.tools.dotc.typer.ProtoTypes$FunProto.typedArg(ProtoTypes.scala:496)
at dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:897)
at dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:897)
at dotty.tools.dotc.typer.Applications$Application.addTyped$1(Applications.scala:589)
at dotty.tools.dotc.typer.Applications$Application.matchArgs(Applications.scala:653)
at dotty.tools.dotc.typer.Applications$Application.init(Applications.scala:492)
at dotty.tools.dotc.typer.Applications$TypedApply.<init>(Applications.scala:779)
at dotty.tools.dotc.typer.Applications$ApplyToUntyped.<init>(Applications.scala:896)
at dotty.tools.dotc.typer.Applications.ApplyTo(Applications.scala:1126)
at dotty.tools.dotc.typer.Applications.ApplyTo$(Applications.scala:352)
at dotty.tools.dotc.typer.Typer.ApplyTo(Typer.scala:116)
at dotty.tools.dotc.typer.Applications.simpleApply$1(Applications.scala:969)
at dotty.tools.dotc.typer.Applications.realApply$1$$anonfun$2(Applications.scala:1052)
at dotty.tools.dotc.typer.Applications$$Lambda$561/0x000000008f066c20.apply(Unknown Source)
at dotty.tools.dotc.typer.Typer.tryEither(Typer.scala:3395)
at dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:1063)
at dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:1101)
at dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:352)
at dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:116)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3112)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3179)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3255)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3259)
at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3371)
at dotty.tools.dotc.typer.Namer.typedAheadExpr$$anonfun$1(Namer.scala:1656)
at dotty.tools.dotc.typer.Namer$$Lambda$425/0x000000008e065620.apply(Unknown Source)
at dotty.tools.dotc.typer.Namer.typedAhead(Namer.scala:1646)
at dotty.tools.dotc.typer.Namer.typedAheadExpr(Namer.scala:1656)
at dotty.tools.dotc.typer.Namer.typedAheadRhs$1$$anonfun$1(Namer.scala:1915)
at dotty.tools.dotc.typer.Namer$$Lambda$779/0x000000006e1f7020.apply(Unknown Source)
at dotty.tools.dotc.inlines.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:243)
at dotty.tools.dotc.typer.Namer.typedAheadRhs$1(Namer.scala:1915)
at dotty.tools.dotc.typer.Namer.rhsType$1(Namer.scala:1923)
at dotty.tools.dotc.typer.Namer.cookedRhsType$1(Namer.scala:1941)
at dotty.tools.dotc.typer.Namer.lhsType$1(Namer.scala:1942)
at dotty.tools.dotc.typer.Namer.inferredResultType(Namer.scala:1953)
at dotty.tools.dotc.typer.Namer.inferredType$1(Namer.scala:1694)
at dotty.tools.dotc.typer.Namer.valOrDefDefSig(Namer.scala:1700)
at dotty.tools.dotc.typer.Namer.defDefSig(Namer.scala:1798)
at dotty.tools.dotc.typer.Namer$Completer.typeSig(Namer.scala:791)
at dotty.tools.dotc.typer.Namer$Completer.completeInCreationContext(Namer.scala:934)
at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:814)
at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:174)
at dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:187)
at dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:189)
at dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:393)
at dotty.tools.dotc.typer.Typer.retrieveSym(Typer.scala:3053)
at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3078)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3178)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3255)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3259)
at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3281)
at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3327)
at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2745)
at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3100)
at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3104)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3178)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3255)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3259)
at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3281)
at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3327)
at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2876)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3146)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3179)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3255)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3259)
at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3371)
at dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$1(TyperPhase.scala:44)
at dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$adapted$1(TyperPhase.scala:50)
at dotty.tools.dotc.typer.TyperPhase$$Lambda$423/0x000000008f9e8020.apply(Unknown Source)
at scala.Function0.apply$mcV$sp(Function0.scala:42)
at dotty.tools.dotc.core.Phases$Phase.monitor(Phases.scala:440)
at dotty.tools.dotc.typer.TyperPhase.typeCheck(TyperPhase.scala:50)
at dotty.tools.dotc.typer.TyperPhase.runOn$$anonfun$3(TyperPhase.scala:84)
at dotty.tools.dotc.typer.TyperPhase$$Lambda$422/0x000000008f9e7a20.applyVoid(Unknown Source)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
at scala.collection.immutable.List.foreach(List.scala:333)
at dotty.tools.dotc.typer.TyperPhase.runOn(TyperPhase.scala:84)
at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:246)
at dotty.tools.dotc.Run$$Lambda$301/0x0000000090066c20.applyVoid(Unknown Source)
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:1321)
at dotty.tools.dotc.Run.runPhases$1(Run.scala:262)
at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:270)
at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:279)
at dotty.tools.dotc.Run$$Lambda$262/0x000000008f06ea20.apply(Unknown Source)
at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:67)
at dotty.tools.dotc.Run.compileUnits(Run.scala:279)
at dotty.tools.dotc.Run.compileUnits(Run.scala:200)
at dotty.tools.dotc.Driver.finish(Driver.scala:58)
at dotty.tools.dotc.Driver.doCompile(Driver.scala:38)
at dotty.tools.dotc.Driver.process(Driver.scala:197)
at dotty.tools.dotc.Driver.process(Driver.scala:165)
at dotty.tools.dotc.Driver.process(Driver.scala:177)
at dotty.tools.dotc.Driver.main(Driver.scala:207)
at dotty.tools.dotc.Main.main(Main.scala)
Expectation
This should compile successfully as it does if at least one of the following changes to the code is applied:
inline def foo
is not transparent- the match on a type is moved outside of the splice, i.e.
Maro.scala
:
import scala.quoted.*
object Macro:
transparent inline def foo: Any = ${ fooImpl }
def fooImpl(using Quotes): Expr[Any] =
import quotes.reflect.*
Type.of[Int] match
case '[tpe] =>
'{
val xxx = ${
Typed(Expr(1).asTerm, TypeTree.of[tpe]).asExpr
}
xxx
}