Skip to content

erl_lint: Don't let maybe mark variables in scope as used - #11944

Open
robertoaloi wants to merge 1 commit into
erlang:maintfrom
robertoaloi:robertoaloi/stdlib/maybe-unused-var
Open

robertoaloi wants to merge 1 commit into
erlang:maintfrom
robertoaloi:robertoaloi/stdlib/maybe-unused-var

Conversation

@robertoaloi

Copy link
Copy Markdown
Contributor

A variable bound before a case, if, receive or try expression was not reported as unused when one of its clauses contained a maybe expression:

t(Unused, X) ->
    case X of
        a -> maybe ok end;
        _ -> b
    end.

The variable table returned for a maybe expression contained every variable of the enclosing scope, not only the variables the expression updated. icrt_export/5 therefore considered all of them reused in that clause and marked them as used. Return only the updated variables, as other expressions do.

A variable bound before a `case`, `if`, `receive` or `try` expression
was not reported as unused when one of its clauses contained a `maybe`
expression:

    t(Unused, X) ->
        case X of
            a -> maybe ok end;
            _ -> b
        end.

The variable table returned for a `maybe` expression contained every
variable of the enclosing scope, not only the variables the expression
updated. `icrt_export/5` therefore considered all of them reused in
that clause and marked them as used. Return only the updated variables,
as other expressions do.
@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

CT Test Results

    2 files    101 suites   1h 3m 19s ⏱️
2 374 tests 2 296 ✅ 78 💤 0 ❌
2 798 runs  2 715 ✅ 83 💤 0 ❌

Results for commit 75ee35c.

♻️ This comment has been updated with latest results.

To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass.

See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally.

Artifacts

// Erlang/OTP Github Action Bot

@robertoaloi
robertoaloi changed the base branch from master to maint October 23, 2026 11:24
@bjorng bjorng self-assigned this Oct 26, 2026
@bjorng bjorng added team:VM Assigned to OTP team VM testing currently being tested, tag is used by OTP internal CI labels Oct 26, 2026
meta-codesync Bot pushed a commit to WhatsApp/erlang-language-platform that referenced this pull request Oct 26, 2026
Summary:
`elp_lint` (our fork of `erl_lint`) did not report an unused variable bound before a `case`, `if`, `receive` or `try` when one of its clauses contained a `maybe` expression; this ports the upstream fix from erlang/otp#11944:

```
t(Unused, X) ->
    case X of
        a -> maybe ok end;
        _ -> b
    end.
```

- The variable table returned for `maybe` (with and without `else`) contained every variable of the enclosing scope, not only the ones the expression updated. `icrt_export/5` then treated all of them as reused in that clause and marked them as used.
- `elp_lint` now returns only the updated variables via `vtupd_unsafe/3`, as other expressions do, matching the upstream change.
- New `erlang_service` fixture `maybe_unused_var.erl` covers unused variables before `case` (with `maybe` and `maybe ... else`) and `receive`, and variables used inside `maybe` and `else`, which must not be reported.

Reviewed By: alanz

Differential Revision: D127201874

fbshipit-source-id: d8dc6866d61e85f4acb7aaa52d6777e91595ae04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team:VM Assigned to OTP team VM testing currently being tested, tag is used by OTP internal CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants