Maybe a bug compiling a list of records without comma between them

We have a big list of static records in our system, but today I realized that some records are missing, and the reason is because commas are missing between some of them, for example:


-record(foo, {bar}).

list() ->
        #foo{bar = foo}
        #foo{bar = bar}

Note that there is no comma between the records.
All compile fine, but no warning or error is emitted, and the result is [{foo,bar}].

Can this be considered a bug? Should a warning or error be emitted? Or this is the expected behavior? Why would someone write two records in sequence?

If I change the list/0 to:

list() ->
        {foo, foo}
        {foo, bar}

a syntax error is raised, as expected:

foo.erl:9:9: syntax error before: '{'
%    9|         {foo, bar}

It took hours to find the problem :sweat:

Oof. That’s parsed as #foo{bar = foo}#foo{bar = bar}, which can be thought of as:

A = #foo{bar = foo},
A#foo{bar = bar}.

We’ll look into raising a warning for this. :slight_smile:


Exactly the same topic, but for maps: Dark corner of Erlang syntax . Would be nice to have a warning for both

1 Like

Nice! Thank you!

Yes, the same problem. Thanks for pointing it out.

That became a side effect of some PR a long time ago, that removed the required parenthesis around the first expression.

I don’t remember why it was removed, it was a couple of years ago.
Allow A#foo{a = X)#foo{a = X+1} ?

IIRC it was to allow you to write: instead of (


I know it’s silly but that’s the reason I absolutely love comma first style.
Unfortunately I didn’t find a formatter that could handle that, but I may be wrong.

Yeah, we’re still waiting for @robertoaloi to write the comma-first formatter module for GitHub - AdRoll/rebar3_format: Erlang Formatter for Rebar3 :stuck_out_tongue:


When I give courses I mention that you don’t need parentheses around the leading record access but stress that I think that with out them the syntax becomes messier. :wink: