You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using the staging API one can extract a mutable variable into a HOAS function and then substitute another bound mutable variable. This generates an intermediate immutable binding and assigns to that one, which is wrong.
importscala.quoted._importscala.quoted.staging._objectTestextendsApp {
// make available the necessary toolbox for runtime code generationgivenToolbox=Toolbox.make(getClass.getClassLoader)
run {
valexpr:Expr[Int] ='{ varx=1; x =2; 42 }
expr match {
case'{ varx:Int= $binding; $body(x):Int } =>valres='{ vary= $binding; ${ Expr.betaReduce('{ $body(y) })}}
println(res.show)
res
case _ => println(expr.show); '{0}
}
}
}
Output (click arrow to expand)
[warn] --Warning:/Users/jonathan/playground/staging-test/src/main/scala/Main.scala:14:4
[warn] 14|valres='{ vary= $binding; ${ Expr.betaReduce('{ $body(y) })}}
[warn] |^
[warn] |Line is indented too far to the left, or a `}` is missing
[warn] --Warning:/Users/jonathan/playground/staging-test/src/main/scala/Main.scala:15:4
[warn] 15| println(res.show)
[warn] |^
[warn] |Line is indented too far to the left, or a `}` is missing
[warn] --Warning:/Users/jonathan/playground/staging-test/src/main/scala/Main.scala:16:4
[warn] 16| res
[warn] |^
[warn] |Line is indented too far to the left, or a `}` is missing
[warn] three warnings found
[info] running Test
{
vary: scala.Int=1valx: scala.Int= y
x =242
}
exception while typing x =2 of classclass dotty.tools.dotc.ast.Trees$Assign#1083
exception while typing {
valx:Int= y
x =242
} of classclass dotty.tools.dotc.ast.Trees$Block#1091
exception while typing {
{
valx:Int= y
x =242
}
} of classclass dotty.tools.dotc.ast.Trees$Inlined#1092
exception while typing {
vary:Int=
{
1
}
{
{
valx:Int= y
x =242
}
}
} of classclass dotty.tools.dotc.ast.Trees$Block#1093
exception while typing {
{
vary:Int=
{
1
}
{
{
valx:Int= y
x =242
}
}
}
} of classclass dotty.tools.dotc.ast.Trees$Inlined#1094
exception while typing defapply:Any=
{
{
vary:Int=
{
1
}
{
{
valx:Int= y
x =242
}
}
}
} of classclass dotty.tools.dotc.ast.Trees$DefDef#31
exception while typing classGenerated$Code$From$Quoted() extendsObject() {
defapply:Any=
{
{
vary:Int=
{
1
}
{
{
valx:Int= y
x =242
}
}
}
}
} of classclass dotty.tools.dotc.ast.Trees$TypeDef#33
exception while typing package_root_ {
classGenerated$Code$From$Quoted() extendsObject() {
defapply:Any=
{
{
vary:Int=
{
1
}
{
{
valx:Int= y
x =242
}
}
}
}
}
} of classclass dotty.tools.dotc.ast.Trees$PackageDef#34
[error] (run-main-4) java.lang.ExceptionInInitializerError
[error] java.lang.ExceptionInInitializerError
[error] at Test.main(Main.scala)
[error] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)
[error] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[error] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[error] at java.base/java.lang.reflect.Method.invoke(Method.java:566)
[error] Causedby: classdotty.tools.dotc.reporting.Diagnostic$Error at src/main/scala/Main.scala:<255..260>:Reassignment to valx
[error] at dotty.tools.dotc.report$.error(report.scala:71)
[error] at dotty.tools.dotc.typer.ErrorReporting$.errorType(ErrorReporting.scala:29)
[error] at dotty.tools.dotc.typer.ErrorReporting$.errorTree(ErrorReporting.scala:20)
[error] at dotty.tools.dotc.typer.ErrorReporting$.errorTree(ErrorReporting.scala:23)
[error] at dotty.tools.dotc.typer.Typer.reassignmentToVal$1(Typer.scala:826)
[error] at dotty.tools.dotc.typer.Typer.typedAssign(Typer.scala:884)
[error] at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2463)
[error] at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2517)
[error] at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:122)
[error] at dotty.tools.dotc.typer.Typer.op$proxy16$1(Typer.scala:2586)
[error] at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2587)
[error] at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2590)
[error] at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2638)
[error] at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2661)
[error] at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:979)
[error] at dotty.tools.dotc.typer.Typer.typedBlockStats(Typer.scala:896)
[error] at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:900)
[error] at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2464)
[error] at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2517)
[error] at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:122)
[error] at dotty.tools.dotc.typer.Typer.op$proxy16$1(Typer.scala:2586)
[error] at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2587)
[error] at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2590)
[error] at dotty.tools.dotc.typer.Typer.typedInlined(Typer.scala:1629)
[error] at dotty.tools.dotc.transform.Erasure$Typer.typedInlined(Erasure.scala:840)
[error] at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2477)
[error] at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2517)
[error] at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:122)
[error] at dotty.tools.dotc.typer.Typer.op$proxy16$1(Typer.scala:2586)
[error] at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2587)
[error] at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2590)
[error] at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2705)
[error] at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:902)
[error] at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2464)
[error] at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2517)
[error] at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:122)
[error] at dotty.tools.dotc.typer.Typer.op$proxy16$1(Typer.scala:2586)
[error] at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2587)
[error] at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2590)
[error] at dotty.tools.dotc.typer.Typer.typedInlined(Typer.scala:1629)
[error] at dotty.tools.dotc.transform.Erasure$Typer.typedInlined(Erasure.scala:840)
[error] at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2477)
[error] at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2517)
[error] at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:122)
[error] at dotty.tools.dotc.typer.Typer.op$proxy16$1(Typer.scala:2586)
[error] at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2587)
[error] at dotty.tools.dotc.typer.Typer.op$proxy16$1(Typer.scala:2583)
[error] at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2587)
[error] at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2590)
[error] at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2705)
[error] at dotty.tools.dotc.typer.Typer.$anonfun$34(Typer.scala:1981)
[error] at dotty.tools.dotc.typer.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:217)
[error] at dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:1981)
[error] at dotty.tools.dotc.transform.Erasure$Typer.typedDefDef(Erasure.scala:892)
[error] at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2433)
[error] at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2516)
[error] at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:122)
[error] at dotty.tools.dotc.typer.Typer.op$proxy16$1(Typer.scala:2586)
[error] at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2587)
[error] at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2590)
[error] at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2612)
[error] at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2661)
[error] at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:979)
[error] at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2118)
[error] at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$2(Typer.scala:2444)
[error] at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2448)
[error] at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2516)
[error] at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:122)
[error] at dotty.tools.dotc.typer.Typer.op$proxy16$1(Typer.scala:2586)
[error] at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2587)
[error] at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2590)
[error] at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2612)
[error] at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2661)
[error] at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:979)
[error] at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2242)
[error] at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2488)
[error] at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2517)
[error] at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:122)
[error] at dotty.tools.dotc.typer.Typer.op$proxy16$1(Typer.scala:2586)
[error] at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2587)
[error] at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2590)
[error] at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2705)
[error] at dotty.tools.dotc.transform.Erasure.run(Erasure.scala:123)
[error] at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:296)
[error] at scala.collection.immutable.List.map(List.scala:246)
[error] at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:297)
[error] at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:180)
[error] at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
[error] at dotty.tools.dotc.Run.runPhases$5(Run.scala:190)
[error] at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:198)
[error] at dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
[error] at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:64)
[error] at dotty.tools.dotc.Run.compileUnits(Run.scala:205)
[error] at dotty.tools.dotc.Run.compileUnits(Run.scala:147)
[error] at scala.quoted.staging.QuoteCompiler$ExprRun.compileExpr(QuoteCompiler.scala:107)
[error] at scala.quoted.staging.QuoteDriver.run(QuoteDriver.scala:39)
[error] at scala.quoted.staging.Toolbox$$anon$1.run(Toolbox.scala:36)
[error] at scala.quoted.staging.package$.run(staging.scala:19)
[error] at Test$.<clinit>(Main.scala:19)
[error] at Test.main(Main.scala)
[error] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)
[error] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[error] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[error] at java.base/java.lang.reflect.Method.invoke(Method.java:566)
The text was updated successfully, but these errors were encountered:
When using the staging API one can extract a mutable variable into a HOAS function and then substitute another bound mutable variable. This generates an intermediate immutable binding and assigns to that one, which is wrong.
Probably related to #9692
Minimized code
Output (click arrow to expand)
The text was updated successfully, but these errors were encountered: