Scala Programming Language
  1. Scala Programming Language
  2. SI-4365

type parameterization unstable based on file compilation order

    Details

      Description

      Extracted from SI-4305, where adriaan has some more info.

      // 1.scala
      trait Derived[+SA, +This <: Derived[SA, This]] extends Base[SA, This] {
        trait Reversed extends super.Reversed with super.Transformed[SA]
        protected override def newReversed: super.Transformed[SA] = new Reversed { } 
      }
      
      // 2.scala
      trait Base[+A, +This <: Base[A, This]] {
        trait Transformed[+B] {
          override def toString: String = error("")
        }
      
        trait Reversed extends Transformed[A] {
          private def x: Unit = {x: A => error("") }
        }
      
        protected def newReversed: Transformed[A] = new Reversed { }
      }  
      
      % scalac29 1.scala 2.scala 
      error: java.lang.Error: A in trait Base cannot be instantiated from [+A,+This <: Base[A,This]]Base[A,This]
      	at scala.tools.nsc.symtab.SymbolTable.abort(SymbolTable.scala:35)
      	at scala.tools.nsc.symtab.Types$$AsSeenFromMap.throwError$$1(Types.scala:3389)
      	at scala.tools.nsc.symtab.Types$$AsSeenFromMap.instParam$$1(Types.scala:3392)
      	at scala.tools.nsc.symtab.Types$$AsSeenFromMap.toInstance$$1(Types.scala:3403)
      
      % scalac29 2.scala 1.scala
      %
      

      Assigning to myself, but don't infer that I know anything about how to fix it, I'm just diving in front of the bullet.

        Issue Links

          Activity

          Hide
          Lukas Rytz added a comment -

          -Yno-generic-signatures can be used as a workaround since https://github.com/scala/scala/commit/93751072ef9ce684a5a8282bbf619f62736c30f4

          Show
          Lukas Rytz added a comment - -Yno-generic-signatures can be used as a workaround since https://github.com/scala/scala/commit/93751072ef9ce684a5a8282bbf619f62736c30f4
          Hide
          Heejong Lee added a comment - - edited

          -Yno-generic-signatures didn't help in my case.
          I still got a following exception from vanilla library source.

          $ qbin/scalac -Yno-generic-signatures -sourcepath src/library -d sandbox -cp build/libs/classes/forkjoin:build/locker/classes/library src/library/scala/collection/SeqViewLike.scala src/library/scala/collection/GenSeqViewLike.scala
          error: something is wrong: cannot make sense of type application
            A
            collection.GenTraversableViewLike[A,Coll,This]
          unhandled exception while transforming GenSeqViewLike.scala
          error: uncaught exception during compilation: FatalError("
               while compiling: src/library/scala/collection/GenSeqViewLike.scala
                  during phase: global=erasure, enteringPhase=explicitouter
               library version: version 2.11.0-20130421-223257-66ba223de5
              compiler version: version 2.11.0-20130421-223257-66ba223de5
            reconstructed args: -d sandbox -classpath build/libs/classes/forkjoin:build/locker/classes/library -Yno-generic-signatures -sourcepath src/library
          
            last tree to typer: TypeTree(trait Seq)
                        symbol: trait Seq in package collection (flags: abstract <trait>)
             symbol definition: abstract trait Seq[+A] extends PartialFunction[Int,A] with Iterable[A] with GenSeq[A] with GenericTraversableTemplate[A,Seq] with SeqLike[A,Seq[A]]
                           tpe: Seq
                 symbol owners: trait Seq -> package collection
                context owners: anonymous class $anonfun -> method createReversedIterator -> class Reversed$class -> trait GenSeqViewLike -> package collection
          
          Show
          Heejong Lee added a comment - - edited -Yno-generic-signatures didn't help in my case. I still got a following exception from vanilla library source. $ qbin/scalac -Yno-generic-signatures -sourcepath src/library -d sandbox -cp build/libs/classes/forkjoin:build/locker/classes/library src/library/scala/collection/SeqViewLike.scala src/library/scala/collection/GenSeqViewLike.scala error: something is wrong: cannot make sense of type application A collection.GenTraversableViewLike[A,Coll,This] unhandled exception while transforming GenSeqViewLike.scala error: uncaught exception during compilation: FatalError(" while compiling: src/library/scala/collection/GenSeqViewLike.scala during phase: global=erasure, enteringPhase=explicitouter library version: version 2.11.0-20130421-223257-66ba223de5 compiler version: version 2.11.0-20130421-223257-66ba223de5 reconstructed args: -d sandbox -classpath build/libs/classes/forkjoin:build/locker/classes/library -Yno-generic-signatures -sourcepath src/library last tree to typer: TypeTree(trait Seq) symbol: trait Seq in package collection (flags: abstract <trait>) symbol definition: abstract trait Seq[+A] extends PartialFunction[Int,A] with Iterable[A] with GenSeq[A] with GenericTraversableTemplate[A,Seq] with SeqLike[A,Seq[A]] tpe: Seq symbol owners: trait Seq -> package collection context owners: anonymous class $anonfun -> method createReversedIterator -> class Reversed$class -> trait GenSeqViewLike -> package collection
          Hide
          Paul Phillips added a comment -

          Aha. Here we see the real benefit of rewrites like AsSeenFromMap. It is not the immediate benefit, but the fact that this time I was fairly easily able to diagnose and apparently fix this issue. Pull request or howl of angst to follow before long.

          Show
          Paul Phillips added a comment - Aha. Here we see the real benefit of rewrites like AsSeenFromMap. It is not the immediate benefit, but the fact that this time I was fairly easily able to diagnose and apparently fix this issue. Pull request or howl of angst to follow before long.
          Show
          Paul Phillips added a comment - https://github.com/scala/scala/pull/2430
          Hide
          Adriaan Moors added a comment -

          The PR is somewhere between a fix and a workaround. Closing though I'd rather see a deeper fix that allows us to go back to comparing by symbol.

          Show
          Adriaan Moors added a comment - The PR is somewhere between a fix and a workaround. Closing though I'd rather see a deeper fix that allows us to go back to comparing by symbol.

            People

            • Assignee:
              Paul Phillips
              Reporter:
              Paul Phillips
              TracCC:
              Johannes Rudolph, Paul Phillips
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development