Re: warning for unused return value
I don't understand. Why would you need to add an unnecessary val? If
the return value is not used, then simply eliminate it and return
Unit.
If the return value is used in some cases and not in others, then
perhaps you need a design review. Why would that be? I'm probably
missing something, but I wonder if that is due to the C-style of
returning an error code (which is sometimes checked and sometimes
not).
If the warning is a compiler option, you always have an out anyway. If
it bothers you, just don't use it.
--Russ
On Feb 29, 6:15 pm, Vlad Patryshev <vpatrys...@...> wrote:
> I'd rather make it an issue in a code revision tool, if there is such a
> thing for Scala.
> Otherwise, it's a normal behavior, I believe, and adding a warning would
> mean that everybody would have to add... add what? An unnecessary val?
>
> Thanks,
> -Vlad
>
>
>
>
>
>
>
> On Wed, Feb 29, 2012 at 5:21 PM, Russ P. <russ.paie...@...> wrote:
> > This topic came up a while ago, but I don't recall exactly how it
> > ended.
>
> > Just today, I had two separate bugs due to a failure to use (i.e.,
> > assign) a return value from a method of an immutable class. The return
> > value was a modified copy of the same class type.
>
> > A simple compiler warning could have saved me substantial debugging
> > time. I realize that such a warning could produce false alerts, but
> > perhaps it could be a compiler option. Also, perhaps the warning could
> > be restricted to certain cases, such as a return value that is not
> > "Unit" or "this." Could something like that be reasonable?
>
> > I sure hope so -- it is easy to forget that a method is returning a
> > modified copy rather than mutating the object.
>
> > --Russ P.