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

bugfix : Show correct error message when mutating def #22880

Closed
wants to merge 2 commits into from

Conversation

ajafri2001
Copy link

@ajafri2001 ajafri2001 commented Mar 28, 2025

Related to #22822

Before, this code

def x = 3
x = 4

showed this as an error message

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

after the pr changes, it shows

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

@ajafri2001
Copy link
Author

@hamzaremmal @SethTisue @som-snytt

I think I messed up, we found this issue in the March 17th compiler spree, so I thought this issue had nothing to do with the issue we solved originally, but apparently a few days ago this pr was submitted 💀 which actually solves this particular issue too as a sideeffect.

Tldr - We have a race condition where two pr's attempt to solve the same issue.

@som-snytt
Copy link
Contributor

The other ticket is in my notifications, but probably I thought it was the same ticket. I'd recommend closing it as duplicate.

They say you should solve every problem twice, so that's fine. I remember I did a trivial change; I haven't looked at improving the message for += when rewriting the assignment fails; so far, I managed not to pun on "reassignment".

The details of the solution won't matter too much; I think having adequate tests is the important goal.

I was too lazy to say def and val, so I just made it say value. The better solution is to omit the name. (!) Or only say it in the "explanation", or only if the symbol differs from what the user wrote. The caret is normally sufficient. (Scala 2 omits the redundant name.)

Thanks for putting in the time! Maybe you have more to spare, to pick a path forward.

@ajafri2001
Copy link
Author

ajafri2001 commented Mar 28, 2025

Hello, thank you for taking the time to comment, I am very noob in scala and this is my first time doing something like this.

The details of the solution won't matter too much; I think having adequate tests is the important goal.

Welp, my tests are a joke compared to yours in the diff, and on trying them myself, they fail miserably, specifically the first one,

object X:
  def x: Int = 42
  def x(y: Int): Int = x + y
  val z = 26

def f =
  X.x = 27 // error

The above gives 
[error] 6 |  X.x = 27
[error]   |  ^^^^^^^^
[error]   |  Reassignment to val <none> // was hoping for some reason to have Reassignment to def <none> instead O.O

I was too lazy to say def and val, so I just made it say value. The better solution is to omit the name. (!) Or only say it in the "explanation", or only if the symbol differs from what the user wrote. The caret is normally sufficient. (Scala 2 omits the redundant name.)
Thanks for putting in the time! Maybe you have more to spare, to pick a path forward.

Oh not at all, @hamzaremmal and @SethTisue had to babysit me through the compiler sprees we had earlier, although it took a while for me to take it all in, documentation/googling concepts helped a lot and I was able to get something done..

I do have plenty of time, although I am not sure how to proceed here, it'll have to be spelled out for me 😅. I can also pick up other issues to solve, if you'd like to finish what you originally started.

@ajafri2001 ajafri2001 closed this Mar 28, 2025
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

Successfully merging this pull request may close these issues.

2 participants