elixir icon indicating copy to clipboard operation
elixir copied to clipboard

Variables defined in cond head should not leak

Open josevalim opened this issue 12 years ago • 5 comments

josevalim avatar Mar 15 '14 18:03 josevalim

This is especially annoying in cases like this:

cond do
  name=opt[:name] -> process_name(name)
  short=opt[:short] -> process_name(name)
  true -> ""
end

There is no compilation error, but name in the second call to process_name will be nil.

alco avatar May 12 '14 21:05 alco

You probably have noticed, but the same leaking happens in if and unless clause, too.

SocialfiPanda avatar Jun 05 '14 23:06 SocialfiPanda

@jw2013 if and unless should leak. They don't have "clauses".

ericmj avatar Jun 05 '14 23:06 ericmj

@jw2013 They don't leak, the modify enclosing scope. See this doc

alco avatar Jun 05 '14 23:06 alco

@ericmj @alco Thanks for the explanation.

SocialfiPanda avatar Jun 05 '14 23:06 SocialfiPanda