Skip to content

Lost type member bounds for refined pattern types #13820

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
Linyxus opened this issue Oct 26, 2021 · 4 comments · Fixed by #13881
Closed

Lost type member bounds for refined pattern types #13820

Linyxus opened this issue Oct 26, 2021 · 4 comments · Fixed by #13881

Comments

@Linyxus
Copy link
Contributor

Linyxus commented Oct 26, 2021

Compiler version

3.1.0

Minimized code

trait Expr { type T }

def foo[A](e: Expr { type T = A }) = e match
  case e1: Expr { type T <: Int } =>
    val i: Int = ??? : e1.T

Output

Found:    e1.T
Required: Int

Expectation

The code should be accepted, since e1.T is defined to be the subtype of Int. However, by inspecting the typer, we found that the pattern will be typed as _: Expr{type T = _} where _ is the wildcard type, and the information about the bounds <: Int gets lost.

@soronpo
Copy link
Contributor

soronpo commented Oct 26, 2021

I'm not sure this is a bug. Same behavior in Scala 2.
https://scastie.scala-lang.org/wvu8P6QkQAKujvrsXv2gDg

@dwijnand
Copy link
Member

dwijnand commented Oct 26, 2021

It's is/was a bug in Scala 2 too! There's no reason e1.T can't widen to Int there, that I can think of.

@SethTisue
Copy link
Member

SethTisue commented Oct 27, 2021

We should not allow this to compile unless we also ensure that it emits an unchecked warning.

@abgruszecki abgruszecki removed their assignment Nov 1, 2021
@abgruszecki
Copy link
Contributor

Unassigning myself since if there's anything in the compiler I will be taking a look at anytime soon, it will be issues directly related to GADTs.

odersky added a commit to dotty-staging/dotty that referenced this issue Nov 4, 2021
Only map type bounds to pattern-bound symbols at the toplevel of a pattern, or
when they appear as type arguments. Do not map them in refinements.

Fixes scala#13820
olsdavis pushed a commit to olsdavis/dotty that referenced this issue Apr 4, 2022
Only map type bounds to pattern-bound symbols at the toplevel of a pattern, or
when they appear as type arguments. Do not map them in refinements.

Fixes scala#13820
@Kordyjan Kordyjan added this to the 3.1.2 milestone Aug 2, 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.

6 participants