You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
caseobjectQux0Foo(Qux0) // does not compile as expected
Output
NA
Expectation
I may be wrong but I would expect the first snippet to throw a compilation error considering that Bar0 is not a Unit. I've asked this question on the Scala discord channel and got the following answer:
The warning on converting arbitrary values to Unit only occurs when the expression that produces the value is guaranteed to have no side-effects, and the way that scalac checks this is via checking whether the expression is
a simple identifier Qux0 (not compound expressions like Bar.Bar0)
not a method
If both of these conditions are met, scalac will issue a warning
You can reproduce the behavior with Bar0 by import Bar.*
I think it is totally reasonable to consider this a bug and open a ticket for it; imo paths that are made of values should throw this warning too...
The text was updated successfully, but these errors were encountered:
Currently our "purity" check is very coarse. An object is considered pure if it does not have initialization code. That's why Qux0 is pure. On the other hand, the companion object of the enum Bar is not pure since it initializes some arrays.
So the purity warning is currently strictly opportunistic: If it is really easy to tell that something's pure, let's flag it. I think to make progress we should see whether we can get better effect checking in general. I'd prefer that route rather than adding a particular hack that overrides for enum's (and it's not so easy to do, since an enum companion could have side effects.)
Compiler version
3.1.3
Minimized code
Output
NA
Expectation
I may be wrong but I would expect the first snippet to throw a compilation error considering that
Bar0
is not aUnit
. I've asked this question on the Scala discord channel and got the following answer:The text was updated successfully, but these errors were encountered: