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 issue 21253 - Can't compile Variant.visit!(...) with generic func… #7637

Merged
merged 1 commit into from
Oct 31, 2020

Conversation

Biotronic
Copy link
Contributor

…tion

@Biotronic Biotronic requested a review from andralex as a code owner September 17, 2020 07:29
@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @Biotronic! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Auto-close Bugzilla Severity Description
21253 normal Can't compile Variant.visit!(...) with generic function

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + phobos#7637"

@Biotronic Biotronic force-pushed the Issue-21253 branch 5 times, most recently from 08f28dc to 96b4913 Compare September 17, 2020 08:37
@Biotronic
Copy link
Contributor Author

Turns out, the tests on lines 2433-2437 probably should have referred to maybenumber all along, and were testing for the wrong thing.

@pbackus
Copy link
Contributor

pbackus commented Oct 27, 2020

The nonmatch check is a breaking change, because visit currently ignores handlers that don't match any types. Here's a unit test that passes on master but breaks with this PR:

@system unittest
{
    Algebraic!(int, string) x = 123;
    assert(__traits(compiles,
        x.visit!(
            (int n) => "got int",
            (string s) => "got string",
            (char c) => "got char"
        )
    ));
}

@myCrack
Copy link

myCrack commented Oct 28, 2020

breaking change, because visit currently ignores handlers that don't match any types.

https://dlang.org/phobos/std_variant.html#.visit:

It is statically ensured that all held types of variant are handled across all handlers.

So, behavior from the master branch must be treated as a bug.

@pbackus
Copy link
Contributor

pbackus commented Oct 28, 2020

I'm pretty sure that just means that you have to handle every type (which, indeed, is statically ensured on master), but the wording is certainly not as clear as it could be.

@dlang-bot dlang-bot merged commit 6ee10a4 into dlang:master Oct 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants