-
Notifications
You must be signed in to change notification settings - Fork 1.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
confusing suggestion when non-Unit expression is adapted to Unit (expression discarded in statement position) #18408
Comments
That is normal, but you want to use Possibly I would expect
|
The warning should take into account that this is a statement in the unit expression |def test = fa({42; ()})
| ^^
|A pure expression does nothing in statement position; you may be omitting necessary parentheses We have a similar case in |def f: Unit = 32
| ^^
|A pure expression does nothing in statement position; you may be omitting necessary parentheses |
Similar cases: def fa(f: => Unit): Unit = f
fa(42) // compiles with warning but does nothing or even def fa(f: Unit): Unit = f
fa(42) // compiles with warning but does nothing I'm not sure it can or should be fixed. My 'gut feeling' was |
@scf37 if by "I'm not sure it can or should be fixed", you mean, it's very convenient that the language allows values to be discarded, then I agree. I think the "fix" is to warn and About Nicolas's comment, there is some ambiguity, since an expression may wind up in "statement position" after some rewrite such as "value discard" conversion. So both warnings are relevant. I just changed Scala 2 to emit the same "category" warning for both cases, to make it easier to silence them or make them errors, as they are really the same concern. |
Compiler version
3.3.0
Minimized code
Output
Expectation
Compilation error. I expect this because
42
seems to not match the typeString ?=> Unit
The text was updated successfully, but these errors were encountered: