Skip to content

Should inline matches strip type ascription? #11291

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
nicolasstucki opened this issue Feb 2, 2021 · 5 comments · Fixed by #11317
Closed

Should inline matches strip type ascription? #11291

nicolasstucki opened this issue Feb 2, 2021 · 5 comments · Fixed by #11317

Comments

@nicolasstucki
Copy link
Contributor

Compiler version

3.0.0.M3

Minimized example

inline def meth =
  inline ("a": Any) match
    case _: String => "ok"

def test = meth

Output

-- Error: Foo.scala:6:11 -------------------------------------------------------
6 |def test = meth
  |           ^^^^
  |           cannot reduce inline match with
  |            scrutinee:  "a":Any : Any
  |            patterns :  case _:String
  | This location contains code that was inlined from Foo.scala:3

Expectation

Should this code compile? It looks like it should. Not sure if there are use-cases where we would want to avoid this.

@nicolasstucki
Copy link
Contributor Author

@odersky @OlivierBlanvillain WDYT?

@abgruszecki
Copy link
Contributor

I think at one point we discussed that inline matches should try to re-type their scrutinees as accurately as possible before matching. Stripping type ascriptions seems to be a part of that.

@nicolasstucki
Copy link
Contributor Author

We do retype the scrutinee. But as the ascription is not removed/ignored the type will not get more precise.

@odersky
Copy link
Contributor

odersky commented Feb 3, 2021

Not sure. Is there a reason why one would need to add : Any to the scrutinee?

@abgruszecki
Copy link
Contributor

A type ascription could prevent a case from matching, so that's one usage. At the same time, one should be able to use .asInstanceOf to accomplish the same. I'd say that the usefulness of stripping type ascriptions is more important than being able to prevent a case from matching. For instance, one may add a type ascription to the value returned by one inline, and I wouldn't expect that to alter how a different inline reduces.

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 4, 2021
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 4, 2021
@Kordyjan Kordyjan added this to the 3.0.0 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.

4 participants