[erlang-bugs] Parser bug with lists of records

Erik Søe Sørensen ess@REDACTED
Mon Jul 25 15:45:33 CEST 2011


This appears to be not a bug, but just that the code is parsed as a 
combination of "create record" with "modify record".
Compare with this:
   X = #rec{x = 2},
    [#rec{x = 1}, X, #rec{x = 3}]. % with comma

   X = #rec{x = 2},
    [#rec{x = 1}, X#rec{x = 3}]. % without comma

The "modify record" syntax is used most often with a variable (here "X") 
in the place of the original record, but it can by used with other 
subexpressions as well.
In your example, it is of course a bit of a gotcha, and I guess you 
could argue for adding a compiler warning for this particular 
combination (modification of a record just created).


Dima no-name wrote:
> Hallo!
> I have found some strange parser behavior with a list of records.
> The bug has been verified on Erlang R14B03, on Ubuntu 11.04 Linux and 
> Mac OS X.
>
> -------------------- Test Module
>
> -module(bugtest).
> -export([test/0]).
>
> -record(rec, {x}).
>
> test() ->
>     [#rec{x = 1},
>      #rec{x = 2}  % <-- missing comma
>      #rec{x = 3}].
>
> -------------------- Shell Output
> Eshell V5.8.4  (abort with ^G)
> 1> c(bugtest).
> {ok,bugtest}    
> 2> bugtest:test().
> [{rec,1},{rec,3}] 




More information about the erlang-bugs mailing list