scala3 icon indicating copy to clipboard operation
scala3 copied to clipboard

Better selection of name for ReassignmentToVal error message

Open jan-pieter opened this issue 8 months ago • 7 comments

(from today's Scala 3 compiler spree)

Use name from tree when it is a NameTree for the ReassignmentToVal error message

Fixes #22671

jan-pieter avatar Mar 17 '25 17:03 jan-pieter

assigning @mbovel as punishment for deserting us :-P

I put some commentary on the ticket about how we found our way to this approach

so then our questions for review are:

  1. is NameTree even the way to go here?
  2. can we assume that lhsCore is always a NameTree? does it make sense to keep the fallback case _ => lhsCore.symbol.name case?

SethTisue avatar Mar 17 '25 17:03 SethTisue

I'm also wondering why it wasn't done this way in the first place, tbh. like does using a symbol (instead of a plain name) in an error message sometimes improve message quality somehow...?

SethTisue avatar Mar 17 '25 18:03 SethTisue

If I import a symbol, it might be renamed. Also, LHS of an assignment can be map(k) style.

Scala 2 expends some LOC on this error case. There is advice1 for does not convert to assignment and advice2 for receiver is not assignable.

som-snytt avatar Mar 17 '25 18:03 som-snytt

I see. In that case, it sounds like it's worth doing some further exploring of whether we can get a hold of the right val with a little more work.

SethTisue avatar Mar 17 '25 23:03 SethTisue

(I've assigned myself as a backstop, but @iusildra @jan-pieter @ajafri2001 if any of you wants to dig into this first, feel free, as I won't get to it right away.)

SethTisue avatar Mar 17 '25 23:03 SethTisue

I submitted https://github.com/scala/scala3/pull/22869 where I'll add spree participants and deserters as co-conspirators. That just uses the other tree. But I'd also like to add the addendum when += fails to become update because of errors; that is fun syntax that is possibly underused.

som-snytt avatar Mar 25 '25 08:03 som-snytt

Many months ago, I saved the format of the co-author tag so I wouldn't forget it, and what I saved was:

➜  ~ cat co-author

    Co-authored-by: Jan-Pieter van den Heuvel
    <[email protected]>

som-snytt avatar Jun 07 '25 03:06 som-snytt

Superseded by https://github.com/scala/scala3/pull/22869

som-snytt avatar Jul 24 '25 20:07 som-snytt