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 22617 - CTFE rejects modification of copied static array #13575
base: stable
Are you sure you want to change the base?
Conversation
Hmm bot seems to be down, cc @CyberShadow . |
Race condition in GitHub API. |
Thanks for your pull request and interest in making D better, @RazvanN7! 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 "stable + dmd#13575" |
// If it's immutable and contains indirections, we don't need to dup it | ||
result = e; |
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.
That doesn't seem right. The following example still fails with this patch:
int countWins(const uint*[2] arr)
{
const(uint)*[2] copy = arr;
copy[0] = null;
return 0;
}
enum force = countWins([null, null]);
@RazvanN7 coming back to this soon? |
When passing
[4, 8]
tocountWins
the interpreter thinks that ifthe parameter is constant, then there is no need to create a copy
for CTFE, however, this is true only if the variable never gets modified.
In this case, the
arr
is correctly assigned to a mutable static array, butsince the interpreter thinks that the original array literal will never get
modifier it simply initializes copy to a slice of it. Hence the error.
This patch fixes the issue by copying the initial array literal on the ctfe stack.
The copy is elided only if the array element type contains indirections.