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

scala.MatchError #20369

Open
Bersier opened this issue May 8, 2024 · 2 comments
Open

scala.MatchError #20369

Bersier opened this issue May 8, 2024 · 2 comments

Comments

@Bersier
Copy link
Contributor

Bersier commented May 8, 2024

Compiler version

Scala 3.4.1

Minimized code

val d1 = foo(Empty)
foo(d1)

type Identity[T] = T

def foo[L <: TList[Int]](t: L): Identity[Bar[L]] = ???

type Bar[L <: TList[Int]] <: TList[Int] = L match
  case Empty.type => Cons[Int, 0, Empty.type]

trait TList[+T]
object Empty extends TList[Nothing]
class Cons[+E, +H <: E, +T <: TList[E]] extends TList[E]

Compiler crash error

error when pickling tree 
...

See https://scastie.scala-lang.org/dPSBEEYPTSOgoqqtut7exw

@Bersier Bersier added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label labels May 8, 2024
@Gedochao Gedochao added area:pickling stat:cannot reproduce and removed stat:needs triage Every issue needs to have an "area" and "itype" label stat:cannot reproduce labels May 9, 2024
@Gedochao
Copy link

Gedochao commented May 9, 2024

To reproduce outside of scastie:

@main def main = {
  val d1 = foo(Empty)
  foo(d1)
}

type Identity[T] = T

def foo[L <: TList[Int]](t: L): Identity[Bar[L]] = ???

type Bar[L <: TList[Int]] <: TList[Int] = L match
  case Empty.type => Cons[Int, 0, Empty.type]

trait TList[+T]
object Empty extends TList[Nothing]
class Cons[+E, +H <: E, +T <: TList[E]] extends TList[E]

output:

error when pickling tree 
  Identity[
    <error Match type reduction failed since selector Cons[Int, (0 : Int), Empty.type]
matches none of the cases

    case Empty.type => Cons[Int, (0 : Int), Empty.type]>
    ]

error when pickling tree @main def main:
  
    Identity[
      <error Match type reduction failed since selector Cons[Int, (0 : Int), Empty.type]
matches none of the cases

    case Empty.type => Cons[Int, (0 : Int), Empty.type]>
      ]
  
 =
  {
    val d1: Identity[Cons[Int, (0 : Int), Empty.type]] = foo[Empty.type](Empty)
    foo[Cons[Int, (0 : Int), Empty.type]](d1)
  }
error when pickling tree () extends Object() { this: repro$package.type =>
  private def writeReplace(): AnyRef =
    new scala.runtime.ModuleSerializationProxy(classOf[repro$package.type])
  @main def main:
    
      Identity[
        <error Match type reduction failed since selector Cons[Int, (0 : Int), Empty.type]
matches none of the cases

    case Empty.type => Cons[Int, (0 : Int), Empty.type]>
        ]
    
   =
    {
      val d1: Identity[Cons[Int, (0 : Int), Empty.type]] =
        foo[Empty.type](Empty)
      foo[Cons[Int, (0 : Int), Empty.type]](d1)
    }
  type Identity[T >: Nothing <: Any] = T
  def foo[L >: Nothing <: TList[Int]](t: L): Identity[Bar[L]] = ???
  type Bar[L >: Nothing <: TList[Int]] =
    L match 
      {
        case Empty.type => Cons[Int, 0.type, Empty.type]
      }
     <: TList[Int]
}
error when pickling tree @SourceFile("repro.scala") final module class repro$package() extends Object() {
   this: repro$package.type =>
  private def writeReplace(): AnyRef =
    new scala.runtime.ModuleSerializationProxy(classOf[repro$package.type])
  @main def main:
    
      Identity[
        <error Match type reduction failed since selector Cons[Int, (0 : Int), Empty.type]
matches none of the cases

    case Empty.type => Cons[Int, (0 : Int), Empty.type]>
        ]
    
   =
    {
      val d1: Identity[Cons[Int, (0 : Int), Empty.type]] =
        foo[Empty.type](Empty)
      foo[Cons[Int, (0 : Int), Empty.type]](d1)
    }
  type Identity[T >: Nothing <: Any] = T
  def foo[L >: Nothing <: TList[Int]](t: L): Identity[Bar[L]] = ???
  type Bar[L >: Nothing <: TList[Int]] =
    L match 
      {
        case Empty.type => Cons[Int, 0.type, Empty.type]
      }
     <: TList[Int]
}
error when pickling tree package <empty> {
  final lazy module val repro$package: repro$package = new repro$package()
  @SourceFile("repro.scala") final module class repro$package() extends Object()
     { this: repro$package.type =>
    private def writeReplace(): AnyRef =
      new scala.runtime.ModuleSerializationProxy(classOf[repro$package.type])
    @main def main:
      
        Identity[
          <error Match type reduction failed since selector Cons[Int, (0 : Int), Empty.type]
matches none of the cases

    case Empty.type => Cons[Int, (0 : Int), Empty.type]>
          ]
      
     =
      {
        val d1: Identity[Cons[Int, (0 : Int), Empty.type]] =
          foo[Empty.type](Empty)
        foo[Cons[Int, (0 : Int), Empty.type]](d1)
      }
    type Identity[T >: Nothing <: Any] = T
    def foo[L >: Nothing <: TList[Int]](t: L): Identity[Bar[L]] = ???
    type Bar[L >: Nothing <: TList[Int]] =
      L match 
        {
          case Empty.type => Cons[Int, 0.type, Empty.type]
        }
       <: TList[Int]
  }
}

  unhandled exception while running pickler on /Users/pchabelski/IdeaProjects/scala-cli-tests/compiler-repro/repro.scala

  An unhandled exception was thrown in the compiler.
  Please file a crash report here:
  https://github.com/scala/scala3/issues/new/choose
  For non-enriched exceptions, compile with -Yno-enrich-error-messages.

     while compiling: /Users/pchabelski/IdeaProjects/scala-cli-tests/compiler-repro/repro.scala
        during phase: pickler
                mode: Mode(ImplicitsEnabled)
     library version: version 2.13.12
    compiler version: version 3.4.1
            settings: -classpath /Users/pchabelski/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.4.1/scala3-library_3-3.4.1.jar:/Users/pchabelski/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.12/scala-library-2.13.12.jar -d /Users/pchabelski/IdeaProjects/scala-cli-tests/compiler-repro/.scala-build/compiler-repro_8f95553e06-28ebf8438e/classes/main -java-output-version 17 -sourceroot /Users/pchabelski/IdeaProjects/scala-cli-tests/compiler-repro

