Skip to content

Match types are (intersection|union)-order-sensitive #6571

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
abgruszecki opened this issue May 27, 2019 · 2 comments
Closed

Match types are (intersection|union)-order-sensitive #6571

abgruszecki opened this issue May 27, 2019 · 2 comments

Comments

@abgruszecki
Copy link
Contributor

Match types allow telling apart intersection types which differ only in the order of elements. We probably don't want to allow doing that.

object Test {                                                                                                                                                                                                                                                                      
  class Inv[T]
  type M[t] = t match {
    case Inv[u] => u
  }
  def foo: M[Inv[Int] & Inv[String]] = ""
  def bar: M[Inv[String] & Inv[Int]] = 0
}

A possible fix would be to use GADTFlexible mode when reducing match types, which would not put any constraints on u from Inv[Int] & Inv[String] <: Inv[u].

@abgruszecki
Copy link
Contributor Author

Weirdly enough, the following does reduce:

scala> object Test {                                                                                                                                                                                                                                                                      
     |   type M[t] = t match {
     |     case u | v => u
     |   }
     |   def foo: M[Int | String] = ""
     | }
// defined object Test

but the following does not:

scala> object Test {                                                                                                                                                                                                                                                                      
     |   type M[t] = t match {
     |     case u & v => u
     |   }
     |   def foo: M[Int & String] = ""
     | }
5 |  def foo: M[Int & String] = ""
  |                             ^^
  |                             Found:    String("")
  |                             Required: Test.M[Int & String]

@abgruszecki abgruszecki changed the title Match types are intersection-order-sensitive Match types are (intersection|union)-order-sensitive May 27, 2019
@panacekcz
Copy link
Contributor

Test.M[Int & String] defined using case u & v also reduces to Int & String - just the error message shows the unreduced type, but so would it for the variant with case u | v if there was a type mismatch.

OlivierBlanvillain added a commit to dotty-staging/dotty that referenced this issue Apr 6, 2022
OlivierBlanvillain added a commit that referenced this issue Apr 7, 2022
michelou pushed a commit to michelou/scala3 that referenced this issue Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants