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

Regression with type inference and type constructors

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: Scala 2.10.2-RC1
    • Fix Version/s: Scala 2.10.2-RC2
    • Component/s: Type Inference
    • Labels:
      None

      Description

      The following compiles in 2.10.1, but not in 2.10.2-RC1. This has a straightforward workaround (see comments) and is not urgent.

      trait Box[ K[A[x]] ]
      
      object Box {
         // type constructor composition
         sealed trait ∙[A[_], B[_]] { type l[T] = A[B[T]] }
      
         // composes type constructors inside K
         type SplitBox[K[A[x]], B[x]] = Box[ ({ type l[A[x]] = K[ (A ∙ B)#l] })#l ]
      
         def split[ K[A[x]], B[x] ](base: Box[K]): SplitBox[K,B] = ???
      
         class Composed[B[_], K[A[x]] ] {
            val box: Box[K] = ???
      
            type Split[ A[x] ] = K[ (A ∙ B)#l ]
            val a: Box[Split] = Box.split(box)
      
            //Either of these work:
            //val a: Box[Split] = Box.split[K,B](box)
            //val a: Box[ ({ type l[A[x]] = K[ (A ∙ B)#l ] })#l ] = Box.split(box)
         }
      }
      

      Error:

      
      Box.scala:16: type mismatch;
       found   : Box[K]
       required: Box[K with Composed.this.Split]
      Note: K >: K with Composed.this.Split, but trait Box is invariant in type K.
      You may wish to define K as -K instead. (SLS 4.5)
            val a: Box[Split] = Box.split(box)
                                          ^
      

        Activity

        Hide
        James Iry added a comment - - edited

        I like the proposed fix (as opposed to reverting), but I'm not qualified to like it. I'll talk to Adriaan.

        Show
        James Iry added a comment - - edited I like the proposed fix (as opposed to reverting), but I'm not qualified to like it. I'll talk to Adriaan.
        Hide
        Adriaan Moors added a comment -

        I think Jason's fix makes sense.

        More generally, I think this is a good reminder that we've hit the limit of what we can fix in 2.10.x, especially regarding type checking.
        We should probably start targeting master with fixes by default, and stop merging 2.10.x into master when it becomes too burdensome.

        Show
        Adriaan Moors added a comment - I think Jason's fix makes sense. More generally, I think this is a good reminder that we've hit the limit of what we can fix in 2.10.x, especially regarding type checking. We should probably start targeting master with fixes by default, and stop merging 2.10.x into master when it becomes too burdensome.
        Hide
        Jason Zaugg added a comment -

        I'm about to submit a PR with this change. Just collecting a trace `unify*` for this test case to help to explain things.

        Show
        Jason Zaugg added a comment - I'm about to submit a PR with this change. Just collecting a trace `unify*` for this test case to help to explain things.
        Show
        Jason Zaugg added a comment - https://github.com/scala/scala/pull/2607
        Hide
        Paul Phillips added a comment -
        Show
        Paul Phillips added a comment - Also: https://github.com/scala/scala/pull/2615

          People

          • Assignee:
            Jason Zaugg
            Reporter:
            Mark Harrah
          • Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development