[erlang-bugs] Parser error regression for ERTS V5.8.3

Robert Virding <>
Sun Dec 26 22:26:33 CET 2010


This is not a bug, it's a feature.

Unfortunately.

As you have noted it is a result of the syntax change which allowed nested record access without parentheses. But it is not an error as the parse is correct. What confuses the issue is that it is spread over three lines and that missing commas have exposed it. If you read it as:

#foo(bar=1}#foo{bar=2}#foo{bar=1}

it becomes clearer. This is parsed as (with parentheses):

( ( #foo{bar=1} ) #foo{bar=2} ) #foo{bar=3}

It then becomes clear that the parse and resultant value are correct and the confusion arises from not having to add parentheses. This usage was probably not intended when the mandatory parentheses were removed by became legal, more as a "by-product".

I would support rolling back.

Robert

P.S. I am trying not to say "vad var det jag sa" (what did I tell you) as one of the reasons I/we added the parentheses was to make it easier for the user and not just the parser. :-)

----- "Jesper Louis Andersen" <> wrote:

> Consider the following module:
> 
> ==
> -module(foo).
> -compile(export_all).
> 
> -record(foo, { bar }).
> 
> 
> x() ->
>     [ #foo { bar = 1}
>       #foo { bar = 2}
>       #foo { bar = 3}].
> ==
> 
> In ERTS V5.8.3 this is valid (notice the lack of commas at the end of
> each line). It is also valid in V5.8.1, but it fails on V5.7.4:
> 
> ./foo.erl:9: syntax error before: '#'
> ./foo.erl:4: Warning: record foo is unused
> 
> The result of foo:x(). is:
> 
> Erlang R14B02 (erts-5.8.3) [source] [64-bit] [smp:2:2] [rq:2]
> [async-threads:0] [hipe] [kernel-poll:false]
> 
> Eshell V5.8.3  (abort with ^G)
> 1> c(foo).
> {ok,foo}
> 2> foo:x().
> [{foo,3}]
> 3>
> 
> which I find highly confusing and wrong.
> 
> The parse derivation is: expr -> list -> tail -> expr -> record_expr
> --(by the last clause erl_parse.yrl  L351)--> record_expr ....
> 
> (parse derivation from commit 609e7ade98c)
> 
> git annotate lib/stdlib/src/erl_parse.yrl points to commit 3829e5fa
> ..:
> 
> Support nested record field access without parentheses.
> ... (omitted rest of the commit)
> 
> git show 3829e5fa
> 
> So it has to do with the introduction of nested records without
> parenthesis. I suggest to revert the patch and add something like the
> above as a SHOULD_FAIL test case to the parser tests.
> 
> (We found it on the IRC channel because someone asked why a Nitrogen
> tutorial slide had this and it worked. It was a mistake in the
> tutorial as the successor slides add the commas but things make on
> boggle and wonder).
> 
> -- 
> J.
> 
> ________________________________________________________________
> erlang-bugs (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:


More information about the erlang-bugs mailing list