Closed
Description
Minimized code
import scala.quoted._
object Test {
def main(args: Array[String]): Unit = {
given staging.Compiler = staging.Compiler.make(getClass.getClassLoader)
staging.run(genCode)
}
}
inline def isTrue: Boolean = true
inline def oneOf: String = inline if isTrue then "foo" else "bar"
def genCode(using Quotes) = '{ oneOf }
This code should work. The issue is that currently, the InlineTyper
assumes that the Typer
will call InlineTyper
again for inline calls that were inlined. But this is not the case when calling the InlineTyper
in the Inlining
phase. InlineTyper
should problably take care of inlining any nested inline calls.
Output (click arrow to expand)
Exception in thread "main" java.lang.reflect.InvocationTargetException
| => sat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at dotty.tools.vulpix.ChildJVMMain.runMain(ChildJVMMain.java:40)
at dotty.tools.vulpix.ChildJVMMain.main(ChildJVMMain.java:47)
Caused by: class dotty.tools.dotc.reporting.Diagnostic$Error at tests/run-staging/inlineInInline.scala:[248..255..286]: Cannot reduce `inline if` because its condition is not a constant value: isTrue
at dotty.tools.dotc.report$.error(report.scala:71)
at dotty.tools.dotc.typer.ErrorReporting$.errorType(ErrorReporting.scala:34)
at dotty.tools.dotc.typer.ErrorReporting$.errorTree(ErrorReporting.scala:25)
at dotty.tools.dotc.typer.ErrorReporting$.errorTree(ErrorReporting.scala:28)
at dotty.tools.dotc.typer.Inliner$InlineTyper.typedIf(Inliner.scala:1264)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2561)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2614)
at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:118)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2679)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2683)
at dotty.tools.dotc.typer.ReTyper.typedTyped(ReTyper.scala:62)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2557)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2614)
at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:118)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2679)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2683)
at dotty.tools.dotc.typer.Inliner.inlined(Inliner.scala:784)
at dotty.tools.dotc.typer.Inliner$.inlineCall(Inliner.scala:126)
at dotty.tools.dotc.transform.Inlining$InliningTreeMap.transform(Inlining.scala:86)
at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1347)
at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:120)
at dotty.tools.dotc.transform.Inlining$InliningTreeMap.transform(Inlining.scala:95)
at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:99)
at dotty.tools.dotc.transform.Inlining$InliningTreeMap.transform(Inlining.scala:79)
at dotty.tools.dotc.ast.TreeMapWithImplicits.traverse$1(TreeMapWithImplicits.scala:53)
at dotty.tools.dotc.ast.TreeMapWithImplicits.transformStats(TreeMapWithImplicits.scala:60)
at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:111)
at dotty.tools.dotc.transform.Inlining$InliningTreeMap.transform(Inlining.scala:79)
at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1390)
at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:104)
at dotty.tools.dotc.transform.Inlining$InliningTreeMap.transform(Inlining.scala:79)
at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform$$anonfun$1(Trees.scala:1414)
at scala.collection.immutable.List.mapConserve(List.scala:472)
at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1414)
at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transformStats(Trees.scala:1412)
at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1399)
at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:104)
at dotty.tools.dotc.transform.Inlining$InliningTreeMap.transform(Inlining.scala:95)
at dotty.tools.dotc.transform.Inlining$$anon$2.transform(Inlining.scala:71)
at dotty.tools.dotc.transform.MacroTransform.run(MacroTransform.scala:21)
at dotty.tools.dotc.transform.Inlining.run(Inlining.scala:43)
at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:303)
at scala.collection.immutable.List.map(List.scala:246)
at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:304)
at dotty.tools.dotc.transform.Inlining.runOn(Inlining.scala:47)
at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:201)
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:1323)
at dotty.tools.dotc.Run.runPhases$5(Run.scala:211)
at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:219)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:67)
at dotty.tools.dotc.Run.compileUnits(Run.scala:226)
at dotty.tools.dotc.Run.compileUnits(Run.scala:168)
at scala.quoted.staging.QuoteCompiler$ExprRun.compileExpr(QuoteCompiler.scala:111)
at scala.quoted.staging.QuoteDriver.run(QuoteDriver.scala:39)
at scala.quoted.staging.Compiler$$anon$1.run(Compiler.scala:38)
at scala.quoted.staging.package$.run(staging.scala:19)
at Test$.main(inlineInInline.scala:6)
at Test.main(inlineInInline.scala)
... 6 more```
</details>