Skip to content

Match type on parameterized trait doesn't preserve input parameter in type variable #14151

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
s5bug opened this issue Dec 21, 2021 · 4 comments · Fixed by #14563
Closed

Match type on parameterized trait doesn't preserve input parameter in type variable #14151

s5bug opened this issue Dec 21, 2021 · 4 comments · Fixed by #14563

Comments

@s5bug
Copy link

s5bug commented Dec 21, 2021

Compiler version

3.1.0, 3.1.1-RC1, 3.1.1-RC2

Minimized code

sealed trait BoundedPair[A, B <: A]

type Second[A, T <: BoundedPair[A, _ <: A]] <: A = T match {
  case BoundedPair[A, b] => b
}

Output

Found:    b
Required: A

where:    b is a type in type Second with bounds <: Playground.BoundedPair[?, ?]#A

Expectation

Second[Animal, BoundedPair[Animal, Cat]]Cat

@s5bug
Copy link
Author

s5bug commented Dec 21, 2021

Note that this is also true with just

sealed trait Single[B]

type Retrieve[A, T <: Single[_ <: A]] <: A = T match {
  case Single[b] => b
}

but I was not sure whether that is the same issue or not.

@OlivierBlanvillain
Copy link
Contributor

Probably related to #11205

@SethTisue
Copy link
Member

SethTisue commented Jan 13, 2022

not sure whether that is the same issue or not

looks like it to me and Dale, this (the Single version) looks like the one to investigate since it's simpler. we're digging into it, but we're still exploring (flailing?) and don't have a theory yet

@SethTisue
Copy link
Member

SethTisue commented Feb 24, 2022

This can be minimized further:

trait Single[B]
type Retrieve[A, T <: Single[A]] <: A = T match
  case Single[b] => b

-- [E007] Type Mismatch Error: -------------------------------------------------
3 |  case Single[b] => b
  |                    ^
  |                    Found:    b
  |                    Required: A

and further:

trait Single[B]
type Retrieve[A] <: A = Single[A] match
  case Single[b] => b

same error.

@SethTisue SethTisue changed the title Match type on a subtype of a trait with a bounded wildcard doesn't preserve the bound Match type on parameterized trait doesn't preserve input parameter in type variable Feb 24, 2022
@dwijnand dwijnand linked a pull request Feb 25, 2022 that will close this issue
@Kordyjan Kordyjan added this to the 3.1.3 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.

5 participants