Description
Minimized code
I found the following position error deep inside the Quill codebase when using a combination of features. In order to reproduce it, you need to create the three files below exactly as I have described, otherwise, the error will not be reproduced. Despite some efforts, I have not been able to compress/squash this example to anything any simpler.
I have also created a standalone repo for this code sample here:
https://github.com/deusaquilus/pos_bug_reproduction/
First, make a file for a macro that returns a class that contains something, and then a list of somethings. (This is distilled from Quill's 'Quotation' macro).
// MyQuoteMacro.scala
case class MyQuoted(val ast: String, runtimeQuotes: List[String])
object MyQuoteMacro {
inline def myquote: MyQuoted = ${ MyQuoteMacro.apply }
def apply(using Quotes): Expr[MyQuoted] = {
import quotes.reflect._
'{ MyQuoted("p", ${Expr.ofList(List( '{ "foo" } ))}) }
}
}
// If you include PullAst.scala here, the error will not happen!
Then make a file that has a macro which pulls out the first member.
// PullAst.scala
object PullAst {
def applyImpl(quoted: Expr[MyQuoted])(using qctx: Quotes): Expr[String] =
'{ $quoted.ast.toString }
inline def apply(inline quoted: MyQuoted): String =
${ applyImpl('quoted) }
}
Then make a file to test these things:
// Test.scala
object Test {
inline def q2 = MyQuoteMacro.myquote
def main(args: Array[String]): Unit = {
println( ContextRet.runAndTest( q2 ) )
}
}
Output
The following error will occur.
[error] ## Exception when compiling 1 sources to /Users/aleiof/git/pos_bug_reproduction/target/scala-3.0.0-M2/test-classes
[error] java.lang.AssertionError: assertion failed: position not set for {
[error] List.apply[String](["foo" : String]:String*)
[error] "p"
[error] } # -1 of class dotty.tools.dotc.ast.Trees$Block in src/main/scala/io/getquill/ContextRet.scala
[error] scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
[error] dotty.tools.dotc.typer.Typer$.assertPositioned(Typer.scala:64)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2596)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2605)
[error] dotty.tools.dotc.typer.Inliner$InlineTyper.typedSelect(Inliner.scala:1232)
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2441)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2531)
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:125)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2601)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2605)
[error] dotty.tools.dotc.typer.Inliner$InlineTyper.typedSelect(Inliner.scala:1228)
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2441)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2531)
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:125)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2601)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2605)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2720)
[error] dotty.tools.dotc.typer.ReTyper.typedFunPart(ReTyper.scala:75)
[error] dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:873)
[error] dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:1026)
[error] dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:236)
[error] dotty.tools.dotc.typer.Inliner$InlineTyper.typedApply(Inliner.scala:1266)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2471)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2532)
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:125)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2601)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2605)
[error] dotty.tools.dotc.typer.Typer.typedInlined(Typer.scala:1631)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2492)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2532)
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:125)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2601)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2605)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2720)
[error] dotty.tools.dotc.typer.Inliner$InlineTyper.typedApply(Inliner.scala:1271)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2471)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2532)
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:125)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2601)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2605)
[error] dotty.tools.dotc.typer.ReTyper.typedTyped(ReTyper.scala:62)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2476)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2532)
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:125)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2601)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2598)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2605)
[error] dotty.tools.dotc.typer.Inliner.inlined(Inliner.scala:772)
[error] dotty.tools.dotc.typer.Inliner$.inlineCall(Inliner.scala:126)
[error] dotty.tools.dotc.typer.Typer.adaptNoArgsOther$4(Typer.scala:3280)
[error] dotty.tools.dotc.typer.Typer.adaptNoArgs$1(Typer.scala:3381)
[error] dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:3610)
[error] dotty.tools.dotc.typer.Typer.adapt(Typer.scala:2932)
[error] dotty.tools.dotc.typer.ProtoTypes$FunProto.typedArg(ProtoTypes.scala:369)
[error] dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:825)
[error] dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:825)
[error] dotty.tools.dotc.typer.Applications$Application.addTyped$1(Applications.scala:545)
[error] dotty.tools.dotc.typer.Applications$Application.matchArgs(Applications.scala:616)
[error] dotty.tools.dotc.typer.Applications$Application.init(Applications.scala:366)
[error] dotty.tools.dotc.typer.Applications$TypedApply.<init>(Applications.scala:720)
[error] dotty.tools.dotc.typer.Applications$ApplyToUntyped.<init>(Applications.scala:824)
[error] dotty.tools.dotc.typer.Applications.ApplyTo(Applications.scala:1051)
[error] dotty.tools.dotc.typer.Applications.ApplyTo$(Applications.scala:236)
[error] dotty.tools.dotc.typer.Typer.ApplyTo(Typer.scala:92)
[error] dotty.tools.dotc.typer.Applications.simpleApply$1(Applications.scala:898)
[error] dotty.tools.dotc.typer.Applications.realApply$5$$anonfun$4(Applications.scala:977)
[error] dotty.tools.dotc.typer.Typer.tryEither(Typer.scala:2728)
[error] dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:988)
[error] dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:1026)
[error] dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:236)
[error] dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:92)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2471)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2532)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2601)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2605)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2720)
[error] dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:904)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2479)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2532)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2601)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2605)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2720)
[error] dotty.tools.dotc.typer.Typer.$anonfun$33(Typer.scala:1987)
[error] dotty.tools.dotc.typer.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:216)
[error] dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:1987)
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2448)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2531)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2601)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2605)
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2627)
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2676)
[error] dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2131)
[error] dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$2(Typer.scala:2459)
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2463)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2531)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2601)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2605)
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2627)
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2676)
[error] dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2256)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2503)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2532)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2601)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2605)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2720)
[error] dotty.tools.dotc.typer.FrontEnd.liftedTree1$1(FrontEnd.scala:79)
[error] dotty.tools.dotc.typer.FrontEnd.typeCheck$$anonfun$1(FrontEnd.scala:84)
[error] dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
[error] dotty.tools.dotc.typer.FrontEnd.monitor(FrontEnd.scala:43)
[error] dotty.tools.dotc.typer.FrontEnd.typeCheck(FrontEnd.scala:85)
[error] dotty.tools.dotc.typer.FrontEnd.runOn$$anonfun$3(FrontEnd.scala:120)
[error] dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] scala.collection.immutable.List.foreach(List.scala:333)
[error] dotty.tools.dotc.typer.FrontEnd.runOn(FrontEnd.scala:120)
[error] dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:185)
[error] dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
[error] dotty.tools.dotc.Run.runPhases$5(Run.scala:195)
[error] dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:203)
[error] dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
[error] dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:67)
[error] dotty.tools.dotc.Run.compileUnits(Run.scala:210)
[error] dotty.tools.dotc.Run.compileSources(Run.scala:147)
[error] dotty.tools.dotc.Run.compile(Run.scala:129)
[error] dotty.tools.dotc.Driver.doCompile(Driver.scala:38)
[error] dotty.tools.dotc.Driver.process(Driver.scala:193)
[error] dotty.tools.dotc.Main.process(Main.scala)
[error] xsbt.CachedCompilerImpl.run(CachedCompilerImpl.java:69)
[error] xsbt.CompilerInterface.run(CompilerInterface.java:41)
[error] sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
[error] sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[error] java.lang.reflect.Method.invoke(Method.java:498)
[error] sbt.internal.inc.AnalyzingCompiler.invoke(AnalyzingCompiler.scala:330)
[error] sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:113)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$7(MixedAnalyzingCompiler.scala:186)
[error] scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
[error] sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:241)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4(MixedAnalyzingCompiler.scala:176)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4$adapted(MixedAnalyzingCompiler.scala:157)
[error] sbt.internal.inc.JarUtils$.withPreviousJar(JarUtils.scala:232)
[error] sbt.internal.inc.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:157)
[error] sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:204)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:573)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:573)
[error] sbt.internal.inc.Incremental$.$anonfun$apply$5(Incremental.scala:174)
[error] sbt.internal.inc.Incremental$.$anonfun$apply$5$adapted(Incremental.scala:172)
[error] sbt.internal.inc.Incremental$$anon$2.run(Incremental.scala:459)
[error] sbt.internal.inc.IncrementalCommon$CycleState.next(IncrementalCommon.scala:116)
[error] sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:56)
[error] sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:52)
[error] sbt.internal.inc.IncrementalCommon.cycle(IncrementalCommon.scala:261)
[error] sbt.internal.inc.Incremental$.$anonfun$incrementalCompile$8(Incremental.scala:414)
[error] sbt.internal.inc.Incremental$.withClassfileManager(Incremental.scala:499)
[error] sbt.internal.inc.Incremental$.incrementalCompile(Incremental.scala:401)
[error] sbt.internal.inc.Incremental$.apply(Incremental.scala:166)
[error] sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:573)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:491)
[error] sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:332)
[error] sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:420
[error] sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:137)
[error] sbt.Defaults$.compileIncrementalTaskImpl(Defaults.scala:2176)
[error] sbt.Defaults$.$anonfun$compileIncrementalTask$2(Defaults.scala:2133)
[error] sbt.internal.io.Retry$.apply(Retry.scala:40)
[error] sbt.internal.io.Retry$.apply(Retry.scala:23)
[error] sbt.internal.server.BspCompileTask$.compute(BspCompileTask.scala:31)
[error] sbt.Defaults$.$anonfun$compileIncrementalTask$1(Defaults.scala:2129)
[error] scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error] sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:62)
[error] sbt.std.Transform$$anon$4.work(Transform.scala:68)
[error] sbt.Execute.$anonfun$submit$2(Execute.scala:282)
[error] sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:23)
[error] sbt.Execute.work(Execute.scala:291)
[error] sbt.Execute.$anonfun$submit$1(Execute.scala:282)
[error] sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
[error] sbt.CompletionService$$anon$2.call(CompletionService.scala:64)
[error] java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error] java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[error] java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error] java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[error] java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[error] java.lang.Thread.run(Thread.java:748)
[error]
[error] stack trace is suppressed; run last Test / compileIncremental for the full output
[error] (Test / compileIncremental) java.lang.AssertionError: assertion failed: position not set for {
[error] List.apply[String](["foo" : String]:String*)
[error] "p"
[error] } # -1 of class dotty.tools.dotc.ast.Trees$Block in src/main/scala/io/getquill/ContextRet.scala
[error] Total time: 0 s, completed Dec 13, 2020 8:29:57 AM
Expectation
Compilation should succeed.