The compiler suggests you re-write it as list = [:one]
list = if false do [:two | list] else list end In your case you have no `else` clause, so if the `if` clause fails, it returns nil, which sets `list` to nil. On Thursday, July 14, 2016 at 10:46:00 AM UTC-4, Fiorillo Nicola wrote: > > Sorry about the object: macro have not meaning in this post. > > On Thursday, July 14, 2016 at 4:44:36 PM UTC+2, Fiorillo Nicola wrote: >> >> Hi all, >> I have a elixir/phoenix project in production written in 1.2.x elixir >> version. >> I'm migrating to 1.3.1 and some "unsafe variable" warning appear: most of >> them were real and useful but I cannot understand the following situation: >> >> #!/usr/bin/env elixir >> list = [:one] >> >> if false do >> list = [:two | list] >> end >> >> IO.inspect list # warning occurs >> >> If, as warning comment suggests, I write >> >> #!/usr/bin/env elixir >> list = [:one] >> >> *list =* >> * if false do* >> * list = [:two | list]* >> * end* >> >> IO.inspect list >> >> # here list is nil >> >> list variable assumes an incorrect value. >> >> Question is: why elixir compiler assume that block must return a value? >> >> Thanks, >> Nicola >> >> >> -- You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-talk/e1733c75-db5d-492d-8670-0596ff32cd69%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
