Record definition order in R11-B0 - incompatibility

Hans.Bolinder <>
Wed May 31 10:00:01 CEST 2006


[Rikard Johansson:]
> The example below works fine in older versions (R9C2 and R10B9 tested)
> but fail to compile with R11B0.
> 
> $ /usr/local/lib/erlang-R11B0/bin/erlc rtest.erl
> ./rtest.erl:5: record r1 undefined
> 
> The reason is appearently to be that record r1 is referenced before it
> is declared, if I swap the two definitions it compiles nicely.
> 
> Besides being questionable coding style, is there a way to make this
> compile with R11 other than re-writing the code? 
> 
> -module(rtest).
> -record(r2, {a=#r1{d=1}, b}).
> -record(r1, {d, e}).
> -export([t/1]).
> 
> t(r1) ->
>     #r1{};
> t(r2) ->
>     #r2{}.

There is no way to make this compile under R11B; you'll have to
rewrite the code.

There used to be a problem with record definitions referring to each
other--the linter would loop forever. An easily implemented fix was to
forbid forward references such as the one in your example. Introducing
this incompatibility was made less awkward by the fact that the Erlang
specification states that the scope of the record declaration starts
immediately after its lexical occurrence ($8.4).

See also the release notes for STDLIB 1.13.12 and 1.14 (OTP-5878).
				   
Best regards,

Hans Bolinder, Erlang/OTP



More information about the erlang-questions mailing list