Skip to content

Quote pattern match swallows summoned values #7715

@anatoliykmetyuk

Description

@anatoliykmetyuk

Macro.scala:

import scala.quoted.{ given, _ }

inline def mcr(e: => Any): Any = ${mcrImpl('e)}
def mcrImpl(e: Expr[Any])(given ctx: QuoteContext): Expr[Any] =
  println(s"In: ${e.show}")
  e match
    case '{$body} =>
      println(s"Out: ${body.show}")
      body

Test.scala:

given Int = ???
@main def Test = mcr(summon[Int])
Output
In: {
  val x: scala.Int = Test$package.given_Int

  (x: x)
}
Out: (x: x)
exception occurred while compiling /Users/kmetiuk/Projects/scala3/pg/cto-bug/Test.scala
java.lang.AssertionError: assertion failed: unresolved symbols: value x(line 1) when pickling /Users/kmetiuk/Projects/scala3/pg/cto-bug/Test.scala while compiling /Users/kmetiuk/Projects/scala3/pg/cto-bug/Test.scala
Exception in thread "main" java.lang.AssertionError: assertion failed: unresolved symbols: value x(line 1) when pickling /Users/kmetiuk/Projects/scala3/pg/cto-bug/Test.scala
	at dotty.DottyPredef$.assertFail(DottyPredef.scala:17)
	at dotty.tools.dotc.core.tasty.TreePickler.pickle(TreePickler.scala:703)
	at dotty.tools.dotc.transform.Pickler.run$$anonfun$10$$anonfun$8(Pickler.scala:63)
	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.immutable.List.foreach(List.scala:305)
	at dotty.tools.dotc.transform.Pickler.run$$anonfun$2(Pickler.scala:87)
	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.immutable.List.foreach(List.scala:305)
	at dotty.tools.dotc.transform.Pickler.run(Pickler.scala:87)
	at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:315)
	at scala.collection.immutable.List.map(List.scala:219)
	at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:316)
	at dotty.tools.dotc.transform.Pickler.runOn(Pickler.scala:91)
	at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:161)
	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at dotty.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:171)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:179)
	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:186)
	at dotty.tools.dotc.Run.compileSources(Run.scala:123)
	at dotty.tools.dotc.Run.compile(Run.scala:106)
	at dotty.tools.dotc.Driver.doCompile(Driver.scala:36)
	at dotty.tools.dotc.Driver.process(Driver.scala:189)
	at dotty.tools.dotc.Driver.process(Driver.scala:158)
	at dotty.tools.dotc.Driver.process(Driver.scala:170)
	at dotty.tools.dotc.Driver.main(Driver.scala:197)
	at dotty.tools.dotc.Main.main(Main.scala)

Workaround Test.scala:

implicit val stuff: Int = ???
@main def Test = mcr(summon[Int])

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions