-
-
Notifications
You must be signed in to change notification settings - Fork 706
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 20850 - Can't assign enum of Tuple #7489
Conversation
|
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 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
Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + phobos#7489" |
|
I actually just envisioned that assignment to the same type would be supported. For instance, a type that alias this' itself to a |
|
If you mean this should work, it does: import std.typecons;
struct S {
alias t this;
Tuple!int t;
}
unittest {
Tuple!int a;
S s;
a = s;
}Assigning Strangely, I don't think there's a way to allow this to work: import std.typecons;
enum T1 : Tuple!(int*) { a = T1(null) }
enum T2 : Tuple!(int*) { a = T2(null) }
unittest {
T1 t1;
T2 t2;
// Allow assignment from T1 to T1:
t1 = T1.a;
// But not T2 to T1:
static assert(!__traits(compiles, t1 = T2.a));
} |
|
Well, that's not what I expected. That seems like an odd difference between enum and alias this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This workaround is OK for now. But I don't love the extra isTuple inside the static if. I get why you need to do it, it's unfortunate we can't figure out how to make the enum work with the existing operator overloads.
areCompatibleTupleshas to checkOriginalTypeto account for enums. Also, swap is confused, so we're not using that for these assignments. Casting toOriginalTypewould work, but breaks@safe.