Skip to content

Crash on casting with isInstanceOf from a quote #6997

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
anatoliykmetyuk opened this issue Aug 6, 2019 · 2 comments
Closed

Crash on casting with isInstanceOf from a quote #6997

anatoliykmetyuk opened this issue Aug 6, 2019 · 2 comments

Comments

@anatoliykmetyuk
Copy link
Contributor

Macro:

package playground

import scala.quoted._, scala.quoted.matching._
import delegate scala.quoted._
import scala.tasty._

delegate for Toolbox = Toolbox.make(getClass.getClassLoader)

inline def mcr(x: => Any): Any = ${mcrImpl('x)}

def mcrImpl(body: Expr[Any]) given (ctx: QuoteContext): Expr[Any] = {
  import ctx.tasty._
  val '{$x: $t} = body
  '{
    val tmp: $t = $x//.asInstanceOf[$t]
    println(tmp)
    tmp
  }
}

Main:

package playground

val a = true
@main def main = println(mcr { a })

Error:

[error] -- [E007] Type Mismatch Error: /Users/anatolii/Projects/dotty/playground/macros/src/main/scala/playground/macros.scala:15:19
[error] 15 |    val tmp: $t = $x//.asInstanceOf[$t]
[error]    |                   ^
[error]    |                   Found:    scala.quoted.Expr[Any](x)
[error]    |                   Required: quoted.Expr[t.T]
[error] one error found

If you uncomment the cast as follows:

val tmp: $t = $x.asInstanceOf[$t]

The compiler crashes:

Crash
java.lang.AssertionError: assertion failed: unresolved symbols: value t(line 12) when pickling /Users/anatolii/Projects/dotty/playground/macros/src/main/scala/playground/macros.scala while compiling /Users/anatolii/Projects/dotty/playground/macros/src/main/scala/playground/macros.scala
[info] exception occurred while compiling /Users/anatolii/Projects/dotty/playground/macros/src/main/scala/playground/macros.scala
[error] ## Exception when compiling 1 sources to /Users/anatolii/Projects/dotty/playground/macros/target/scala-0.18/classes
[error] assertion failed: unresolved symbols: value t(line 12) when pickling /Users/anatolii/Projects/dotty/playground/macros/src/main/scala/playground/macros.scala
[error] dotty.DottyPredef$.assertFail(DottyPredef.scala:16)
[error] dotty.tools.dotc.core.tasty.TreePickler.pickle(TreePickler.scala:695)
[error] dotty.tools.dotc.core.quoted.PickledQuotes$.pickle(PickledQuotes.scala:89)
[error] dotty.tools.dotc.core.quoted.PickledQuotes$.pickleQuote(PickledQuotes.scala:32)
[error] dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.pickleAsTasty$1(ReifyQuotes.scala:237)
[error] dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.pickledQuote(ReifyQuotes.scala:249)
[error] dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transformQuotation(ReifyQuotes.scala:195)
[error] dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:94)
[error] dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:409)
[error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1255)
[error] dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:118)
[error] dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:77)
[error] dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:127)
[error] dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:409)
[error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1261)
[error] dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:118)
[error] dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:77)
[error] dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:127)
[error] dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:409)
[error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1269)
[error] dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:118)
[error] dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:77)
[error] dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:127)
[error] dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:409)
[error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1275)
[error] dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:90)
[error] dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:77)
[error] dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:106)
[error] dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:409)
[error] dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:98)
[error] dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:77)
[error] dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:127)
[error] dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:409)
[error] dotty.tools.dotc.ast.TreeMapWithImplicits.traverse$1(TreeMapWithImplicits.scala:52)
[error] dotty.tools.dotc.ast.TreeMapWithImplicits.transformStats(TreeMapWithImplicits.scala:59)
[error] dotty.tools.dotc.ast.TreeMapWithImplicits.recur$1(TreeMapWithImplicits.scala:33)
[error] dotty.tools.dotc.ast.TreeMapWithImplicits.recur$1(TreeMapWithImplicits.scala:39)
[error] dotty.tools.dotc.ast.TreeMapWithImplicits.recur$1(TreeMapWithImplicits.scala:39)
[error] dotty.tools.dotc.ast.TreeMapWithImplicits.traverse$1(TreeMapWithImplicits.scala:53)
[error] dotty.tools.dotc.ast.TreeMapWithImplicits.transformStats(TreeMapWithImplicits.scala:59)
[error] dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:109)
[error] dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:77)
[error] dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:127)
[error] dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:409)
[error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1331)
[error] dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:102)
[error] dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:77)
[error] dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:127)
[error] dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:409)
[error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform$$anonfun$2(Trees.scala:1351)
[error] scala.collection.immutable.List.mapConserve(List.scala:179)
[error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1351)
[error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transformStats(Trees.scala:1349)
[error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1337)
[error] dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:102)
[error] dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:77)
[error] dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:127)
[error] dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:409)
[error] dotty.tools.dotc.transform.ReifyQuotes$$anon$1.transform(ReifyQuotes.scala:94)
[error] dotty.tools.dotc.transform.MacroTransform.run(MacroTransform.scala:21)
[error] dotty.tools.dotc.transform.ReifyQuotes.run(ReifyQuotes.scala:90)
[error] dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:316)
[error] scala.collection.immutable.List.map(List.scala:286)
[error] dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:318)
[error] dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:158)
[error] dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] scala.collection.IndexedSeqOptimized.foreach(IndexedSeqOptimized.scala:36)
[error] scala.collection.IndexedSeqOptimized.foreach$(IndexedSeqOptimized.scala:33)
[error] scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:198)
[error] dotty.tools.dotc.Run.runPhases$5(Run.scala:170)
[error] dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:178)
[error] dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
[error] dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:65)
[error] dotty.tools.dotc.Run.compileUnits(Run.scala:185)
[error] dotty.tools.dotc.Run.compileSources(Run.scala:120)
[error] dotty.tools.dotc.Run.compile(Run.scala:104)
[error] dotty.tools.dotc.Driver.doCompile(Driver.scala:34)
[error] dotty.tools.dotc.Driver.process(Driver.scala:172)
[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.NativeMethodAccessorImpl.invoke0(Native Method)
[error] sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[error] sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[error] java.lang.reflect.Method.invoke(Method.java:498)
[error] sbt.internal.inc.AnalyzingCompiler.call(AnalyzingCompiler.scala:237)
[error] sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:111)
[error] sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:90)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$3(MixedAnalyzingCompiler.scala:82)
[error] scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
[error] sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:133)
[error] sbt.internal.inc.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:73)
[error] sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:116)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:307)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:307)
[error] sbt.internal.inc.Incremental$.doCompile(Incremental.scala:106)
[error] sbt.internal.inc.Incremental$.$anonfun$compile$4(Incremental.scala:87)
[error] sbt.internal.inc.IncrementalCommon.recompileClasses(IncrementalCommon.scala:116)
[error] sbt.internal.inc.IncrementalCommon.cycle(IncrementalCommon.scala:63)
[error] sbt.internal.inc.Incremental$.$anonfun$compile$3(Incremental.scala:89)
[error] sbt.internal.inc.Incremental$.manageClassfiles(Incremental.scala:134)
[error] sbt.internal.inc.Incremental$.compile(Incremental.scala:80)
[error] sbt.internal.inc.IncrementalCompile$.apply(Compile.scala:67)
[error] sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:311)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:269)
[error] sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:159)
[error] sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:238)
[error] sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:69)
[error] sbt.Defaults$.compileIncrementalTaskImpl(Defaults.scala:1549)
[error] sbt.Defaults$.$anonfun$compileIncrementalTask$1(Defaults.scala:1523)
[error] scala.Function1.$anonfun$compose$1(Function1.scala:44)
[error] sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:40)
[error] sbt.std.Transform$$anon$4.work(System.scala:67)
[error] sbt.Execute.$anonfun$submit$2(Execute.scala:269)
[error] sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:16)
[error] sbt.Execute.work(Execute.scala:278)
[error] sbt.Execute.$anonfun$submit$1(Execute.scala:269)
[error] sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:178)
[error] sbt.CompletionService$$anon$2.call(CompletionService.scala:37)
[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:1142)
[error] java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
[error] java.lang.Thread.run(Thread.java:745)
[error]
[error] java.lang.AssertionError: assertion failed: unresolved symbols: value t(line 12) when pickling /Users/anatolii/Projects/dotty/playground/macros/src/main/scala/playground/macros.scala
[error] 	at dotty.DottyPredef$.assertFail(DottyPredef.scala:16)
[error] 	at dotty.tools.dotc.core.tasty.TreePickler.pickle(TreePickler.scala:695)
[error] 	at dotty.tools.dotc.core.quoted.PickledQuotes$.pickle(PickledQuotes.scala:89)
[error] 	at dotty.tools.dotc.core.quoted.PickledQuotes$.pickleQuote(PickledQuotes.scala:32)
[error] 	at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.pickleAsTasty$1(ReifyQuotes.scala:237)
[error] 	at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.pickledQuote(ReifyQuotes.scala:249)
[error] 	at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transformQuotation(ReifyQuotes.scala:195)
[error] 	at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:94)
[error] 	at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:409)
[error] 	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1255)
[error] 	at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:118)
[error] 	at dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:77)
[error] 	at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:127)
[error] 	at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:409)
[error] 	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1261)
[error] 	at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:118)
[error] 	at dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:77)
[error] 	at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:127)
[error] 	at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:409)
[error] 	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1269)
[error] 	at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:118)
[error] 	at dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:77)
[error] 	at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:127)
[error] 	at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:409)
[error] 	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1275)
[error] 	at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:90)
[error] 	at dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:77)
[error] 	at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:106)
[error] 	at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:409)
[error] 	at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:98)
[error] 	at dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:77)
[error] 	at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:127)
[error] 	at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:409)
[error] 	at dotty.tools.dotc.ast.TreeMapWithImplicits.traverse$1(TreeMapWithImplicits.scala:52)
[error] 	at dotty.tools.dotc.ast.TreeMapWithImplicits.transformStats(TreeMapWithImplicits.scala:59)
[error] 	at dotty.tools.dotc.ast.TreeMapWithImplicits.recur$1(TreeMapWithImplicits.scala:33)
[error] 	at dotty.tools.dotc.ast.TreeMapWithImplicits.recur$1(TreeMapWithImplicits.scala:39)
[error] 	at dotty.tools.dotc.ast.TreeMapWithImplicits.recur$1(TreeMapWithImplicits.scala:39)
[error] 	at dotty.tools.dotc.ast.TreeMapWithImplicits.traverse$1(TreeMapWithImplicits.scala:53)
[error] 	at dotty.tools.dotc.ast.TreeMapWithImplicits.transformStats(TreeMapWithImplicits.scala:59)
[error] 	at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:109)
[error] 	at dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:77)
[error] 	at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:127)
[error] 	at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:409)
[error] 	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1331)
[error] 	at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:102)
[error] 	at dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:77)
[error] 	at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:127)
[error] 	at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:409)
[error] 	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform$$anonfun$2(Trees.scala:1351)
[error] 	at scala.collection.immutable.List.mapConserve(List.scala:179)
[error] 	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1351)
[error] 	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transformStats(Trees.scala:1349)
[error] 	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1337)
[error] 	at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:102)
[error] 	at dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:77)
[error] 	at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:127)
[error] 	at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:409)
[error] 	at dotty.tools.dotc.transform.ReifyQuotes$$anon$1.transform(ReifyQuotes.scala:94)
[error] 	at dotty.tools.dotc.transform.MacroTransform.run(MacroTransform.scala:21)
[error] 	at dotty.tools.dotc.transform.ReifyQuotes.run(ReifyQuotes.scala:90)
[error] 	at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:316)
[error] 	at scala.collection.immutable.List.map(List.scala:286)
[error] 	at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:318)
[error] 	at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:158)
[error] 	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] 	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] 	at scala.collection.IndexedSeqOptimized.foreach(IndexedSeqOptimized.scala:36)
[error] 	at scala.collection.IndexedSeqOptimized.foreach$(IndexedSeqOptimized.scala:33)
[error] 	at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:198)
[error] 	at dotty.tools.dotc.Run.runPhases$5(Run.scala:170)
[error] 	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:178)
[error] 	at dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
[error] 	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:65)
[error] 	at dotty.tools.dotc.Run.compileUnits(Run.scala:185)
[error] 	at dotty.tools.dotc.Run.compileSources(Run.scala:120)
[error] 	at dotty.tools.dotc.Run.compile(Run.scala:104)
[error] 	at dotty.tools.dotc.Driver.doCompile(Driver.scala:34)
[error] 	at dotty.tools.dotc.Driver.process(Driver.scala:172)
[error] 	at dotty.tools.dotc.Main.process(Main.scala)
[error] 	at xsbt.CachedCompilerImpl.run(CachedCompilerImpl.java:69)
[error] 	at xsbt.CompilerInterface.run(CompilerInterface.java:41)
[error] 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[error] 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[error] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[error] 	at java.lang.reflect.Method.invoke(Method.java:498)
[error] 	at sbt.internal.inc.AnalyzingCompiler.call(AnalyzingCompiler.scala:237)
[error] 	at sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:111)
[error] 	at sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:90)
[error] 	at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$3(MixedAnalyzingCompiler.scala:82)
[error] 	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
[error] 	at sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:133)
[error] 	at sbt.internal.inc.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:73)
[error] 	at sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:116)
[error] 	at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:307)
[error] 	at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:307)
[error] 	at sbt.internal.inc.Incremental$.doCompile(Incremental.scala:106)
[error] 	at sbt.internal.inc.Incremental$.$anonfun$compile$4(Incremental.scala:87)
[error] 	at sbt.internal.inc.IncrementalCommon.recompileClasses(IncrementalCommon.scala:116)
[error] 	at sbt.internal.inc.IncrementalCommon.cycle(IncrementalCommon.scala:63)
[error] 	at sbt.internal.inc.Incremental$.$anonfun$compile$3(Incremental.scala:89)
[error] 	at sbt.internal.inc.Incremental$.manageClassfiles(Incremental.scala:134)
[error] 	at sbt.internal.inc.Incremental$.compile(Incremental.scala:80)
[error] 	at sbt.internal.inc.IncrementalCompile$.apply(Compile.scala:67)
[error] 	at sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:311)
[error] 	at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:269)
[error] 	at sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:159)
[error] 	at sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:238)
[error] 	at sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:69)
[error] 	at sbt.Defaults$.compileIncrementalTaskImpl(Defaults.scala:1549)
[error] 	at sbt.Defaults$.$anonfun$compileIncrementalTask$1(Defaults.scala:1523)
[error] 	at scala.Function1.$anonfun$compose$1(Function1.scala:44)
[error] 	at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:40)
[error] 	at sbt.std.Transform$$anon$4.work(System.scala:67)
[error] 	at sbt.Execute.$anonfun$submit$2(Execute.scala:269)
[error] 	at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:16)
[error] 	at sbt.Execute.work(Execute.scala:278)
[error] 	at sbt.Execute.$anonfun$submit$1(Execute.scala:269)
[error] 	at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:178)
[error] 	at sbt.CompletionService$$anon$2.call(CompletionService.scala:37)
[error] 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error] 	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[error] 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error] 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
[error] 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
[error] 	at java.lang.Thread.run(Thread.java:745)
@nicolasstucki
Copy link
Contributor

nicolasstucki commented Aug 7, 2019

It can be minimized to

import scala.quoted._
class Foo {
  def mcrImpl(body: Expr[Any]) given (t: Type[_ <: Any]) given (ctx: QuoteContext): Expr[Any] = '{
      val tmp = $body.asInstanceOf[$t]
      tmp
  }
}

The issue is that ReifyQuotes is not able to handle a splice of Type[_]. An error should be reported.

Crash
Exception in thread "main" java.lang.AssertionError: assertion failed: unresolved symbols: value t(line 3) when pickling Foo.scala
	at dotty.DottyPredef$.assertFail(DottyPredef.scala:16)
	at dotty.tools.dotc.core.tasty.TreePickler.pickle(TreePickler.scala:695)
	at dotty.tools.dotc.core.quoted.PickledQuotes$.pickle(PickledQuotes.scala:89)
	at dotty.tools.dotc.core.quoted.PickledQuotes$.pickleQuote(PickledQuotes.scala:32)
	at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.pickleAsTasty$1(ReifyQuotes.scala:237)
	at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.pickledQuote(ReifyQuotes.scala:249)
	at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transformQuotation(ReifyQuotes.scala:195)
	at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:94)
	at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:409)
	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1255)
	at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:118)
	at dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:77)
	at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:127)
	at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:409)
	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1261)
	at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:118)
	at dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:77)
	at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:127)
	at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:409)
	at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:98)
	at dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:77)
	at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:127)
	at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:409)
	at dotty.tools.dotc.ast.TreeMapWithImplicits.traverse$1(TreeMapWithImplicits.scala:52)
	at dotty.tools.dotc.ast.TreeMapWithImplicits.transformStats(TreeMapWithImplicits.scala:59)
	at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:109)
	at dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:77)
	at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:127)
	at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:409)
	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1331)
	at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:102)
	at dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:77)
	at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:127)
	at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:409)
	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform$$anonfun$2(Trees.scala:1351)
	at scala.collection.immutable.List.mapConserve(List.scala:179)
	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1351)
	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transformStats(Trees.scala:1349)
	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1337)
	at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:102)
	at dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:77)
	at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:127)
	at dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:409)
	at dotty.tools.dotc.transform.ReifyQuotes$$anon$1.transform(ReifyQuotes.scala:94)
	at dotty.tools.dotc.transform.MacroTransform.run(MacroTransform.scala:21)
	at dotty.tools.dotc.transform.ReifyQuotes.run(ReifyQuotes.scala:90)
	at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:316)
	at scala.collection.immutable.List.map(List.scala:286)
	at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:318)
	at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:158)
	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.IndexedSeqOptimized.foreach(IndexedSeqOptimized.scala:36)
	at scala.collection.IndexedSeqOptimized.foreach$(IndexedSeqOptimized.scala:33)
	at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:198)
	at dotty.tools.dotc.Run.runPhases$5(Run.scala:170)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:178)
	at dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:65)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:185)
	at dotty.tools.dotc.Run.compileSources(Run.scala:120)
	at dotty.tools.dotc.Run.compile(Run.scala:104)
	at dotty.tools.dotc.Driver.doCompile(Driver.scala:35)
	at dotty.tools.dotc.Driver.process(Driver.scala:180)
	at dotty.tools.dotc.Driver.process(Driver.scala:149)
	at dotty.tools.dotc.Driver.process(Driver.scala:161)
	at dotty.tools.dotc.Driver.main(Driver.scala:188)
	at dotty.tools.dotc.Main.main(Main.scala)

@anatoliykmetyuk anatoliykmetyuk changed the title Quote matching on a typed value does not capture its type properly Crash on casting with isInstanceOf from a quote Aug 7, 2019
@nicolasstucki
Copy link
Contributor

Actually adding the following ascription fixes it

import scala.quoted._
class Foo {
  def mcrImpl(body: Expr[Any]) given (t: Type[_ <: Any]) given (ctx: QuoteContext): Expr[Any] = '{
      val tmp = $body.asInstanceOf[$t]
      tmp: $t
  }
}

a similar type ascription is added (tmp: t.T) while typing the other version.

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Aug 7, 2019
odersky added a commit that referenced this issue Aug 23, 2019
Fix #6997: Adapt quote type direct aliase to type splice
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants