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

val _ should not create an identifier named "_" #7761

Closed
scabug opened this issue Aug 16, 2013 · 3 comments
Closed

val _ should not create an identifier named "_" #7761

scabug opened this issue Aug 16, 2013 · 3 comments

Comments

@scabug
Copy link

scabug commented Aug 16, 2013

scala> { val _ = "foo"; val _ = "bar"; }
<console>:8: error: _ is already defined as value _
              { val _ = "foo"; val _ = "bar"; }
                                   ^

The error should not be present, because _ is not a simple identifier but a pattern.

In Scala Language Specification 4.1 Value Declarations and Definitions

If p is some pattern other than a simple name or a name followed by a colon and a type,
then the value definition val p = e is expanded as follows:

3. If p has no bound variables:
e match { case p => ()}

In Scala Language Specification 1.1 Identifiers

The following names are reserved words instead of being members of the syntactic class id of lexical identifiers.

abstract case catch class def
do else extends false final
finally for forSome if implicit
import lazy match new null
object override package private protected
return sealed super this throw
trait try true type val
var while with yield
_ : = => <<:
<% >: # @
@scabug
Copy link
Author

scabug commented Aug 16, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7761?orig=1
Reporter: @Atry
Affected Versions: 2.10.2-RC2
See #6426

@scabug
Copy link
Author

scabug commented Aug 16, 2013

@retronym said:
Related to #6426. I'm sort of sure there is also an exact duplicate of this one, but I can't find it.

@scabug
Copy link
Author

scabug commented Aug 16, 2013

@harrah said:
Duplicate of #7691.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant