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

Syntactic sugar for calling mutator doesn't always work #4237

Closed
scabug opened this issue Feb 11, 2011 · 3 comments
Closed

Syntactic sugar for calling mutator doesn't always work #4237

scabug opened this issue Feb 11, 2011 · 3 comments
Assignees

Comments

@scabug
Copy link

scabug commented Feb 11, 2011

=== What steps will reproduce the problem (please be specific and use wikiformatting)? ===

  (new { def field = 0; def field_=(i: Int) = () }).field = 5 // compiles as expected
  (new { def field(implicit i: Int) = 0; def field_=(i: Int) = () }).field = 5 // compiles even with implicit params on getter
  (new { def field = 0; def field_=[T](i: Int) = () }).field = 5 // compiles with type param on setter
  (new { def field[T] = 0; def field_=(i: Int) = () }).field = 5 // DOESN'T COMPILE

=== What is the expected behavior? ===
According to the standard, "If x is a parameterless function defined in some template, and the same template contains a setter function x_= as member, then the assignment x = e is interpreted as the invocation x_=(e) of that setter function. Analogously, an assignment f .x = e to a parameterless function x is interpreted as the invocation f.x_=(e)".

I would expect the fourth case to compile as the getter has no parameters.
If I'm allowed to add type parameters to the setter and it still works, I'd expect to be able to add type parameters to the getter as well.

=== What do you see instead? ===
The fourth case doesn't compile and fails with "error: reassignment to val".

=== Additional information ===
Bug is possibly in method typedAssign in Typers.scala

=== What versions of the following are you using? ===

  • Scala: 2.8.1
  • Java: 1.6.0_22
  • Operating system: Mac OS X 10.6.6
@scabug
Copy link
Author

scabug commented Feb 11, 2011

Imported From: https://issues.scala-lang.org/browse/SI-4237?orig=1
Reporter: Jean-Philippe Pellet (jppellet)

@scabug
Copy link
Author

scabug commented Feb 22, 2011

@adriaanm said:
the spec language means that the type parameter case should work as well, so it's a bug

@scabug
Copy link
Author

scabug commented May 31, 2011

Commit Message Bot (anonymous) said:
(extempore in r25048) A getter with type params is still a getter. Closes #4237.
There were two distinct bugs in here, which if I ran the world
would be a wakeup call that robust software cannot emerge from
thousands of lines of low-level AST matching. In case you are
frozen in suspense: I do not run the world. Review by moors.

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

2 participants