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

Error says none for overloaded symbol #22671

Open
som-snytt opened this issue Feb 26, 2025 · 5 comments · May be fixed by #22823 or #22869
Open

Error says none for overloaded symbol #22671

som-snytt opened this issue Feb 26, 2025 · 5 comments · May be fixed by #22823 or #22869
Labels
better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:bug Spree Suitable for a future Spree

Comments

@som-snytt
Copy link
Contributor

Compiler version

3.6.3

Minimized code

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

def test =
  X.x = 27

Output

  snips scala-cli compile --server=false -S 3.6.3 badass.scala
-- [E052] Type Error: /home/amarki/snips/badass.scala:7:6 ----------------------
7 |  X.x = 27
  |  ^^^^^^^^
  |  Reassignment to val <none>
  |
  | longer explanation available when compiling with `-explain`
1 error found
Compilation failed

Expectation

Tell me the name of the unassignable overload.

@som-snytt som-snytt added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label better-errors Issues concerned with improving confusing/unhelpful diagnostic messages and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 26, 2025
@hamzaremmal hamzaremmal added the Spree Suitable for a future Spree label Mar 3, 2025
@mbovel
Copy link
Member

mbovel commented Mar 17, 2025

This issue was picked for the Scala Issue Spree of today, Monday, March 17th. @SethTisue, @iusildra, @jan-pieter and @ajafri2001 will be working on it. If you have any insight into the issue or guidance on how to fix it, please leave it here.

@mbovel
Copy link
Member

mbovel commented Mar 17, 2025

Using -Ydebug-error, we can find the origin of the error:

java.lang.Exception: Stack trace
        at java.base/java.lang.Thread.dumpStack(Thread.java:1389)
        at dotty.tools.dotc.report$.error(report.scala:70)
        at dotty.tools.dotc.typer.Typer.reassignmentToVal$1(Typer.scala:1392)
        at dotty.tools.dotc.typer.Typer.typedAssign(Typer.scala:1475)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3567)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3648)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3725)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3730)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3841)

report.error(ReassignmentToVal(lhsCore.symbol.name), tree.srcPos)

Seems like the tree has no symbol there. Is this correct? If so, maybe a workaround to find the name can be used in this situation?

@SethTisue
Copy link
Member

The lhsCore tree has no symbol because the compiler hasn't resolved the overload.

Can look at tree.lhs instead? The problem is that lhs might have different shapes; in this particular test case it's Select, but it might also be a plain Indent — and are there other possibilities?

@SethTisue
Copy link
Member

after some fumbling we released that NameTree exists. I'm not sure if tree.lhs (or lhsCore) is actually guaranteed to be a NameTree, but if it is we can just call .name on it

@SethTisue
Copy link
Member

(let's use the PR for any further discussion of implementation details)

@som-snytt som-snytt linked a pull request Mar 25, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:bug Spree Suitable for a future Spree
Projects
None yet
4 participants