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

Error message with val and += is confusing #9834

Closed
scabug opened this issue Jun 27, 2016 · 2 comments
Closed

Error message with val and += is confusing #9834

scabug opened this issue Jun 27, 2016 · 2 comments

Comments

@scabug
Copy link

scabug commented Jun 27, 2016

Consider the following statements:

scala> var j = Set("a")
j: scala.collection.immutable.Set[String] = Set(a)

scala> j += "b"

scala> j
res8: scala.collection.immutable.Set[String] = Set(a, b)

scala> val j = Set("a")
j: scala.collection.immutable.Set[String] = Set(a)

scala> j += "b"
<console>:13: error: value += is not a member of scala.collection.immutable.Set[String]
       j += "b"
         ^

The error message seems to imply that += cannot be used with scala.collection.immutable.Set[String]. However, the first example (with var) shows that it can (the two sets are identical; the only thing that differs is the mutability of the LHS variable).

It might be more intuitive to change this particular error message to indicate that the problem is in the attempt to reassign to an immutable variable; that is, "error: reassignment to val" instead.

@scabug
Copy link
Author

scabug commented Jun 27, 2016

Imported From: https://issues.scala-lang.org/browse/SI-9834?orig=1
Reporter: Seth Bromberger (sbromberger)
Affected Versions: 2.11.7, 2.11.8

@scabug
Copy link
Author

scabug commented Jun 28, 2016

@som-snytt said (edited on Nov 25, 2016 8:57:14 PM UTC):
scala/scala#5454

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

2 participants