WhatsApp / erlfmt

An automated code formatter for Erlang
Apache License 2.0
412 stars 52 forks source link

Warning: expression updates a literal on upcoming OTP 27 #353

Closed maennchen closed 8 months ago

maennchen commented 8 months ago

https://github.com/erlef/oidcc/actions/runs/7978117370/job/21787920914?pr=337

===> Compiling erlfmt
  _build/default/plugins/erlfmt/src/erlfmt_parse.yrl:98:71: Warning: expression updates a literal
  _build/default/plugins/erlfmt/src/erlfmt_parse.yrl:153:39: Warning: expression updates a literal
  _build/default/plugins/erlfmt/src/erlfmt_parse.yrl:155:39: Warning: expression updates a literal
  _build/default/plugins/erlfmt/src/erlfmt_parse.yrl:379:37: Warning: expression updates a literal
  _build/default/plugins/erlfmt/src/erlfmt_parse.yrl:382:37: Warning: expression updates a literal
  _build/default/plugins/erlfmt/src/erlfmt_parse.yrl:526:37: Warning: expression updates a literal
  _build/default/plugins/erlfmt/src/erlfmt_parse.yrl:529:37: Warning: expression updates a literal
  _build/default/plugins/erlfmt/src/erlfmt_parse.yrl:539:37: Warning: expression updates a literal
  _build/default/plugins/erlfmt/src/erlfmt_parse.yrl:542:37: Warning: expression updates a literal

https://github.com/WhatsApp/erlfmt/blob/732d4438a2c246b8bcadabce52aed545ab2ac14a/src/erlfmt_parse.yrl#L98

It seems like the following is no longer allowed:

expr()#{property => value}

The code therefore will have to use maps:put/3 or maps:merge/2 instead.

I'd be happy to provide a PR for that change.

michalmuskala commented 8 months ago

Yes, a PR would definitely be welcome. Either maps:put should work, alternative could be to try and redefine the macro as:

-define(range_anno(Tok1, Tok2), begin #{
    location => map_get(location, ?anno(Tok1)),
    end_location => map_get(end_location, ?anno(Tok2))
} end).

I wonder if this might be enough to "fool" the compiler into not emitting a warning

maennchen commented 8 months ago

@michalmuskala Yes, the begin ... end trick works. :+1: