Fix Issue 22107 - [scope][dip1000] Can't .dup an array of structs wit…#3509
Conversation
…h impure copy constructor
|
Thanks for your pull request, @CyberShadow! 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 + druntime#3509" |
|
CC @dkorpel |
|
I thought Is |
I didn't see that ... but, I can reproduce the issue even with DMD
Sorry, not sure how to test this. |
Actually, since the array is @safe:
struct S
{
int x;
int* y;
this(ref S old)
{
y = &old.x;
}
}
void main()
{
S[] oldArr = new S[1];
S[] newArr = oldArr[].dup;
assert(newArr[0].y == &oldArr[0].x); // allowed since it's on the heap
S[1] oldArr1; // on the stack
S[] newArr1 = oldArr1[].dup; // now it's not allowed
}This is horrible code, but the first case is technically valid. |
|
Well, I don't know what's going on here, then. Especially considering that the "fix" is in the CTFE helper, and none of this pertains CTFE. |
And now it is allowed with the changes in this PR, which I understand is incorrect. But then why wasn't this flagged as an error somewhere else? |
The |
I think the fact that it didn't compile is completely accidental: it didn't compile for the same reason the correct case in this PR's unittest didn't compile. My copy constructor example is actually invalid, you're not allowed to assign a pointer to a |
|
I just noticed that this is also needed to make druntime unittests compile with dlang/dmd#12010. |
…h impure copy constructor