scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.81k stars 1.05k forks source link

Type pattern variables not supported at the top level of match types and inline matches #6018

Open milessabin opened 5 years ago

milessabin commented 5 years ago

The following is rejected,

import scala.compiletime._

object Test {
  type Foo[T] = T match {
    case f[Int] => f[String]
  }

  val ls: Foo[List[Int]] = ???
}

object Test2 {
  inline def summon[T] = implicit match {
    case t: T => t
  }

  inline def foo[T] = inline erasedValue[T] match {
    case _: f[Int] => summon[f[String]]
  }
}

with,

-- [E006] Unbound Identifier Error: tests/pos/match-bugs.scala:5:9 -------------
5 |    case f[Int] => f[String]
  |         ^
  |         Not found: type f

longer explanation available when compiling with `-explain`
-- [E006] Unbound Identifier Error: tests/pos/match-bugs.scala:5:19 ------------
5 |    case f[Int] => f[String]
  |                   ^
  |                   Not found: type f

longer explanation available when compiling with `-explain`
-- [E006] Unbound Identifier Error: tests/pos/match-bugs.scala:17:12 -----------
17 |    case _: f[Int] => summon[f[String]]
   |            ^
   |            Not found: type f

longer explanation available when compiling with `-explain`
-- [E006] Unbound Identifier Error: tests/pos/match-bugs.scala:17:29 -----------
17 |    case _: f[Int] => summon[f[String]]
   |                             ^
   |                             Not found: type f
LPTK commented 5 years ago

Note that this is not specific to inline matches or to higher-kinded types.

scala> () match { case t: a => t }
1 |() match { case t: a => t }
  |                   ^
  |                   Not found: type a

Pattern matching is currently full of weird inconsistencies

odersky commented 5 years ago

Pattern matching has restructions, as is the case in all languages. Unless someone will make a focussed and prolonged effort to change this, it will stay that way.