dmd/compiler/test/fail_compilation/test22298.d
Dennis 9b94878c85
Make safe error messages consistent (#20654)
Co-authored-by: Dennis Korpel <dennis@sarc.nl>
2025-01-08 13:46:38 +08:00

30 lines
621 B
D

/*
REQUIRED_ARGS: -preview=dip1000
TEST_OUTPUT:
---
fail_compilation/test22298.d(18): Error: assigning scope variable `i` to `p` with longer lifetime is not allowed in a `@safe` function
fail_compilation/test22298.d(29): Error: assigning scope variable `y` to `x` with longer lifetime is not allowed in a `@safe` function
---
*/
void g(scope void delegate(scope int*) @safe cb) @safe {
int x = 42;
cb(&x);
}
void main() @safe {
int* p;
void f(scope int* i) @safe {
p = i;
}
g(&f);
// address of x has escaped g
assert(*p == 42);
}
void f() @safe {
mixin("scope int* x;");
scope int* y;
x = y;
}