Weird rule for immutable

Nick Treleaven nick at geany.org
Sat Apr 11 08:51:32 UTC 2020


On Saturday, 11 April 2020 at 01:24:53 UTC, Victor Porton wrote:
> void f(ref immutable int v) { }
>
> int x = 1;
> f(x);
> x = 2; // the immutable reference does not exist at this point
>        // but the assignment is disallowed(?)

You can't pass a mutable int to a `ref immutable int` parameter. 
(Without 'ref', D will allow passing a mutable int to an 
immutable int because a copy is made).


More information about the Digitalmars-d mailing list