Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EPP Dodger does not respect features #7266

Open
robertoaloi opened this issue May 19, 2023 · 0 comments
Open

EPP Dodger does not respect features #7266

robertoaloi opened this issue May 19, 2023 · 0 comments
Assignees
Labels
bug Issue is reported as a bug team:VM Assigned to OTP team VM

Comments

@robertoaloi
Copy link
Contributor

robertoaloi commented May 19, 2023

Describe the bug
This is a follow up from #7175, which was partially fixed by #7176.

To Reproduce
Given the following example module (extracted from the OTP 26 highlights post):

-module(t).
-feature(maybe_expr, enable).

-export([listen_port/2]).
listen_port(Port, Options) ->
    maybe
        {ok, ListenSocket} ?= inet_tcp:listen(Port, Options),
        {ok, Address} ?= inet:sockname(ListenSocket),
        {ok, {ListenSocket, Address}}
    end.

The following crashes:

$ erl -enable-feature maybe_expr
> edoc:get_doc("t.erl").
t.erl: at line 7: syntax error before: '{'
t.erl: If the error is caused by too exotic macro
t.erl: definitions or uses of macros, adding option
t.erl: {preprocess, true} can help. See also edoc(3).
** exception exit: error
     in function  edoc:'-check_forms/3-fun-0-'/3 (edoc.erl, line 771)
     in call from lists:foreach_1/2 (lists.erl, line 1686)
     in call from edoc:read_source/2 (edoc.erl, line 640)
     in call from edoc_extract:source/3 (edoc_extract.erl, line 60)

Expected behavior
The function call succeeds.

Affected versions

  • OTP 26.0

Additional context
The root cause is in the epp_dodger module, where the io:scan_erl_form/4 function is invoked with an incorrect reserved_word_fun which does not take into account the feature macros, which are currently discarded by the dodger.

A possible solution could be to introduce some state and update the features accordingly, similarly to how the update_feature/4 function works in the epp module. This could be tricky to do in a backward-compatible way, since most of the epp_dodger parsing functions are exported.

Alternatives could be:

  • Treat all potential keywords as keywords (would break the opposite case, where the atoms maybe and else
  • Use the process dictionary
@robertoaloi robertoaloi added the bug Issue is reported as a bug label May 19, 2023
@rickard-green rickard-green added team:PS Assigned to OTP team PS team:VM Assigned to OTP team VM and removed team:PS Assigned to OTP team PS labels May 22, 2023
facebook-github-bot pushed a commit to facebook/buck2-prelude that referenced this issue May 8, 2024
Summary: In OTP 26, [EDoc is broken](erlang/otp#7266) in presence of the `maybe` operator. This is (partially) fixed in OTP 27. Backport the OTP 27 dodger, so that EDoc can be built for OTP 26 modules.

Reviewed By: TheGeorge

Differential Revision: D57099852

fbshipit-source-id: 9e8935411d2e41c20afc12a4ac11f2706356e86b
facebook-github-bot pushed a commit to facebook/buck2 that referenced this issue May 8, 2024
Summary: In OTP 26, [EDoc is broken](erlang/otp#7266) in presence of the `maybe` operator. This is (partially) fixed in OTP 27. Backport the OTP 27 dodger, so that EDoc can be built for OTP 26 modules.

Reviewed By: TheGeorge

Differential Revision: D57099852

fbshipit-source-id: 9e8935411d2e41c20afc12a4ac11f2706356e86b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue is reported as a bug team:VM Assigned to OTP team VM
Projects
None yet
Development

No branches or pull requests

4 participants