Skip to content
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

Type matching on structural types does not work (nor gives an error) #15312

Closed
p-pavel opened this issue May 29, 2022 · 2 comments · Fixed by #15375
Closed

Type matching on structural types does not work (nor gives an error) #15312

p-pavel opened this issue May 29, 2022 · 2 comments · Fixed by #15375

Comments

@p-pavel
Copy link

p-pavel commented May 29, 2022

Compiler version

3.1.2

Minimized code

type F[t] =
  t match
    case {type A = Float} => Int
    case {type A = Int} => String

val a: F[{type A = Float}] = 10
val b: F[{type A = Int}] = "asd" // Found:("asd" : String) Required: F[Object{A = Int}]

Output

Found:("asd" : String) Required: F[Object{A = Int}]

Expectation

I expect the compiler to either do the right match (accepting string value for val b) or give some diagnostic about the limitation of match types not playing with structural patterns

@p-pavel p-pavel added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels May 29, 2022
@prolativ prolativ added area:match-types and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels May 30, 2022
@prolativ
Copy link
Contributor

There used to be a workaround for that

type FAux[A0] = {type A = A0}

type F[t] =
  t match
    case FAux[a] => a match
      case Float => Int
      case Int => String

val a: F[{type A = Float}] = 10
val b: F[{type A = Int}] = "asd"

however this stopped working because of the regression #15319.
The original example from this issue seems to have never worked.

@odersky
Copy link
Contributor

odersky commented Jun 4, 2022

In main I see the following diagnostic:

7 |val b: F[{type A = Int}] = "asd" // Found:("asd" : String) Required: F[Object{A = Int}]
  |                           ^^^^^
  |               Found:    ("asd" : String)
  |               Required: F[Object{A = Int}]
  |
  |               Note: a match type could not be fully reduced:
  |
  |                 trying to reduce  F[Object{A = Int}]
  |                 failed since selector  Object{A = Int}
  |                 does not match  case Object{A = Float} => Int
  |                 and cannot be shown to be disjoint from it either.
  |                 Therefore, reduction cannot advance to the remaining case
  |
  |                   case Object{A = Int} => String
  |

So it explains what goes wrong, but we should be able to make the disjointness check more precise, so that this passes.

@odersky odersky self-assigned this Jun 4, 2022
odersky added a commit to dotty-staging/dotty that referenced this issue Jun 5, 2022
bishabosha pushed a commit to dotty-staging/dotty that referenced this issue Oct 18, 2022
@Kordyjan Kordyjan added this to the 3.2.0 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants