Why use a DFA instead of DIP1000?
Richard (Rikki) Andrew Cattermole
richard at cattermole.co.nz
Sat Sep 13 15:43:27 UTC 2025
On 14/09/2025 1:06 AM, kdevel wrote:
> On Saturday, 13 September 2025 at 11:08:29 UTC, IchorDev wrote:
>> [...]
>>> What about "release" mode? And what about that code:
>>>
>>> ```d
>>> void main ()
>>> {
>>> assert (0);
>>>
>>> string s = "x";
>>> s [0] = 'y';
>>> }
>>> ```
>>
>> The program has entered an invalid state and the behaviour of the
>> continuing execution of the program is undefined.
>
> Please note that the program is not run but just compiled.
>
>> [...]
>>> Is "Error: cannot modify `immutable` expression `s[0]`" a false
>>> positive, too?
>>
>> It's not a 'false positive' because it's not related to DIP1000's
>> stack escape rules at all.
>
> I thought that the intent of the original code
>
> ```d
> int* ptr;
>
> void func(bool b, scope int* p) @safe {
> assert(!b);
>
> if (b) {
> ptr = p; // Error: scope variable `p` assigned to global variable
> `ptr`
> }
> }
> ```
>
> was to show that there is some code-block
>
> ```d
> ptr = p; // Error: scope variable `p` assigned to global variable
> `ptr`
> ```
>
> which is never executed regardless of the value of `b`.
Half right.
There is a code block that will never be executed, it is because of
variable b's state is known to prevent that code block from execution.
More information about the Digitalmars-d
mailing list