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

Match type pattern with compiletime.ops isn't simplified #20166

Closed
EugeneFlesselle opened this issue Apr 11, 2024 · 0 comments · Fixed by #20168
Closed

Match type pattern with compiletime.ops isn't simplified #20166

EugeneFlesselle opened this issue Apr 11, 2024 · 0 comments · Fixed by #20168

Comments

@EugeneFlesselle
Copy link
Contributor

Compiler version

3.5.0-RC1

Minimized code

import scala.compiletime.ops.int.+

type M[I <: Int] = 0 match
  case 1 + 1 => "a"
  case I + 1 => "b"
  case _ => "c"

val _: M[1] = "c"

Output

-- [E007] Type Mismatch Error: tests/playground/example.scala:8:14 -------------
8 |val _: M[1] = "c"
  |              ^^^
  |            Found:    ("c" : String)
  |            Required: M[(1 : Int)]
  |
  |            Note: a match type could not be fully reduced:
  |
  |              trying to reduce  M[(1 : Int)]
  |              failed since selector (0 : Int)
  |              does not match  case (1 : Int) + (1 : Int) => ("b" : String)
  |              and cannot be shown to be disjoint from it either.
  |              Therefore, reduction cannot advance to the remaining case
  |
  |                case _ => ("c" : String)
  |-----------------------------------------------------------------------------
  | Explanation (enabled by `-explain`)
  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  |
  | Tree: "c"
  | I tried to show that
  |   ("c" : String)
  | conforms to
  |   M[(1 : Int)]
  | but none of the attempts shown below succeeded:
  |
  |   ==> ("c" : String)  <:  M[(1 : Int)]
  |     ==> ("c" : String)  <:  (0 : Int) match {   case (2 : Int) => ("a" : String)   case (1 : Int) + (1 : Int) => ("b" : String)   case Any => ("c" : String) } <: ("a" : String) | ("b" : String) | ("c" : String)
  |       ==> String  <:  (0 : Int) match {   case (2 : Int) => ("a" : String)   case (1 : Int) + (1 : Int) => ("b" : String)   case Any => ("c" : String) } <: ("a" : String) | ("b" : String) | ("c" : String)  = false
  |
  | The tests were made under the empty constraint
   -----------------------------------------------------------------------------
@EugeneFlesselle EugeneFlesselle added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label area:match-types and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 11, 2024
@EugeneFlesselle EugeneFlesselle self-assigned this Apr 11, 2024
EugeneFlesselle added a commit to dotty-staging/dotty that referenced this issue Apr 11, 2024
EugeneFlesselle added a commit to dotty-staging/dotty that referenced this issue Apr 11, 2024
EugeneFlesselle added a commit to dotty-staging/dotty that referenced this issue Apr 24, 2024
EugeneFlesselle added a commit to dotty-staging/dotty that referenced this issue Apr 25, 2024
EugeneFlesselle added a commit to dotty-staging/dotty that referenced this issue Apr 30, 2024
sjrd added a commit that referenced this issue May 29, 2024
Fixes #20166

Alternatively placing the tryCompiletimeConstantFold in
`AppliedType#superType` also seems to fix the issue and not break
anything. But I'm not very sure about the spec here either way.
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.

1 participant