Skip to content
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

Macro pickling causes unresolved symbols due to type parameter dependency on parameter #15475

Closed
andrzejressel opened this issue Jun 19, 2022 · 3 comments · Fixed by #16862
Closed
Labels

Comments

@andrzejressel
Copy link
Contributor

andrzejressel commented Jun 19, 2022

Compiler version

3.1.3-RC5

Minimized code

// A.scala
package x

def hello = {
  xtransform {
    val a: Seq[Generic[?]] = null
    a
      .foreach { to =>
        to.mthd()
      }
  }
}

trait Generic[+T] {
  def mthd(): Generic[T] = this
}
// X.scala
package x

import scala.quoted.*


transparent inline def xtransform[T](inline expr:T) = ${
   X.transform('expr)
}

object X {

   def transform[T:Type](x: Expr[T])(using Quotes):Expr[T] = {
      import quotes.reflect.*
      x
   }

}

Output (click arrow to expand)

Exception in thread "main" java.lang.AssertionError: assertion failed: unresolved symbols: parameter to (line 6) #22672 when pickling A.scala while compiling A.scala, X.scala
java.lang.AssertionError: assertion failed: unresolved symbols: parameter to (line 6) #22672 when pickling A.scala
        at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
        at dotty.tools.dotc.core.tasty.TreePickler.pickle(TreePickler.scala:770)
        at dotty.tools.dotc.transform.Pickler.run$$anonfun$1$$anonfun$1(Pickler.scala:72)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.immutable.List.foreach(List.scala:333)
        at dotty.tools.dotc.transform.Pickler.run$$anonfun$1(Pickler.scala:109)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.immutable.List.foreach(List.scala:333)
        at dotty.tools.dotc.transform.Pickler.run(Pickler.scala:109)
        at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:311)
        at scala.collection.immutable.List.map(List.scala:246)
        at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:312)
        at dotty.tools.dotc.transform.Pickler.runOn(Pickler.scala:114)
        at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:225)
        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:1328)
        at dotty.tools.dotc.Run.runPhases$1(Run.scala:236)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:244)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:253)
        at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:68)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:253)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:192)
        at dotty.tools.dotc.Driver.finish(Driver.scala:56)
        at dotty.tools.dotc.Driver.doCompile(Driver.scala:36)
        at dotty.tools.dotc.Driver.process(Driver.scala:195)
        at dotty.tools.dotc.Driver.process(Driver.scala:163)
        at dotty.tools.dotc.Driver.process(Driver.scala:175)
        at dotty.tools.dotc.Driver.main(Driver.scala:205)
        at dotty.tools.dotc.Main.main(Main.scala)

Discussion in dotty-cps-async about this bug: dotty-cps-async/dotty-cps-async#58 (comment)

Regression starts here: 2317859

Example project: https://github.com/andrzejressel/scala-3-unresolved-symbols

@andrzejressel andrzejressel added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label labels Jun 19, 2022
@nicolasstucki nicolasstucki added area:metaprogramming:quotes Issues related to quotes and splices stat:needs minimization Needs a self contained minimization and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jun 19, 2022
@odersky
Copy link
Contributor

odersky commented Jun 19, 2022

I think further minimizing would be nice, but in principle the existing test case should be workable.

@odersky odersky removed the stat:needs minimization Needs a self contained minimization label Jun 19, 2022
odersky added a commit to dotty-staging/dotty that referenced this issue Jun 19, 2022
This test case first broke when level checking was disabled.

I verified that it compiles OK when Config.checkLevels is set to true.
odersky added a commit that referenced this issue Jun 20, 2022
@KacperFKorban
Copy link
Member

I managed to minimize it into a single file:

//> using scala "3.1.3-RC5"

def test =
  transform {
    val a: Seq[Generic[?]] = ???
    a.foreach { to =>
      to.mthd()
    }
  }

transparent inline def transform[T](expr: T): T = ??? // if we add inline to param, it doesn't crash

trait Generic[+T] { // both covariance and contravariance cause a crash (invariance doesn't)
  def mthd(): Generic[T] = ??? // has to have a parameter list to crash
}

@prolativ
Copy link
Contributor

Additionally the crash in the snippet above doesn't occur if one of the following is true:

  • we get rid o ? in val a: Seq[Generic[?]] = ???, e.g. val a: Seq[Generic[Int]] = ???
  • we don't refer to T in the result type of mthd, e.g. def mthd(): Generic[Int] = ???

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 9, 2023
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 13, 2023
Kordyjan added a commit that referenced this issue Feb 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants