Skip to content

Map comprehensions not annotated by erl_syntax_lib:annotate_bindings/2 #10119

@hanssv

Description

@hanssv

Describe the bug
erl_syntax_lib:annotate_bindings is missing code to handle map comprehensions. More specifically there is a case for map_comp missing in vann/2.

To Reproduce
To manifest, use the following module:

-module(foo).

-export([test/1]).

test(String) ->
  {ok, Tokens, _} = erl_scan:string(String),
  {ok, [Expr]} = erl_parse:parse_exprs(Tokens),
  erl_syntax:get_ann(erl_syntax_lib:annotate_bindings(Expr, [])).

Then test its behavior on a simple List comprehension, and compare to the similar Map comprehension:

19> foo:test("[ {X, Y} || {X, Y} <- Pairs ].", ['Pairs']).
[{env,['Pairs']},{bound,[]},{free,['Pairs']}]
20> foo:test("#{ X => Y || {X, Y} <- Pairs }.", ['Pairs']).
[{env,['Pairs']},{bound,['X','Y']},{free,['Pairs','X','Y']}]

Expected behavior
The expected result would be that you get the same set of Bound and Free variables in both cases.

Affected versions
A quick look in Git seems to suggest there has never been any code handling map_comp so all versions since map comprehensions were introduced are likely affected. Tested on OTP27 and OTP28.

Metadata

Metadata

Assignees

Labels

bugIssue is reported as a bugteam:VMAssigned to OTP team VM

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions