Skip to content

Multiple dummy bindings using underscore not allowed #7691

Closed
scala/scala
#6218
@scabug

Description

@scabug

These show that the compiler knows that a wildcard is not a valid identifier in accordance with the spec:

scala> def _ = 3
<console>:1: error: identifier expected but '_' found.
       def _ = 3
           ^

scala> class _
<console>:1: error: identifier expected but '_' found.
       class _
             ^

scala> val _ = 3
<console>:5: error: identifier expected but '_' found.
  lazy val $result = _
                                          ^
<console>:10: error: identifier expected but '_' found.
 + "_: Int = " + scala.runtime.ScalaRunTime.replStringOf(_, 1000)
                                                                              ^

However, scalac complains about multiple bindings to _ :

scala> { val _ = 3; val _ = 5; 7 }
<console>:8: error: _ is already defined as value _
              { val _ = 3; val _ = 5; 7 }
                               ^

This was reported on a mailing list a while ago (http://www.scala-lang.org/node/7159), but never filed as an issue. One improvement since then:

scala> { val _ = 3; `_` }
<console>:1: error: wildcard invalid as backquoted identifier
       { val _ = 3; `_` }
                    ^

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions