Skip to content

Match type subtyping wrongly instantiates types in patterns #9107

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
OlivierBlanvillain opened this issue Jun 4, 2020 · 0 comments · Fixed by #12320
Closed

Match type subtyping wrongly instantiates types in patterns #9107

OlivierBlanvillain opened this issue Jun 4, 2020 · 0 comments · Fixed by #12320

Comments

@OlivierBlanvillain
Copy link
Contributor

There is something off with match type subtyping:

trait Inv[T]
object Test {
  def ev[X] = implicitly[
    (X match { case Inv[t] => Int }) =:=
    (X match { case Inv[t] => t })
  ]
}
==> isSubType internal.MatchCase[Inv[t], Int] <:< internal.MatchCase[Inv[t], t] ?
  ==> isSubType Inv[t] <:< Inv[t] ?
  <== isSubType Inv[t] <:< Inv[t]  = true   
  ==> isSubType Inv[t] <:< Inv[t] ?
  <== isSubType Inv[t] <:< Inv[t]  = true   
  ==> isSubType Int <:< t ?                 
    ==> isSubType Int <:< t ?           
      ==> isSubType Int <:< Nothing ?
      <== isSubType Int <:< Nothing  = false  
    <== isSubType Int <:< t  = false        
    ==> lub(Nothing, Int, canConstrain=false)?
    <== lub(Nothing, Int, canConstrain=false) = Int
    ==> isSubType Int <:< Any ?             
    <== isSubType Int <:< Any  = true
  <== isSubType Int <:< t  = true
<== isSubType internal.MatchCase[Inv[t], Int] <:< internal.MatchCase[Inv[t], t] = true

The issue seams to be really match type related, as the following minimization attempt is correctly rejected:

trait M[F[_]]
trait Inv[T]
object Test {
  def ev[X] = implicitly[
    M[[t] =>> internal.MatchCase[Inv[t], t]] =:=
    M[[t] =>> internal.MatchCase[Inv[t], Int]]
  ] // error
}
==> isSubType internal.MatchCase[Inv[t], Int] <:< internal.MatchCase[Inv[t], t] ?
  ==> isSubType internal.type <:< internal.type ?
  <== isSubType internal.type <:< internal.type  = true
  ==> isSubType Inv[t] <:< Inv[t] ?
  <== isSubType Inv[t] <:< Inv[t]  = true
  ==> isSubType Inv[t] <:< Inv[t] ?
  <== isSubType Inv[t] <:< Inv[t]  = true
  ==> isSubType Int <:< t ?
    ==> isSubType Int <:< t ?
      ==> isSubType Int <:< Nothing ?
      <== isSubType Int <:< Nothing  = false
    <== isSubType Int <:< t  = false
  <== isSubType Int <:< t  = false
<== isSubType internal.MatchCase[Inv[t], Int] <:< internal.MatchCase[Inv[t], t] = false
OlivierBlanvillain added a commit to dotty-staging/dotty that referenced this issue Jun 4, 2020
Because of `caseLambda = constrained(cas)` in `def matchCase`, subtyping
wrongly things that it's OK to further constrain types introduced in match
type patterns. This commit fixes the issue with a stronger version of
`inFrozenConstraint` around match type reduction.
OlivierBlanvillain added a commit to dotty-staging/dotty that referenced this issue Jun 4, 2020
Because of `caseLambda = constrained(cas)` in `def matchCase`, subtyping
wrongly things that it's OK to further constrain types introduced in match
type patterns. This commit fixes the issue with a stronger version of
`inFrozenConstraint` around match type reduction.
@nicolasstucki nicolasstucki linked a pull request Jun 24, 2020 that will close this issue
OlivierBlanvillain added a commit to dotty-staging/dotty that referenced this issue Jun 24, 2020
Because of `caseLambda = constrained(cas)` in `def matchCase`, subtyping
wrongly things that it's OK to further constrain types introduced in match
type patterns. This commit fixes the issue with a stronger version of
`inFrozenConstraint` around match type reduction.
OlivierBlanvillain added a commit to dotty-staging/dotty that referenced this issue Apr 23, 2021
Because of `caseLambda = constrained(cas)` in `def matchCase`, subtyping
wrongly things that it's OK to further constrain types introduced in match
type patterns. This commit fixes the issue with a stronger version of
`inFrozenConstraint` around match type reduction.
OlivierBlanvillain added a commit to dotty-staging/dotty that referenced this issue Apr 26, 2021
OlivierBlanvillain added a commit to dotty-staging/dotty that referenced this issue Apr 29, 2021
Because of `caseLambda = constrained(cas)` in `def matchCase`, subtyping
wrongly things that it's OK to further constrain types introduced in match
type patterns. This commit fixes the issue with a stronger version of
`inFrozenConstraint` around match type reduction.
OlivierBlanvillain added a commit to dotty-staging/dotty that referenced this issue Apr 30, 2021
Because of `caseLambda = constrained(cas)` in `def matchCase`, subtyping
wrongly things that it's OK to further constrain types introduced in match
type patterns. This commit fixes the issue with a stronger version of
`inFrozenConstraint` around match type reduction.
OlivierBlanvillain added a commit to dotty-staging/dotty that referenced this issue May 4, 2021
odersky pushed a commit to dotty-staging/dotty that referenced this issue May 4, 2021
neko-kai pushed a commit to 7mind/dotty that referenced this issue May 5, 2021
michelou pushed a commit to michelou/scala3 that referenced this issue May 14, 2021
@Kordyjan Kordyjan added this to the 3.0.1 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment