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

**URL:** <https://erlangforums.com/t/maybe-a-bug-compiling-a-list-of-records-without-comma-between-them/3239>\
**Category:** Questions / Help\
**Tags:** possible-bug\
**Created:** [January 29, 2024, 2:22pm UTC](https://erlangforums.com/t/maybe-a-bug-compiling-a-list-of-records-without-comma-between-them/3239 "2024-01-29T14:22:59Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![williamthome](https://erlangforums.com/user_avatar/erlangforums.com/williamthome/32/471_2.png) [@williamthome](https://erlangforums.com/u/williamthome)\
**Post date:** [January 29, 2024, 2:22pm UTC](https://erlangforums.com/t/maybe-a-bug-compiling-a-list-of-records-without-comma-between-them/3239/1 "2024-01-29T14:22:59Z")

</div>

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:

```erlang
-module(foo).
-export([list/0]).

-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:

```erlang
list() ->
    [
        {foo, foo}
        {foo, bar}
    ].

```

a syntax error is raised, as expected:

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

```

It took hours to find the problem 😓

---

<div class="post-metadata">

**Author:** ![jhogberg](https://erlangforums.com/user_avatar/erlangforums.com/jhogberg/32/179_2.png) [@jhogberg](https://erlangforums.com/u/jhogberg)\
**Post date:** [January 29, 2024, 2:28pm UTC](https://erlangforums.com/t/maybe-a-bug-compiling-a-list-of-records-without-comma-between-them/3239/2 "2024-01-29T14:28:43Z")

</div>

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

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

```

We’ll look into raising a warning for this. 🙂

---

<div class="post-metadata">

**Author:** ![mmin](https://erlangforums.com/user_avatar/erlangforums.com/mmin/32/2193_2.png) [@mmin](https://erlangforums.com/u/mmin)\
**Post date:** [January 29, 2024, 2:30pm UTC](https://erlangforums.com/t/maybe-a-bug-compiling-a-list-of-records-without-comma-between-them/3239/3 "2024-01-29T14:30:26Z")

</div>

Exactly the same topic, but for maps: [Dark corner of Erlang syntax](https://erlangforums.com/t/dark-corner-of-erlang-syntax/1192) . Would be nice to have a warning for both

---

<div class="post-metadata">

**Author:** ![williamthome](https://erlangforums.com/user_avatar/erlangforums.com/williamthome/32/471_2.png) [@williamthome](https://erlangforums.com/u/williamthome)\
**Post date:** [January 29, 2024, 2:41pm UTC](https://erlangforums.com/t/maybe-a-bug-compiling-a-list-of-records-without-comma-between-them/3239/4 "2024-01-29T14:41:13Z")

</div>

> [@jhogberg](#):
>
> We’ll look into raising a warning for this. 🙂

Nice! Thank you!

> [@mmin](#):
>
> Exactly the same topic, but for maps: [Dark corner of Erlang syntax](https://erlangforums.com/t/dark-corner-of-erlang-syntax/1192) . Would be nice to have a warning for both

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

---

<div class="post-metadata">

**Author:** ![dgud](https://erlangforums.com/user_avatar/erlangforums.com/dgud/32/191_2.png) [@dgud](https://erlangforums.com/u/dgud)\
**Post date:** [January 29, 2024, 2:44pm UTC](https://erlangforums.com/t/maybe-a-bug-compiling-a-list-of-records-without-comma-between-them/3239/5 "2024-01-29T14:44:03Z")

</div>

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} ?

---

<div class="post-metadata">

**Author:** ![garazdawi](https://erlangforums.com/user_avatar/erlangforums.com/garazdawi/32/175_2.png) [@garazdawi](https://erlangforums.com/u/garazdawi)\
**Post date:** [January 29, 2024, 3:01pm UTC](https://erlangforums.com/t/maybe-a-bug-compiling-a-list-of-records-without-comma-between-them/3239/6 "2024-01-29T15:01:24Z")

</div>

> [@dgud](#):
>
> I don’t remember why it was removed.

IIRC it was to allow you to write: `A#foo.bar#foo.bar` instead of `(A#foo.bar)#foo.bar`.

---

<div class="post-metadata">

**Author:** ![carlotm](https://erlangforums.com/user_avatar/erlangforums.com/carlotm/32/1870_2.png) [@carlotm](https://erlangforums.com/u/carlotm)\
**Post date:** [January 30, 2024, 6:36am UTC](https://erlangforums.com/t/maybe-a-bug-compiling-a-list-of-records-without-comma-between-them/3239/7 "2024-01-30T06:36:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![elbrujohalcon](https://erlangforums.com/user_avatar/erlangforums.com/elbrujohalcon/32/241_2.png) [@elbrujohalcon](https://erlangforums.com/u/elbrujohalcon)\
**Post date:** [January 30, 2024, 7:00am UTC](https://erlangforums.com/t/maybe-a-bug-compiling-a-list-of-records-without-comma-between-them/3239/8 "2024-01-30T07:00:51Z")

</div>

Yeah, we’re still waiting for @robertoaloi to write the comma-first formatter module for [GitHub - AdRoll/rebar3\_format: Erlang Formatter for Rebar3](https://github.com/AdRoll/rebar3_format) 😛

---

<div class="post-metadata">

**Author:** ![jhogberg](https://erlangforums.com/user_avatar/erlangforums.com/jhogberg/32/179_2.png) [@jhogberg](https://erlangforums.com/u/jhogberg)\
**Post date:** [January 30, 2024, 10:03am UTC](https://erlangforums.com/t/maybe-a-bug-compiling-a-list-of-records-without-comma-between-them/3239/9 "2024-01-30T10:03:58Z")

</div>

> <https://github.com/erlang/otp/pull/8069>
>
> This PR adds a warning whenever a literal map or record is updated, catching err…ors like missing commas in lists of records:
> 
> \`\`\`
> \-module(foo).
> \-export(\[list/0\]).
> 
> \-record(foo, {bar}).
> 
> list() -\>
> \[
> #foo{bar = foo} %% Missing comma!
> #foo{bar = bar}
> \].
> \`\`\`
> 
> https://erlangforums.com/t/maybe-a-bug-compiling-a-list-of-records-without-comma-between-them/3239

---

<div class="post-metadata">

**Author:** ![rvirding](https://erlangforums.com/user_avatar/erlangforums.com/rvirding/32/178_2.png) [@rvirding](https://erlangforums.com/u/rvirding)\
**Post date:** [January 30, 2024, 3:44pm UTC](https://erlangforums.com/t/maybe-a-bug-compiling-a-list-of-records-without-comma-between-them/3239/10 "2024-01-30T15:44:37Z")

</div>

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. 😉