Exception in thread "main" scala.MatchError: dotty.tools.dotc.core.Types$PreviousErrorType@115dcaea (of class dotty.tools.dotc.core.Types$PreviousErrorType)
        at dotty.tools.dotc.core.tasty.TreePickler.pickleNewType(TreePickler.scala:297)
        at dotty.tools.dotc.core.tasty.TreePickler.pickleType(TreePickler.scala:165)
        at dotty.tools.dotc.core.tasty.TreePickler.pickleNewType$$anonfun$2(TreePickler.scala:186)
        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.core.tasty.TreePickler.pickleNewType(TreePickler.scala:186)
        at dotty.tools.dotc.core.tasty.TreePickler.pickleType(TreePickler.scala:165)
        at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:648)
        at dotty.tools.dotc.core.tasty.TreePickler.pickleTpt(TreePickler.scala:322)
        at dotty.tools.dotc.core.tasty.TreePickler.pickleDef(TreePickler.scala:346)
        at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:594)
        at dotty.tools.dotc.core.tasty.TreePickler.pickleStats$$anonfun$2(TreePickler.scala:386)
        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.core.tasty.TreePickler.pickleStats(TreePickler.scala:386)
        at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:630)
        at dotty.tools.dotc.core.tasty.TreePickler.pickleDef(TreePickler.scala:345)
        at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:596)
        at dotty.tools.dotc.core.tasty.TreePickler.pickleStats$$anonfun$2(TreePickler.scala:386)
        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.core.tasty.TreePickler.pickleStats(TreePickler.scala:386)
        at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:646)
        at dotty.tools.dotc.core.tasty.TreePickler.pickle$$anonfun$1(TreePickler.scala:851)
        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.core.tasty.TreePickler.pickle(TreePickler.scala:858)
        at dotty.tools.dotc.transform.Pickler.run$$anonfun$1$$anonfun$1(Pickler.scala:125)
        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:180)
        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:180)
        at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:354)
        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.core.Phases$Phase.runOn(Phases.scala:360)
        at dotty.tools.dotc.transform.Pickler.runOn(Pickler.scala:197)
        at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:315)
        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:1323)
        at dotty.tools.dotc.Run.runPhases$1(Run.scala:337)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:350)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:360)
        at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:69)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:360)
        at dotty.tools.dotc.Run.compileSources(Run.scala:261)
        at dotty.tools.dotc.Run.compile(Run.scala:246)
        at dotty.tools.dotc.Driver.doCompile(Driver.scala:37)
        at dotty.tools.dotc.Driver.process(Driver.scala:196)
        at dotty.tools.dotc.Driver.process(Driver.scala:164)
        at dotty.tools.dotc.Driver.process(Driver.scala:176)
        at dotty.tools.dotc.Driver.main(Driver.scala:206)
        at dotty.tools.dotc.Main.main(Main.scala)

@odersky
Copy link
Contributor

odersky commented May 9, 2024

It works for me on main.

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

3 participants