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

erl_syntax_lib: annotate maybe_match_expr and else_expr correctly #8811

Merged

Conversation

MarkoMin
Copy link
Contributor

@MarkoMin MarkoMin commented Sep 13, 2024

maybe_match_expr and else_expr were not handled properly when annotating bindings. This was causing problem with ELS and this is currently preventing me to fix the issue. The problems were both false positive and false negative diagnostics.

This will probably cause problem in ELP too, so I'll kindly ping @robertoaloi @michalmuskala to take a look at this.

I didn't provide any test for this because it seems that erl_syntax_lib is not tested.

What one can do to test this PR is to build Erlang-LS from this PR and make sure that els_diagnostics_SUITE:bound_var_in_pattern_maybe/1 testcase passes. Testcase tests for both false negatives and false positives.

What I'm not completely sure is whether:

f() ->
maybe
    X ?= foo
else
    Err -> Err
end,
X.

should return bound variable or unsafe variable diagnostic? Currently it returns bound variable, but it probably should be unsafe. I'll add that to some testcase once I know what the desired behavior is.

Copy link
Contributor

github-actions bot commented Sep 13, 2024

CT Test Results

  2 files   13 suites   4m 41s ⏱️
113 tests 111 ✅ 2 💤 0 ❌
129 runs  127 ✅ 2 💤 0 ❌

Results for commit 95b849d.

♻️ 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

@rickard-green rickard-green added the team:VM Assigned to OTP team VM label Sep 16, 2024
@MarkoMin
Copy link
Contributor Author

Currently it returns bound variable, but it probably should be unsafe. I'll add that to some testcase once I know what the desired behavior is.

I just re-check and the code already results in "unsafe in maybe" error - which I think is correct behavior.

@bjorng
Copy link
Contributor

bjorng commented Oct 31, 2024

Thanks for your pull request.

Since this is a bug fix, I think it is appropriate to base it on the maint branch. If based on master, this fix will be released in Erlang/OTP 28, which is planned to be released next spring.

Could you also add a test to the syntax_tools_SUITE? We usually add a test when a bug is fixed. As an example of writing a test case for testing annotations, there is test_named_fun_bind_ann/1, which was added by you in 2022.

While you are it, please squash the commits into one commit. It would also be nice if you can put some of the information from the description of this PR into the commit message.

@bjorng bjorng added the waiting waiting for changes/input from author label Nov 4, 2024
@MarkoMin MarkoMin closed this Nov 13, 2024
@MarkoMin MarkoMin force-pushed the erl_syntax_lib/annotate_maybe_match_correctly branch from d97f353 to c319d4b Compare November 13, 2024 03:28
@MarkoMin MarkoMin reopened this Nov 13, 2024
@MarkoMin MarkoMin changed the base branch from master to maint November 13, 2024 03:56
@bjorng bjorng added the testing currently being tested, tag is used by OTP internal CI label Nov 13, 2024
@bjorng
Copy link
Contributor

bjorng commented Nov 15, 2024

Your new test case will not actually be run unless you add its name to the end of the list of test cases in all/0. When you have done this change, please squash the commits down into one commit.

@MarkoMin MarkoMin force-pushed the erl_syntax_lib/annotate_maybe_match_correctly branch from a4f56b9 to 95b849d Compare December 16, 2024 08:59
@MarkoMin
Copy link
Contributor Author

Finally found some time for this. I think now it's correct. If I understood it correctly, no variables are bound after maybe.

I'm not completely sure whether Error variable in:

else
   Error -> Error

should be free or not? Currently is neither free nor bound. Is this correct behavior?

FWIW: I've tested this quickly over few examples with erlang_ls that previously caused errors and now it works as it should.

@bjorng bjorng added testing currently being tested, tag is used by OTP internal CI and removed testing currently being tested, tag is used by OTP internal CI waiting waiting for changes/input from author labels Dec 16, 2024
@bjorng bjorng merged commit 0129381 into erlang:maint Dec 18, 2024
24 checks passed
@bjorng
Copy link
Contributor

bjorng commented Dec 18, 2024

Thanks for your pull request.

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.

3 participants