dmd/compiler/test/fail_compilation/test18644.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

23 lines
730 B
D

/* REQUIRED_ARGS: -preview=dip1000
TEST_OUTPUT:
---
fail_compilation/test18644.d(15): Error: escaping a `scope` value returned from nested function `foo` into allocated memory is not allowed in a `@safe` function
fail_compilation/test18644.d(16): Error: escaping local variable through nested function `foo` is not allowed in a `@safe` function
fail_compilation/test18644.d(22): Error: escaping local variable through nested function `foo` is not allowed in a `@safe` function
---
*/
// https://issues.dlang.org/show_bug.cgi?id=18644
@safe int* test1() {
int i;
int* foo() { return &i; }
int*[] b = [foo()];
return foo();
}
@safe ref int test2() {
int i;
ref int foo() { return i; }
return foo();
}