[erlang-bugs] bogus 'unsafe variable' warning with try-else
Raimo Niskanen
raimo+erlang-bugs@REDACTED
Thu Nov 20 16:48:34 CET 2014
On Thu, Nov 20, 2014 at 02:44:55PM +0100, Joel Ericson wrote:
> The binding {ok,Bin} = file:read(F, 1024*1024) *can* fail. E.g., if I were
> to load in my own file library, where file:read/2 returns {data,Data}, this
Yes, but since the try .. of .. after .. end construct does not catch any
exceptions there is no way to reach the code after it without having
succeeded with the variable binding.
> fails. And as far as I know, one is not supposed to assume anything about
> what other modules return during compile time.
>
> Regards
> Joel
>
> On Thu, Nov 20, 2014 at 2:22 PM, Kostis Sagonas <kostis@REDACTED> wrote:
>
> > On 11/20/14 15:13, Anthony Ramine wrote:
> >
> >> try file:read(F, 1024 * 1024) of
> >> {ok,Bin} -> binary_to_term(Bin)
> >> after
> >> file:close(F)
> >> end
> >>
> >
> >
> > And the reason to _having_ to write this is? (*)
> >
> > Cheers,
> > Kostis
> >
> > (*) Less bugs are exposed in the compiler and less baby cats die in China
> > if we all write like that, perhaps? :)
> >
> > Jokes aside, I also agree the above code is nicer, but that does not mean
> > that the current warning is bogus and the analysis should be fixed.
> >
> > _______________________________________________
> > erlang-bugs mailing list
> > erlang-bugs@REDACTED
> > http://erlang.org/mailman/listinfo/erlang-bugs
> >
> _______________________________________________
> erlang-bugs mailing list
> erlang-bugs@REDACTED
> http://erlang.org/mailman/listinfo/erlang-bugs
--
/ Raimo Niskanen, Erlang/OTP, Ericsson AB
More information about the erlang-bugs
mailing list