Bug 24586 – [REG 2.108] initialization of immutable arrays with a system function marks the array as system

Status
NEW
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2024-06-05T01:43:56Z
Last change time
2024-12-13T19:35:35Z
Keywords
rejects-valid
Assigned to
No Owner
Creator
Steven Schveighoffer
Moved to GitHub: dmd#20464 →

Comments

Comment #0 by schveiguy — 2024-06-05T01:43:56Z
In 2.108, I started receiving deprecation messages about system variables. This bizarrely occurs on explicitly typed arrays initialized from unmarked CTFE functions, and not on inferred ones. ```d int[] arr() { return [1, 2, 3]; } static immutable x = arr(); static immutable int[] x2 = [1, 2, 3]; static immutable int[] x3 = arr(); void main() @safe { int v; v = x[0]; // ok v = x2[0]; // ok v = x3[0]; // deprecation } ``` The deprecation message is: ``` Deprecation: cannot access `@system` variable `x3` in @safe code ``` Marking `arr` as `@safe` fixes the problem. Using the preview switch indeed treats this as an error, so marking as rejects-valid. This does not happen for 2.107 and earlier, so this is a regression.
Comment #1 by robert.schadek — 2024-12-13T19:35:35Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20464 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB