Skip to content

Puzzling linter message for private var that is never updated. #10282

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

Closed
tpolecat opened this issue Apr 25, 2017 · 5 comments
Closed

Puzzling linter message for private var that is never updated. #10282

tpolecat opened this issue Apr 25, 2017 · 5 comments
Assignees
Labels
Milestone

Comments

@tpolecat
Copy link

tpolecat commented Apr 25, 2017

If you create a class with a private var that is never updated you get a puzzling linter warning:

scala> class A { private var x = 1; val y = x }
<console>:11: warning: private setter of x in class A is never used
       class A { private var x = 1; val y = x }
                             ^

Since users don't typically know that getter/setter pairs are generated it might be more useful to say something like private var x in class A is never updated and could be a val, or similar.

This is in 2.12.2 with -Xlint.

@tpolecat tpolecat changed the title Puzzling warning message for private var that is never updated. Puzzling linter message for private var that is never updated. Apr 25, 2017
@som-snytt
Copy link

The wording is inherited from -Ywarn-unused in 2.12.1. The workaround is to make it private[this] so it doesn't warn at all. When I noticed the wording, I was too tired to bust up the tidy code.

I'm not sure that the equivalence of vars and get/setters isn't widely known, at least among Java refugees. But maybe it could say "synthetic setter x_= of x".

@tpolecat
Copy link
Author

I'm not sure that the equivalence of vars and get/setters isn't widely known, at least among Java refugees.

Since it's normally observed only when calling from Java it's easy to forget. For me anyway. I never think about getters and setters for fields because there's no reason to think they're there.

@som-snytt
Copy link

The browser tab just says, Puzzling linter mess....

som-snytt added a commit to som-snytt/scala that referenced this issue Apr 28, 2017
The runner concatenates -i files and -e expression
to run the code as a script. The addition of -I
broke detection of -i there, which is now fixed.

In addition, allow explicit `-howtorun:repl` which
is now useful for `-e`, so that REPL will handle
`-i` and `-I` and then evalute the expression as
usual (and as the `-help` text implies).

Fixes: scala/bug#10282
@som-snytt
Copy link

That old reference was a typo...

@SethTisue SethTisue added this to the 2.12.5 milestone Feb 16, 2018
@lrytz
Copy link
Member

lrytz commented Feb 22, 2018

scala/scala#6190

@lrytz lrytz closed this as completed Feb 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants