Skip to content

Class and method type parameters named _ no longer supported #235

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
retronym opened this issue Nov 18, 2014 · 4 comments
Closed

Class and method type parameters named _ no longer supported #235

retronym opened this issue Nov 18, 2014 · 4 comments
Assignees

Comments

@retronym
Copy link
Member

Intentional? It is arguably poor style, but should probably be deprecated before removal.

% cat sandbox/test.scala
trait T[_] {
  def foo[_] = 0
  def bar[M[_]] = 0
}

% scalac-hash v2.11.4 ./sandbox/test.scala
warning: there was one feature warning; re-run with -feature for details
one warning found

% ./bin/dotc ./sandbox/test.scala
./sandbox/test.scala:1: error: identifier expected but '_' found.
trait T[_] {
        ^
./sandbox/test.scala:2: error: identifier expected but '_' found.
  def foo[_] = 0
          ^
two errors found
@odersky
Copy link
Contributor

odersky commented Dec 13, 2014

I would argue this should be forbidden. It's a common mistake to confuse type application and parameterized type definition. E.g. I have seen many times people write

 class Foo[Int] { ... }

and then wonder what goes wrong. Allowing an underscore for type parameter definition can only make this worse. The existing occurrences can be handled by a rewriting tool that inserts fresh identifiers for wildcards in type parameter (not type argument!) position. Assigning to Samuel.

@samuelgruetter
Copy link
Contributor

I had anticipated this decision and already implemented this feature some days ago ;-)

@odersky
Copy link
Contributor

odersky commented Dec 13, 2014

Cool! Looking forward to the PR.

@smarter
Copy link
Member

smarter commented Nov 18, 2015

Closed because this is as intended.

@smarter smarter closed this as completed Nov 18, 2015
WojciechMazur pushed a commit to WojciechMazur/dotty that referenced this issue May 8, 2025
Backport "Align erasure of `Array[Nothing]` and `Array[Null]` with Scala 2" to 3.3 LTS
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

4 participants