Thread overview | |||||
---|---|---|---|---|---|
|
July 24, 2019 dip1000, perhaps annotate with return, and vibe-d | ||||
---|---|---|---|---|
| ||||
Trying to get dip1000 flag in use. I have this error: Error: returning Optional(null, false).this(value) escapes a reference to parameter value, perhaps annotate with return in this function: public auto some(T)(auto ref T value) { return Optional!T(value); // <-- error on this line } And it's instantiated from here: static Optional!T fromRepresentation(Json value) { if (value == Json.undefined) { return no!T; } return some(deserializeJson!T(value)); // <-- instantiated from here } I put the qualifier "return" on the parameter to some, but did nothing. And I put it on Optional.this() as well, but I'm not sure where I'm supposed to put it. The constructor for Optional takes an auto ref T ... I'm not sure that makes sense. Does it make sense to take a constructor parameter that is copied in to the struct by auto ref if you're not calling .move on it explicitly? And as for vibe-d, I get this when compiling with dip1000: Also, vibe-d gives me this: ../../../.dub/packages/vibe-core-1.6.2/vibe-core/source/vibe/internal/traits.d(391,2): Error: static assert: "FileStream does not implement method "read" of type @safe ulong(scope ubyte[] dst, IOMode mode)" Has anyone seen that or used vibed with dip1000? |
July 24, 2019 Re: dip1000, perhaps annotate with return, and vibe-d | ||||
---|---|---|---|---|
| ||||
Posted in reply to aliak | On Wednesday, 24 July 2019 at 12:54:51 UTC, aliak wrote:
> Trying to get dip1000 flag in use. I have this error:
>
> Error: returning Optional(null, false).this(value) escapes a reference to parameter value, perhaps annotate with return
>
> in this function:
>
> public auto some(T)(auto ref T value) {
> return Optional!T(value); // <-- error on this line
> }
>
> And it's instantiated from here:
>
> static Optional!T fromRepresentation(Json value) {
> if (value == Json.undefined) {
> return no!T;
> }
> return some(deserializeJson!T(value)); // <-- instantiated from here
> }
>
> I put the qualifier "return" on the parameter to some, but did nothing. And I put it on Optional.this() as well, but I'm not sure where I'm supposed to put it.
It should go on the constructor's parameter; i.e.,
this(auto return ref T value) { /* ... */ }
Under the hood, a constructor actually returns the constructed value by reference, so the actual signature of the above constructor seen by the lifetime checker is:
ref Optional!T __ctor(auto return ref T value)
You can see this for yourself with something like `pragma(msg, typeof(Optional!T.__ctor))`.
|
July 25, 2019 Re: dip1000, perhaps annotate with return, and vibe-d | ||||
---|---|---|---|---|
| ||||
Posted in reply to Paul Backus | On Wednesday, 24 July 2019 at 16:23:48 UTC, Paul Backus wrote:
> On Wednesday, 24 July 2019 at 12:54:51 UTC, aliak wrote:
>> [...]
>
> It should go on the constructor's parameter; i.e.,
>
> this(auto return ref T value) { /* ... */ }
>
> Under the hood, a constructor actually returns the constructed value by reference, so the actual signature of the above constructor seen by the lifetime checker is:
>
> ref Optional!T __ctor(auto return ref T value)
>
> You can see this for yourself with something like `pragma(msg, typeof(Optional!T.__ctor))`.
Thanks! The under the hood stuff was good to know!
I was putting it in the right place but it seems to still have been complaining. Ah well. I guess an auto ref on a constructor doesn't really make sense anyway.
|
Copyright © 1999-2021 by the D Language Foundation