Skip to content

Comments

Fix Bugzilla Issue 24818 Sumtype with single-type wastes space#10642

Merged
LightBender merged 3 commits intodlang:masterfrom
Inkrementator:sumtype_singletype
Feb 19, 2025
Merged

Fix Bugzilla Issue 24818 Sumtype with single-type wastes space#10642
LightBender merged 3 commits intodlang:masterfrom
Inkrementator:sumtype_singletype

Conversation

@Inkrementator
Copy link
Contributor

Github issue #10563

I tried doing this with a template mixin that takes the new tag as an alias parameter to avoid having to deplicate the static check all over the place, but that gave me deprecation warnings about assigning a variable to itself and also failed the unittest in line 936 where one postblit destructor didn't execute correctly ...

@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @Inkrementator! 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
24818 normal Tag of a single-type SumType wastes space

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#10642"

@dlang-bot dlang-bot added the Bug Fix Use *Severity:Bug Fix* instead. label Feb 18, 2025
Copy link
Contributor

@pbackus pbackus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rewrite this to use getter and setter functions for tag, so that we don't have to add checks for Types.length > 1 in a bunch of different places.

@Inkrementator
Copy link
Contributor Author

Inkrementator commented Feb 18, 2025

Please rewrite this to use getter and setter functions for tag, so that we don't have to add checks for Types.length > 1 in a bunch of different places.

Some constructors are immutable, const and inout, which will not allow calling other functions that mutate the object (as far as I know).

I can do it for all other constructors if you prefer it.

I tried this first:

mixin template setTag(alias newTag)
{
    auto _ = (this.tag = newTag);
}

But this caused some unit tests to fail. I might eventually create a bug report for it, but I don't understand enough yet to isolate the error.

@Inkrementator
Copy link
Contributor Author

https://github.com/Inkrementator/phobos/tree/sumtype_showerror

see this branch std/sumtype.d line 510 to see how this would fail with template mixin

@pbackus
Copy link
Contributor

pbackus commented Feb 19, 2025

Some constructors are immutable, const and inout, which will not allow calling other functions that mutate the object (as far as I know).

I guess there's no better way to do it, then. Oh well.

@LightBender LightBender merged commit f52a44d into dlang:master Feb 19, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Fix Use *Severity:Bug Fix* instead.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants