www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - -preview=in deprecation warning

reply Jack Applegame <japplegame gmail.com> writes:
Can anyone help me get rid of this depreciation?

```d
struct Foo {
	string foo;
	string getFoo() const  safe { return foo; }
}

size_t bar(in Foo foo)  safe {
	return foo.getFoo().length;
}

void main() {
	Foo("hello").bar().writeln();
}
```
```sh
$ ldc2 -preview=in --run foo.d
foo.d(9): Deprecation: scope variable `foo` assigned to non-scope 
parameter `this` calling `getFoo`
```
```sh
$ ldc2 --version
LDC - the LLVM D compiler (1.32.1):
   based on DMD v2.102.2 and LLVM 15.0.7
```
Apr 20 2023
parent reply Dennis <dkorpel gmail.com> writes:
On Thursday, 20 April 2023 at 09:14:48 UTC, Jack Applegame wrote:
 Can anyone help me get rid of this depreciation?
Annotate `getFoo` with `return scope`: ```d struct Foo { string foo; string getFoo() return scope const safe { return foo; } }
Apr 20 2023
parent Jack Applegame <japplegame gmail.com> writes:
On Thursday, 20 April 2023 at 09:41:13 UTC, Dennis wrote:
 On Thursday, 20 April 2023 at 09:14:48 UTC, Jack Applegame 
 wrote:
 Can anyone help me get rid of this depreciation?
Annotate `getFoo` with `return scope`: ```d struct Foo { string foo; string getFoo() return scope const safe { return foo; } }
Wow. Thanks. I tried this, but rearranged the return and scope like this ```d // doesn't work string getFoo() scope return const safe { return foo; } ``` ```d // works string getFoo() return scope const safe { return foo; } ```
Apr 20 2023