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

Cannot extract type from refinement in match type #15319

Closed
prolativ opened this issue May 30, 2022 · 4 comments · Fixed by #15341
Closed

Cannot extract type from refinement in match type #15319

prolativ opened this issue May 30, 2022 · 4 comments · Fixed by #15341
Labels
area:match-types itype:bug regression This worked in a previous version but doesn't anymore
Milestone

Comments

@prolativ
Copy link
Contributor

Compiler version

According to our bisecting tool:
Last good release: 3.1.3-RC1-bin-20220403-a26a2c3-NIGHTLY
First bad release: 3.1.3-RC1-bin-20220404-ad2553d-NIGHTLY

Minimized code

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

type F[t] =
  t match
    case FAux[a] => a

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

Output

[error] /var/folders/rp/f9y80jvs54lcy26rxnt2y2kw0000gn/T/StructMatch.scala:7:28: Found:    (10 : Int)
[error] Required: F[Object{A = Int}]
[error] val a: F[{type A = Int}] = 10
[error]                            ^^
[error] /var/folders/rp/f9y80jvs54lcy26rxnt2y2kw0000gn/T/StructMatch.scala:8:31: Found:    ("asd" : String)
[error] Required: F[Object{A = String}]
[error] val b: F[{type A = String}] = "asd"
[error] 

Expectation

This should compile without an error as it used to before the regression.

@odersky
Copy link
Contributor

odersky commented May 30, 2022

That looks like a duplicate of a bug we closed recently

@prolativ
Copy link
Contributor Author

Which one? Indeed I had an impression that I've already seen something similar to that but I couldn't find this. Anyway, this still doesn't work on nightly so the fix might have been incomplete

@odersky
Copy link
Contributor

odersky commented May 30, 2022

It was #15155. The code looks similar, not sure whether the error is the same.

@prolativ
Copy link
Contributor Author

Well, the fix for #15155 made the error message more verbose but this still does not compile (I'm checking this directly on the main branch as the nightly release currently available on maven seems to be one day older and does not incorporate the fix)

-- [E007] Type Mismatch Error: /var/folders/rp/f9y80jvs54lcy26rxnt2y2kw0000gn/T/StructMatch.scala:9:27 
9 |val a: F[{type A = Int}] = 10
  |                           ^^
  |                      Found:    (10 : Int)
  |                      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 FAux[a] => a
  |                        and cannot be shown to be disjoint from it either.
  |
  | longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: /var/folders/rp/f9y80jvs54lcy26rxnt2y2kw0000gn/T/StructMatch.scala:10:30 
10 |val b: F[{type A = String}] = "asd"
   |                              ^^^^^
   |                    Found:    ("asd" : String)
   |                    Required: F[Object{A = String}]
   |
   |                    Note: a match type could not be fully reduced:
   |
   |                      trying to reduce  F[Object{A = String}]
   |                      failed since selector  Object{A = String}
   |                      does not match  case FAux[a] => a
   |                      and cannot be shown to be disjoint from it either.
   |
   | longer explanation available when compiling with `-explain`
2 errors found

As suggested by the compiler i tried compiling it with -explain:

-- [E007] Type Mismatch Error: /var/folders/rp/f9y80jvs54lcy26rxnt2y2kw0000gn/T/StructMatch.scala:7:27 
7 |val a: F[{type A = Int}] = 10
  |                           ^^
  |                      Found:    (10 : Int)
  |                      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 FAux[a] => a
  |                        and cannot be shown to be disjoint from it either.
  |-----------------------------------------------------------------------------
  | Explanation (enabled by `-explain`)
  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  |
  | Tree: 10
  | I tried to show that
  |   (10 : Int)
  | conforms to
  |   F[Object{A = Int}]
  | but the comparison trace ended with `false`:
  |
  |   ==> (10 : Int)  <:  F[Object{A = Int}]
  |     ==> Int  <:  F[Object{A = Int}] (left is approximated)
  |       ==> Int  <:  Object{A = Int} match {   case FAux[a] => a } (left is approximated) (right is approximated)
  |       <== Int  <:  Object{A = Int} match {   case FAux[a] => a } (left is approximated) (right is approximated) = false
  |     <== Int  <:  F[Object{A = Int}] (left is approximated) = false
  |     ==> (10 : Int)  <:  Object{A = Int} match {   case FAux[a] => a } (right is approximated)
  |       ==> Int  <:  Object{A = Int} match {   case FAux[a] => a } (left is approximated) (right is approximated)
  |       <== Int  <:  Object{A = Int} match {   case FAux[a] => a } (left is approximated) (right is approximated) = false
  |     <== (10 : Int)  <:  Object{A = Int} match {   case FAux[a] => a } (right is approximated) = false
  |   <== (10 : Int)  <:  F[Object{A = Int}] = false
  |
  | The tests were made under the empty constraint
   -----------------------------------------------------------------------------
-- [E007] Type Mismatch Error: /var/folders/rp/f9y80jvs54lcy26rxnt2y2kw0000gn/T/StructMatch.scala:8:30 
8 |val b: F[{type A = String}] = "asd"
  |                              ^^^^^
  |                      Found:    ("asd" : String)
  |                      Required: F[Object{A = String}]
  |
  |                      Note: a match type could not be fully reduced:
  |
  |                        trying to reduce  F[Object{A = String}]
  |                        failed since selector  Object{A = String}
  |                        does not match  case FAux[a] => a
  |                        and cannot be shown to be disjoint from it either.
  |-----------------------------------------------------------------------------
  | Explanation (enabled by `-explain`)
  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  |
  | Tree: "asd"
  | I tried to show that
  |   ("asd" : String)
  | conforms to
  |   F[Object{A = String}]
  | but the comparison trace ended with `false`:
  |
  |   ==> ("asd" : String)  <:  F[Object{A = String}]
  |     ==> String  <:  F[Object{A = String}] (left is approximated)
  |       ==> String  <:  Object{A = String} match {   case FAux[a] => a } (left is approximated) (right is approximated)
  |       <== String  <:  Object{A = String} match {   case FAux[a] => a } (left is approximated) (right is approximated) = false
  |     <== String  <:  F[Object{A = String}] (left is approximated) = false
  |     ==> ("asd" : String)  <:  Object{A = String} match {   case FAux[a] => a } (right is approximated)
  |       ==> String  <:  Object{A = String} match {   case FAux[a] => a } (left is approximated) (right is approximated)
  |       <== String  <:  Object{A = String} match {   case FAux[a] => a } (left is approximated) (right is approximated) = false
  |     <== ("asd" : String)  <:  Object{A = String} match {   case FAux[a] => a } (right is approximated) = false
  |   <== ("asd" : String)  <:  F[Object{A = String}] = false
  |
  | The tests were made under the empty constraint
   -----------------------------------------------------------------------------
2 errors found

This case seems simpler than #15155
Do we still have any doubts here regarding whether this should reduce or not?
@OlivierBlanvillain what do you think?

@anatoliykmetyuk anatoliykmetyuk added this to the 3.1.3 milestone May 30, 2022
odersky added a commit to dotty-staging/dotty that referenced this issue May 31, 2022
@Kordyjan Kordyjan modified the milestones: 3.1.3, 3.2.0 Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:match-types itype:bug regression This worked in a previous version but doesn't anymore
Projects
None yet
4 participants