Strange behaviour with a record in a guard

Thomas Lindgren <>
Tue Mar 4 22:55:52 CET 2003


--- Åke_Johansson_AI_(EAB)
<> wrote:
> ...
> -record(r1,{f1})
> 
> foo(R) when R#r1.f1 == undefined ->
> 	ok.
> ...	
> 
> It seems like foo(R) matches any tuple of size 2 or
> bigger, where the second element is undefined.
> Should not the compiler add code which checks that R
> is a record of the correct type?

If it's any consolation, I definitely think it should.
The very same bug also means that:

-record(a, {f1, f2}).
-record(b, {f3, f4}).

foo() ->
  X = #a{f1 = 1, f2 = 2},
  X#b.f3.

will return 1 rather than failing.

I think this is a bug because this behaviour is
strange and unexpected, and a point of Erlang
philosophy is to avoid that. The right way to do it is
to check the record type first.

Best,
Thomas


__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/



More information about the erlang-questions mailing list