How to replicate an Error: scope variable `old` assigned to `ref` variable `ctx` with longer lifetime?

matheus matheus at gmail.com
Tue May 13 12:22:44 UTC 2025


On Tuesday, 13 May 2025 at 12:08:09 UTC, Dennis wrote:
> On Tuesday, 13 May 2025 at 11:55:21 UTC, matheus wrote:
>> Unfortunately adding the pointer gives me another error:
>
> I added @safe: and replaced `const` with `auto` because casting 
> away const isn't safe. This should do it:
>
> ...

Indeed it worked, but I scratched my head because I wrote almost 
the same code to test (with auto) and it wouldn't give me an 
error, and if you see my first post I wrote:

"@safe" without ":" at the beginning. While adding ":" finally 
did it:

onlineapp.d(10): Error: scope variable `old` assigned to `ref` 
variable `ctx` with longer lifetime

Maybe the compiler it should give an warning in that @safe 
without ":" when marking all the file?

Anyway thanks for your help,

Matheus.


More information about the Digitalmars-d-learn mailing list