[Issue 24586] New: [REG 2.108] initialization of immutable arrays with a system function marks the array as system
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Wed Jun  5 01:43:56 UTC 2024
    
    
  
https://issues.dlang.org/show_bug.cgi?id=24586
          Issue ID: 24586
           Summary: [REG 2.108] initialization of immutable arrays with a
                    system function marks the array as system
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: rejects-valid
          Severity: regression
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: schveiguy at gmail.com
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.
--
    
    
More information about the Digitalmars-d-bugs
mailing list