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

Pickler crashes with unresolved local type in closure #15595

Closed
WojciechMazur opened this issue Jul 5, 2022 · 6 comments · Fixed by #15746
Closed

Pickler crashes with unresolved local type in closure #15595

WojciechMazur opened this issue Jul 5, 2022 · 6 comments · Fixed by #15746
Labels
area:pickling itype:bug itype:crash regression This worked in a previous version but doesn't anymore
Milestone

Comments

@WojciechMazur
Copy link
Contributor

WojciechMazur commented Jul 5, 2022

Compiler version

Fails in 3.1.1
Works in 3.1.2
Works In 3.1.3-RC4
Fails in 3.1.3-RC5
Fails in 3.2.0-RC1

Minimized code

Based on https://scala3.westeurope.cloudapp.azure.com/blue/organizations/jenkins/buildCommunityProject/detail/buildCommunityProject/561/pipeline

trait MatchResult[+T]

@main def Test() = {
  def convert[T <: Seq[_], U <: MatchResult[_]](fn: T => U)(implicit x: Seq[_] = Seq.empty): U = ???
  def resultOf[T](v: T): MatchResult[T] = ???

  convert { _ =>
    type R = String
    resultOf[R](???)
    // this would not lead to crash: 
    // val x = resultOf[R](???)
    // x
  }
}

Output (click arrow to expand)

java.lang.AssertionError: assertion failed: unresolved symbols: type R (line 11) #6547 when pickling /home/wmazur/projects/virtuslab/community-build3/test.scala
        at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
        at dotty.tools.dotc.core.tasty.TreePickler.pickle(TreePickler.scala:783)
        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:110)
        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:110)
        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:115)
        at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:234)
        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:245)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:253)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:262)
        at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:68)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:262)
        at dotty.tools.dotc.Run.compileSources(Run.scala:186)
        at dotty.tools.dotc.Run.compile(Run.scala:170)
        at dotty.tools.dotc.Driver.doCompile(Driver.scala:35)
        at dotty.tools.xsbt.CompilerBridgeDriver.run(CompilerBridgeDriver.java:88)
        at dotty.tools.xsbt.CompilerBridge.run(CompilerBridge.java:22)
        at sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:91)
        at sbt.internal.inc.bloop.internal.BloopHighLevelCompiler.compileSources$1(BloopHighLevelCompiler.scala:133)
        at sbt.internal.inc.bloop.internal.BloopHighLevelCompiler.$anonfun$compile$7(BloopHighLevelCompiler.scala:151)
        at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
        at sbt.internal.inc.bloop.internal.BloopHighLevelCompiler.$anonfun$compile$1(BloopHighLevelCompiler.scala:71)
        at bloop.tracing.BraveTracer.traceInternal(BraveTracer.scala:65)
        at bloop.tracing.BraveTracer.trace(BraveTracer.scala:39)
        at sbt.internal.inc.bloop.internal.BloopHighLevelCompiler.timed$1(BloopHighLevelCompiler.scala:70)
        at sbt.internal.inc.bloop.internal.BloopHighLevelCompiler.$anonfun$compile$6(BloopHighLevelCompiler.scala:151)
        at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
        at monix.eval.internal.TaskRunLoop$.monix$eval$internal$TaskRunLoop$$loop$1(TaskRunLoop.scala:187)
        at monix.eval.internal.TaskRunLoop$RestartCallback$1.onSuccess(TaskRunLoop.scala:119)
        at monix.eval.Task$.$anonfun$forkedUnit$2(Task.scala:1463)
        at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1395)
        at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
        at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
        at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
        at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
        at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)
Error: Unexpected error when compiling project_6d5831c594_6d5831c594-15348604ae: 'assertion failed: unresolved symbols: type R (line 11) #6547 when pickling /home/wmazur/projects/virtuslab/community-build3/test.scala'

Code after typer phase (click arrow to expand)

Differences in enclosing packages and imports originate from minimalizing issue in the original repo
package <empty> {
  import util.WithTemporaryCollection.*
  import org.specs2.matcher.MatchResult
  final class ChangeStreamSpec() extends Object() {
    def resultOf[T >: Nothing <: Any](v: T): org.specs2.matcher.MatchResult[T]
       = 
    ???
    trait Coll() extends Object {}
    def convert[T >: Nothing <: Seq[? >: Nothing <: Any], 
      U >: Nothing <: org.specs2.matcher.MatchResult[? >: Nothing <: Any]
    ](fn: T => U)(implicit x: Seq[ChangeStreamSpec.this.Coll]): U = ???
    def convert$default$2[T >: Nothing <: Seq[? >: Nothing <: Any], 
      U >: Nothing <: org.specs2.matcher.MatchResult[? >: Nothing <: Any]
    ](fn: T => U): Seq[ChangeStreamSpec.this.Coll] @uncheckedVariance = 
      Seq.empty[ChangeStreamSpec.this.Coll]
    {
      val fn$1: Seq[?] => org.specs2.matcher.MatchResult[R] = 
        {
          {
            def $anonfun(_$1: Seq[?]): org.specs2.matcher.MatchResult[R] = 
              {
                type R = String
                this.resultOf[R](???):org.specs2.matcher.MatchResult[String]
              }
            closure($anonfun)
          }
        }
      this.convert[Seq[?], org.specs2.matcher.MatchResult[R]](fn$1)(
        this.convert$default$2[Seq[?], org.specs2.matcher.MatchResult[R]](fn$1)
      )
    }
  }
}
@WojciechMazur WojciechMazur added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label labels Jul 5, 2022
@griggt
Copy link
Contributor

griggt commented Jul 5, 2022

Seems like this started working after #14026.

The breakage between 3.1.3-RC4 and RC5 was caused by #15388

The corresponding PR #15343 is what broke it on main

@rochala rochala added area:pickling regression This worked in a previous version but doesn't anymore and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jul 6, 2022
@odersky
Copy link
Contributor

odersky commented Jul 6, 2022

Probably related to #15584

@olhotak
Copy link
Contributor

olhotak commented Jul 7, 2022

Is that a typo? #15584 is not merged yet.

@odersky
Copy link
Contributor

odersky commented Jul 7, 2022

Ah, yes, it's #15564.

@dwijnand
Copy link
Member

Duplicate of #15564

@dwijnand dwijnand marked this as a duplicate of #15564 Jul 11, 2022
@dwijnand
Copy link
Member

Hmm. Same result, but perhaps they're different causes, different issue numbers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:pickling itype:bug itype:crash regression This worked in a previous version but doesn't anymore
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants