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

Deprecate _ syntax for type wildcards #18869

Open
nicolasstucki opened this issue Nov 7, 2023 · 4 comments
Open

Deprecate _ syntax for type wildcards #18869

nicolasstucki opened this issue Nov 7, 2023 · 4 comments

Comments

@nicolasstucki
Copy link
Contributor

nicolasstucki commented Nov 7, 2023

Warn in: 3.4
Error in: TBD

@nicolasstucki nicolasstucki changed the title Deprecate _ syntax for wildcards (needs Scala-2 change, PR pending) Deprecate _ syntax for type wildcards Nov 7, 2023
nicolasstucki added a commit that referenced this issue Nov 14, 2023
Based on #18887
First part of #18869

* In `3.4` we emit the deprecation warning and enable the patch with
`-rewrite`.
* In `future` we emit we make this syntax an error

```scala
//> using options -source future
def f: F[_] = ??? // error
```
```diff
//> using options -rewrite -source 3.4-migration
- def f: F[_] = ???
+ def f: F[?] = ???
```
@smarter smarter added this to the 3.4.0 milestone Dec 8, 2023
@smarter
Copy link
Member

smarter commented Dec 8, 2023

I just saw that we now warn on:

trait Base[X]
trait One[X] extends Base[X]
trait Two[X] extends Base[X]

def foo(one: One[Int]) = one match
  case two: Two[_] =>
    two: Two[Int]
  case _ =>
    ()
```-- Warning: try/cond-map.scala:26:16 -------------------------------------------
26 |  case two: Two[_] =>
   |                ^
   |`_` is deprecated for wildcard arguments of types: use `?` instead
   |This construct can be rewritten automatically under -rewrite -source 3.4-migration.

I think this is misleading: in a type test, Foo[_] is sugar for Foo[t] where t is an unnamed type variable with inferred bounds, which is why two is a subtype of Two[Int].
If I replace Two[_] by Two[?] then the code still compiles because it turns out we desugar the latter like the former, so if anything we should deprecate case two: Two[?], but really I think both forms are fine and there's no need to deprecate anything.

@som-snytt
Copy link
Contributor

som-snytt commented Dec 9, 2023

  • change the stackoverflow question from "how many uses of underscore are there in Scala?" to "how many uses of underscore did they leave us?"

@nicolasstucki
Copy link
Contributor Author

We could generalize #18887 to all patterns.

@nicolasstucki
Copy link
Contributor Author

I think this is misleading: in a type test, Foo[_] is sugar for Foo[t] where t is an unnamed type variable with inferred bounds, which is why two is a subtype of Two[Int].
If I replace Two[_] by Two[?] then the code still compiles because it turns out we desugar the latter like the former, so if anything we should deprecate case two: Two[?], but really I think both forms are fine and there's no need to deprecate anything.

Followup in #19249

@nicolasstucki nicolasstucki removed this from the 3.4.0 milestone Dec 12, 2023
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Dec 12, 2023
@nicolasstucki nicolasstucki removed their assignment Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants