-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Use other tree for actual symbol of Assign #22869
base: main
Are you sure you want to change the base?
Conversation
cbdcdd5
to
ef97824
Compare
|Also, assignment syntax can be used if there is a corresponding setter: | ||
| ${hl("def")} ${name}${hl("_=(x: Int): Unit = _v = x")} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't add this one here. The sugaring for setters is very very scope specific and fragile. It cannot be summarized into the assignment syntax can be used if there is a corresponding setter...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think some words are necessary for user who needs an explanation; I restricted it to class members.
@@ -1528,14 +1528,16 @@ class AmbiguousExtensionMethod(tree: untpd.Tree, expansion1: tpd.Tree, expansion | |||
|
|||
class ReassignmentToVal(name: Name)(using Context) | |||
extends TypeMsg(ReassignmentToValID) { | |||
def msg(using Context) = i"""Reassignment to val $name""" | |||
def msg(using Context) = i"""Reassignment to value $name""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could actually pass the symbol instead of the name and we would either get val
, def
,... depending on the actual symbol.
ef97824
to
76c6790
Compare
I started down the long tail of polishing words. Let the symbol say what it is, and restrict setter explanation to class-owned symbols. (Need to check class params.) |
76c6790
to
7785a12
Compare
7785a12
to
21d48c8
Compare
Fixes #22671
Scala 2 says that the setter was not found.
For
+=
it will add what error caused "convert to assignment" to fail. I added a test but not the addendum.The Scala 3 message text is tweaked. (A def is not a val, so just say "value".)
Scala 2 omits the name, since the caret points to the name, but supplying the name is useful if it is different from what is written.