Uploaded image for project: 'Scala Programming Language'
  1. Scala Programming Language
  2. SI-9760

Higher kinded type arguments not refined by GADT pattern matching

    Details

      Description

      In the following the, pattern matches should refine F to List,

      object HKGADT {
        sealed trait Foo[F[_]]
        final case class Bar() extends Foo[List]
       
        def frob[F[_]](foo: Foo[F]): F[Int] =
          foo match {
            case Bar() => // dotc accepts the pattern, scalac doesn't.
               List(1) // both dotc and scalac error here
          }
       
        sealed trait Foo1[F]
        final case class Bar1() extends Foo1[Int]
        def frob1[A](foo: Foo1[A]) = foo match {
          case Bar1() => 1 // alles klar in scalac, dotc
        }
      }
      

      It doesn't because of this defensive move ... according to Jason Zaugg this,

      does not treat F in the type of the scrutinee of the match as a free type param, which is needed to allow the constructor pattern of type Foo[List] to be allowed.

      It turns out that this exclusion is overly conservative and the bug it was originally introduced to avoid was later fixed independently in this commit.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                milessabin Miles Sabin
                Reporter:
                milessabin Miles Sabin
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: