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

Incorrect "assignment to val" error when assigning to a def #22822

Open
SethTisue opened this issue Mar 17, 2025 · 2 comments
Open

Incorrect "assignment to val" error when assigning to a def #22822

SethTisue opened this issue Mar 17, 2025 · 2 comments
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:bug Spree Suitable for a future Spree

Comments

@SethTisue
Copy link
Member

SethTisue commented Mar 17, 2025

(noticed while working on #22671 at a spree)

Minimized code

Welcome to Scala 3.6.4 (17.0.14, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
                                                                                                    
scala> def x = 3
def x: Int
                                                                                                    
scala> x = 4

Output

-- [E052] Type Error: ----------------------------------------------------------
1 |x = 4
  |^^^^^
  |Reassignment to val x

Expectation

x isn't a val, it's a def, so it's nonsensical for the error to refer to "val x"

@SethTisue SethTisue added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label Spree Suitable for a future Spree labels Mar 17, 2025
@SethTisue
Copy link
Member Author

Scala 2 takes a different tack (we don't necessarily need to do it the same in Scala 3)

scala 2.13.16> object O { def x = 3 }
object O

scala 2.13.16> O.x = 5
                 ^
               error: value x_= is not a member of object O

@hamzaremmal hamzaremmal added the better-errors Issues concerned with improving confusing/unhelpful diagnostic messages label Mar 17, 2025
@Gedochao Gedochao added area:reporting Error reporting including formatting, implicit suggestions, etc and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Mar 18, 2025
@som-snytt
Copy link
Contributor

I think mentioning "explicit setter" would be useful in the "explanation". I don't know whether the explanation is used a lot or never. I certainly never re-run with -explanation, what a hassle. Does the IDE use it? That would be ideal (IDEal).

Also, I suggested that this is a duplicate of the other "improve the message" ticket, but it's also fine to leave it open, especially if #22880 follows up with better improvements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:bug Spree Suitable for a future Spree
Projects
None yet
Development

No branches or pull requests

4 participants