DMD treats these 2 cases differently, while GDC works as expected and LDC is being fixed accordingly:
```
@safe:
int[] globalArray;
ref int[] getSliceRef() { return globalArray; }
int getLowerBound()
{
globalArray = [ 666 ];
return 0;
}
void main()
{
globalArray = [ 1 ];
auto r1 = globalArray[getLowerBound() .. $];
assert(r1 == [ 666 ]);
globalArray = [ 1 ];
auto r2 = getSliceRef()[getLowerBound() .. $];
assert(r2 == [ 1 ]); // BUG, should be [ 666 ]
}
```
Comment #1 by dfj1esp02 — 2017-05-02T16:12:19Z
I'd say the array should be loaded before evaluation of slice arguments. For example you can't resolve length before loading the array. So asserts should be assert(r1 == [ 1 ]); assert(r2 == [ 1 ]);
How does it work with function pointers?
Comment #2 by kinke — 2017-05-02T17:49:03Z
> For example you can't resolve length before loading the array.
Not sure what you mean by 'loading the array'. The base expression evaluates to a slice, a pointer+length pair, in these 2 cases either to a variable directly or a reference to it, i.e., in both cases an lvalue representing a slice in memory. Length/pointer may then be loaded independently from the slice in memory, but *when* the loads happen is clearly crucial and currently inconistent.
Comment #3 by dfj1esp02 — 2017-05-03T09:21:10Z
(In reply to kinke from comment #2)
> but *when* the loads happen is clearly crucial
That's the loading I talk about.
Comment #4 by b2.temp — 2024-05-06T08:16:47Z
As of v 2.108 DMD is consistent and always verifies that the slice is equal to `[1]`.
Maybe that now the issue could be closed with a PR introducing a test with `version()` for each compiler ?
Comment #5 by robert.schadek — 2024-12-13T18:52:06Z