-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Fix "a pure expression does nothing" in synthetic REPL code #9161
Conversation
When you invoke repl with "-Wconf:any:error" currently you get ``` $line3.$read.INSTANCE.$iw ^ <synthetic>:6: error: a pure expression does nothing in statement position; multiline expressions might require enclosing parentheses (To diagnose errors in synthetic code, try adding `// show` to the end of your input.) ``` This fixes that by putting it into `val _`. I'm guessing this goes back all the way to 2006? (01443e4#diff-6eef86d28757da64bbaee0b568952750R332) but it's now surfaced.
Using #7563 you can just ascribe the expression, which avoids a needless field. |
|
This is a bug in the "pure expr for warning" check. It doesn't look at the selected path.
The difference in behavior is that ordinarily, warnings in the synthetic cruft are ignored. So maybe it's also undesirable for If an "unused value in statement position" lint is desirable, it would be different from "pure expr" and "value discard". It would be potentially noisier. This comes up frequently because people expect There's that It looks like this is a local block, so |
For the "warning purposes" treating
Yea. I think it would be better if we could tag these as synthetic somehow and skip them in the warning. |
@@ -224,7 +224,7 @@ abstract class TreeInfo { | |||
} | |||
def isWarnableSymbol = { | |||
val sym = tree.symbol | |||
(sym == null) || !(sym.isModule || sym.isLazy || definitions.isByNameParamType(sym.tpe_*)) || { | |||
(sym == null) || !(sym.isSynthetic || sym.decodedName.startsWith("$") || sym.isModule || sym.isLazy || definitions.isByNameParamType(sym.tpe_*)) || { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are both additions necessary for $fullAccessPath
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this particular one only the hackier one sym.decodedName.startsWith("$")
is needed. I'm trying to exempt all synthetic symbols though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should do something more fine-grained than that. It's $line
I think? There's already
val INTERPRETER_IMPORT_WRAPPER = "$iw"
val INTERPRETER_WRAPPER = "$read"
perhaps we just need to add "$line" to that? There's also isLineReadVal
, which it looks like needs some attention from being merged from the 2.12 repl to the 2.13 repl.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
REPL is not the only code that generates synthetic code with dollar sign tho. I'd rather fix "pure expression in any synthetic looking" code problem than this narrow REPL situation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be good, but sym.decodedName.startsWith("$")
is an overreach IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How so? "pure expression does nothing" is a linting warning at best, and by convention $
variable names are not used by normal human-written programs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is every tree symbol a variable name? Does every tree symbol with a $
make it not human-facing?
I've been looking at parts of the exhaustivity checker and there's a 1001 ways where the check can bail out and give no heads-up. So I'm keen that we don't reach for the biggest tool in the toolbox here.
To be fair the problem is the REPL should take care of communicating its synthetic code, rather than having to reverse-engineer it here. Have you seen wrapperCleanup
? Could we do something like that to address the original issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is every tree symbol a variable name? Does every tree symbol with a
$
make it not human-facing?
I'd claim that for the purpose of warning (this method is nested in isPureExprForWarningPurposes
), sure it's ok to ignore $
.
It would be ideal if the symbols created by the REPLs are automatically flagged as synthetic. I guess from my point of view, I sent in quick fixes for the bug that was reported. It's a lint, and likely not going to break anyone's code. I'd rather not spend further time on this, so feel free to send in another PR I guess.
I took the liberty to
I think that should stay the way it is. To initialize a module, refer to the module in a statement, not to one of its fields. A statement reference to a module field is almost certainly a bug and the warning is helpful. |
(makes me wonder why the generated repl code references a field in statement position...) |
Is this where the field used to be the lazily loaded object? Is this issue why I noticed to close scala/bug#10209 about |
Went back to the |
So this was originally reported to sbt as sbt/sbt#5733.
When you invoke repl with "-Wconf:any:error" currently you get
I'm guessing this goes back all the way to 2006? (01443e4#diff-6eef86d28757da64bbaee0b568952750R332) but it's now surfaced.
This fixes that by putting it intoval _
.This fixes this behavior by exempting synthetic-looking things from the "pure expression" warnings.