Skip to content

match type, poly function: orphan parameter reference #8300

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
Jasper-M opened this issue Feb 12, 2020 · 0 comments · Fixed by #17481
Closed

match type, poly function: orphan parameter reference #8300

Jasper-M opened this issue Feb 12, 2020 · 0 comments · Fixed by #17481

Comments

@Jasper-M
Copy link
Contributor

minimized code

scala> type Bar[X] = X match { 
     |   case List[a] => List[Tuple1[a]]
     |   case Set[a] => Set[Tuple1[a]]
     | }

scala> (Set(1,2,3), List("a","b")).map([A] => (a: A) => a match {
     |   case it: Iterable[x] => it.map(Tuple1(_)).asInstanceOf[Bar[A]]
     | })

Crash output (click arrow to expand)

error when pickling type a
error when pickling type Set[a]
error when pickling type (Set[a], List[String])
error when pickling tree (Set[a], List[String])
error when pickling tree val Tuple_this: (Set[a], List[String]) = 
  Tuple2.apply[Set[a], List[String]](Set.apply[a]([1,2,3 : a]:a*), 
    List.apply[String](["a","b" : String]:String*)
  )
error when pickling tree {
  val f: PolyFunction{apply: [A](a: A): Bar[A]} = 
    {
      final class $anon() extends Object(), PolyFunction {
        def apply[A >: Nothing <: Any](a: A): Bar[A] = 
          a match 
            {
              case it @ _:Iterable[x @ _] => 
                it.map[Tuple1[x]](
                  {
                    def $anonfun(_$2: x): Tuple1[x] = Tuple1.apply[x](_$2)
                    closure($anonfun)
                  }
                ).asInstanceOf[Bar[A]]
            }
      }
      new $anon():PolyFunction{apply: [A](a: A): Bar[A]}
    }
  val Tuple_this: (Set[a], List[String]) = 
    Tuple2.apply[Set[a], List[String]](Set.apply[a]([1,2,3 : a]:a*), 
      List.apply[String](["a","b" : String]:String*)
    )
  runtime.DynamicTuple.dynamicMap[(Tuple_this : (Set[a], List[String])), Bar](
    {
      Tuple_this
    }
  , 
    {
      f
    }
  ):
    Tuple.Map[
      {
        Tuple_this
      }.type
    , Bar]
}
error when pickling tree val res4: (Set[Tuple1[Int]], List[Tuple1[String]]) = 
  {
    val f: PolyFunction{apply: [A](a: A): Bar[A]} = 
      {
        final class $anon() extends Object(), PolyFunction {
          def apply[A >: Nothing <: Any](a: A): Bar[A] = 
            a match 
              {
                case it @ _:Iterable[x @ _] => 
                  it.map[Tuple1[x]](
                    {
                      def $anonfun(_$2: x): Tuple1[x] = Tuple1.apply[x](_$2)
                      closure($anonfun)
                    }
                  ).asInstanceOf[Bar[A]]
              }
        }
        new $anon():PolyFunction{apply: [A](a: A): Bar[A]}
      }
    val Tuple_this: (Set[a], List[String]) = 
      Tuple2.apply[Set[a], List[String]](Set.apply[a]([1,2,3 : a]:a*), 
        List.apply[String](["a","b" : String]:String*)
      )
    runtime.DynamicTuple.dynamicMap[(Tuple_this : (Set[a], List[String])), Bar](
      {
        Tuple_this
      }
    , 
      {
        f
      }
    ):
      Tuple.Map[
        {
          Tuple_this
        }.type
      , Bar]
  }
error when pickling tree () extends Object(), _root_.scala.Serializable { this: rs$line$9.type =>
  private def writeReplace(): AnyRef = 
    new scala.runtime.ModuleSerializationProxy(classOf[rs$line$9.type])
  val res4: (Set[Tuple1[Int]], List[Tuple1[String]]) = 
    {
      val f: PolyFunction{apply: [A](a: A): Bar[A]} = 
        {
          final class $anon() extends Object(), PolyFunction {
            def apply[A >: Nothing <: Any](a: A): Bar[A] = 
              a match 
                {
                  case it @ _:Iterable[x @ _] => 
                    it.map[Tuple1[x]](
                      {
                        def $anonfun(_$2: x): Tuple1[x] = Tuple1.apply[x](_$2)
                        closure($anonfun)
                      }
                    ).asInstanceOf[Bar[A]]
                }
          }
          new $anon():PolyFunction{apply: [A](a: A): Bar[A]}
        }
      val Tuple_this: (Set[a], List[String]) = 
        Tuple2.apply[Set[a], List[String]](Set.apply[a]([1,2,3 : a]:a*), 
          List.apply[String](["a","b" : String]:String*)
        )
      runtime.DynamicTuple.dynamicMap[(Tuple_this : (Set[a], List[String])), Bar
        ]
      (
        {
          Tuple_this
        }
      , 
        {
          f
        }
      ):
        Tuple.Map[
          {
            Tuple_this
          }.type
        , Bar]
    }
}
error when pickling tree @scala.annotation.internal.SourceFile("rs$line$9") final module class rs$line$9$
  (
) extends Object(), _root_.scala.Serializable { this: rs$line$9.type =>
  private def writeReplace(): AnyRef = 
    new scala.runtime.ModuleSerializationProxy(classOf[rs$line$9.type])
  val res4: (Set[Tuple1[Int]], List[Tuple1[String]]) = 
    {
      val f: PolyFunction{apply: [A](a: A): Bar[A]} = 
        {
          final class $anon() extends Object(), PolyFunction {
            def apply[A >: Nothing <: Any](a: A): Bar[A] = 
              a match 
                {
                  case it @ _:Iterable[x @ _] => 
                    it.map[Tuple1[x]](
                      {
                        def $anonfun(_$2: x): Tuple1[x] = Tuple1.apply[x](_$2)
                        closure($anonfun)
                      }
                    ).asInstanceOf[Bar[A]]
                }
          }
          new $anon():PolyFunction{apply: [A](a: A): Bar[A]}
        }
      val Tuple_this: (Set[a], List[String]) = 
        Tuple2.apply[Set[a], List[String]](Set.apply[a]([1,2,3 : a]:a*), 
          List.apply[String](["a","b" : String]:String*)
        )
      runtime.DynamicTuple.dynamicMap[(Tuple_this : (Set[a], List[String])), Bar
        ]
      (
        {
          Tuple_this
        }
      , 
        {
          f
        }
      ):
        Tuple.Map[
          {
            Tuple_this
          }.type
        , Bar]
    }
}
error when pickling tree package <empty> {
  final lazy module val rs$line$9: rs$line$9$ = new rs$line$9$()
  @scala.annotation.internal.SourceFile("rs$line$9") final module class 
    rs$line$9$
  () extends Object(), _root_.scala.Serializable { this: rs$line$9.type =>
    private def writeReplace(): AnyRef = 
      new scala.runtime.ModuleSerializationProxy(classOf[rs$line$9.type])
    val res4: (Set[Tuple1[Int]], List[Tuple1[String]]) = 
      {
        val f: PolyFunction{apply: [A](a: A): Bar[A]} = 
          {
            final class $anon() extends Object(), PolyFunction {
              def apply[A >: Nothing <: Any](a: A): Bar[A] = 
                a match 
                  {
                    case it @ _:Iterable[x @ _] => 
                      it.map[Tuple1[x]](
                        {
                          def $anonfun(_$2: x): Tuple1[x] = Tuple1.apply[x](_$2)
                          closure($anonfun)
                        }
                      ).asInstanceOf[Bar[A]]
                  }
            }
            new $anon():PolyFunction{apply: [A](a: A): Bar[A]}
          }
        val Tuple_this: (Set[a], List[String]) = 
          Tuple2.apply[Set[a], List[String]](Set.apply[a]([1,2,3 : a]:a*), 
            List.apply[String](["a","b" : String]:String*)
          )
        runtime.DynamicTuple.dynamicMap[(Tuple_this : (Set[a], List[String])), 
          Bar
        ](
          {
            Tuple_this
          }
        , 
          {
            f
          }
        ):
          Tuple.Map[
            {
              Tuple_this
            }.type
          , Bar]
      }
  }
}
Exception in thread "main" java.lang.AssertionError: assertion failed: orphan parameter reference: TypeParamRef(a)
	at dotty.DottyPredef$.assertFail(DottyPredef.scala:17)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleNewType(TreePickler.scala:279)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleType(TreePickler.scala:152)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleNewType$$anonfun$11$$anonfun$1(TreePickler.scala:169)
	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.core.tasty.TreePickler.pickleNewType$$anonfun$1(TreePickler.scala:169)
	at dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.core.tasty.TreePickler.withLength(TreePickler.scala:47)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleNewType(TreePickler.scala:169)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleType(TreePickler.scala:152)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleNewType$$anonfun$11$$anonfun$1(TreePickler.scala:169)
	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.core.tasty.TreePickler.pickleNewType$$anonfun$1(TreePickler.scala:169)
	at dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.core.tasty.TreePickler.withLength(TreePickler.scala:47)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleNewType(TreePickler.scala:169)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleType(TreePickler.scala:152)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:558)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTpt(TreePickler.scala:305)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleDef$$anonfun$2(TreePickler.scala:320)
	at dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.core.tasty.TreePickler.withLength(TreePickler.scala:47)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleDef(TreePickler.scala:324)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:509)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree$$anonfun$42$$anonfun$1(TreePickler.scala:485)
	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.core.tasty.TreePickler.pickleTree$$anonfun$18(TreePickler.scala:485)
	at dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.core.tasty.TreePickler.withLength(TreePickler.scala:47)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:487)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTreeUnlessEmpty(TreePickler.scala:308)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleDef$$anonfun$2(TreePickler.scala:322)
	at dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.core.tasty.TreePickler.withLength(TreePickler.scala:47)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleDef(TreePickler.scala:324)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:509)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleStats$$anonfun$2(TreePickler.scala:343)
	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.core.tasty.TreePickler.pickleStats(TreePickler.scala:343)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree$$anonfun$25(TreePickler.scala:546)
	at dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.core.tasty.TreePickler.withLength(TreePickler.scala:47)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:547)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleDef$$anonfun$2(TreePickler.scala:319)
	at dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.core.tasty.TreePickler.withLength(TreePickler.scala:47)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleDef(TreePickler.scala:324)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:522)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleStats$$anonfun$2(TreePickler.scala:343)
	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.core.tasty.TreePickler.pickleStats(TreePickler.scala:343)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree$$anonfun$27(TreePickler.scala:556)
	at dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.core.tasty.TreePickler.withLength(TreePickler.scala:47)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:556)
	at dotty.tools.dotc.core.tasty.TreePickler.pickle$$anonfun$1(TreePickler.scala:713)
	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.core.tasty.TreePickler.pickle(TreePickler.scala:713)
	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:167)
	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:177)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:185)
	at dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:64)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:192)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:134)
	at dotty.tools.repl.ReplCompiler.runCompilationUnit(ReplCompiler.scala:156)
	at dotty.tools.repl.ReplCompiler.compile(ReplCompiler.scala:166)
	at dotty.tools.repl.ReplDriver.compile(ReplDriver.scala:229)
	at dotty.tools.repl.ReplDriver.interpret(ReplDriver.scala:193)
	at dotty.tools.repl.ReplDriver.loop$1(ReplDriver.scala:127)
	at dotty.tools.repl.ReplDriver.runUntilQuit$$anonfun$1(ReplDriver.scala:130)
	at dotty.tools.repl.ReplDriver.withRedirectedOutput(ReplDriver.scala:148)
	at dotty.tools.repl.ReplDriver.runUntilQuit(ReplDriver.scala:130)
	at dotty.tools.repl.Main$.main(Main.scala:6)
	at dotty.tools.repl.Main.main(Main.scala)

This on the other hand does not crash:

scala> type Foo[F[_]] = [X] =>> X match { 
     |   case F[a] => F[Tuple1[a]]
     | }

scala> (Set(1,2,3), List("a","b")).map([A] => (a: A) => a match {
     |   case it: Iterable[x] => it.map(Tuple1(_)).asInstanceOf[Foo[Iterable][A]]
     | })
val res1: (Foo[Iterable][Set[Int]], Foo[Iterable][List[String]]) = (Set((1,), (2,), (3,)),List((a,), (b,)))

scala> val tup: (Iterable[Tuple1[Int]], Iterable[Tuple1[String]]) = res1
val tup: (Iterable[Tuple1[Int]], Iterable[Tuple1[String]]) = (Set((1,), (2,), (3,)),List((a,), (b,)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants