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

Fix partial record matching in map generator #7878

Merged

Conversation

bjorng
Copy link
Contributor

@bjorng bjorng commented Nov 17, 2023

When attempting to match part of a record in the key of a map generator, the entire record would be matched.

Example:

-module(t).
-export([test/0]).
-record(r, {a,b}).

f(Map) ->
    [V || #r{a=N} := V <- Map, is_integer(N)].

test() ->
    f(#{#r{a=1} => 1, #r{a=2,b=42} => 2}).

It would be expected that t:test() would return [1,2], but it returned [1] because the entire record was matched, instead of just field a. Therefore, only the first record #r{a=1,b=undefined} would match.

Fixes #7875

When attempting to match part of a record in the key of a map
generator, the entire record would be matched.

Example:

    -module(t).
    -export([test/0]).
    -record(r, {a,b}).

    f(Map) ->
        [V || #r{a=N} := V <- Map, is_integer(N)].

    test() ->
        f(#{#r{a=1} => 1, #r{a=2,b=42} => 2}).

It would be expected that `t:test()` would return `[1,2]`, but it
returned `[1]` because the entire record was matched, instead of just
field `a`. Therefore, only the first record `#r{a=1,b=undefined}`
would match.

Fixes erlang#7875
@bjorng bjorng added team:VM Assigned to OTP team VM fix labels Nov 17, 2023
@bjorng bjorng requested a review from jhogberg November 17, 2023 08:37
@bjorng bjorng self-assigned this Nov 17, 2023
@bjorng bjorng added the testing currently being tested, tag is used by OTP internal CI label Nov 17, 2023
@bjorng bjorng force-pushed the bjorn/compiler/fix-mc-record-bug/GH-7875/OTP-18866 branch 2 times, most recently from bd7f745 to 3de9ae0 Compare November 22, 2023 07:06
Copy link
Contributor

CT Test Results

Tests are running... https://github.com/erlang/otp/actions/runs/6953984493

Results for commit 3de9ae0

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

  • No CT logs found
  • No HTML docs found
  • No Windows Installer found

// Erlang/OTP Github Action Bot

@bjorng bjorng merged commit 5682f06 into erlang:maint Nov 22, 2023
44 of 45 checks passed
@bjorng bjorng deleted the bjorn/compiler/fix-mc-record-bug/GH-7875/OTP-18866 branch March 1, 2024 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix 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.

record matches do not work in KeyPattern of a map generator in a comprehension
2 participants