Weird rule for immutable
Walter Bright
newshound2 at digitalmars.com
Sat Apr 11 09:08:34 UTC 2020
On 4/10/2020 6:45 PM, Victor Porton wrote:
> But is there any practical reason that the specification disallows the following?
>
> int[] x = [];
> {
> immutable y = cast(immutable)x;
> }
> x = [1, 2];
Because Data Flow Analysis would needed to prove there are not other mutations
to x within the lifetime of y. DFA is slow and complex, and doesn't seem worth
it for this case.
More information about the Digitalmars-d
mailing list