Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add return to ctor parameters #92

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions source/mir/algebraic.d
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ Compatible with BetterC mode.
alias Nullable(T...) = Variant!(typeof(null), T);

/// ditto
Nullable!T nullable(T)(T t)
Nullable!T nullable(T)(return T t)
{
import core.lifetime: forward;
return Nullable!T(forward!t);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated, I know, but forward doesn't really make sense here, for a non-auto ref param. It always boils down to a move for non-ref params.

Expand Down Expand Up @@ -2034,7 +2034,7 @@ struct Algebraic(T__...)
private alias _ReflectionTypes = AllowedTypes[is(AllowedTypes[0] == typeof(null)) .. $];

static if (_ReflectionTypes.length)
this(this This, Args...)(auto ref Args args)
this(this This, Args...)(auto ref return Args args)
if (Args.length && (Args.length > 1 || !isLikeVariant!(Args[0])))
{
import std.traits: CopyTypeQualifiers;
Expand Down Expand Up @@ -2077,17 +2077,17 @@ struct Algebraic(T__...)
else
static if (allSatisfy!(ApplyRight!(templateOr!(hasField, isProperty), member), _ReflectionTypes))
{
mixin(`auto ref ` ~ member ~q{(this This, Args...)(auto ref Args args) @property { static if (args.length) { import core.lifetime: forward; return this.getMember!member = forward!args; } else return this.getMember!member; }});
mixin(`auto ref ` ~ member ~q{(this This, Args...)(auto ref return Args args) @property return { static if (args.length) { import core.lifetime: forward; return this.getMember!member = forward!args; } else return this.getMember!member; }});
}
static if (allSatisfy!(ApplyRight!(templateNot!(templateOr!(hasField, isProperty)), member), _ReflectionTypes))
{
mixin(`template ` ~ member ~`(TArgs...) { auto ref ` ~ member ~q{(this This, Args...)(auto ref Args args) { static if (args.length) { import core.lifetime: forward; return this.getMember!(member, TArgs)(forward!args); } else return this.getMember!(member, TArgs); }} ~ `}`);
mixin(`template ` ~ member ~`(TArgs...) { auto ref ` ~ member ~q{(this This, Args...)(auto ref return Args args) return { static if (args.length) { import core.lifetime: forward; return this.getMember!(member, TArgs)(forward!args); } else return this.getMember!(member, TArgs); }} ~ `}`);
}
}
}

///
ref opAssign(RhsTypes...)(Algebraic!RhsTypes rhs) return @trusted
ref opAssign(RhsTypes...)(return Algebraic!RhsTypes rhs) return @trusted
if (allSatisfy!(Contains!AllowedTypes, Algebraic!RhsTypes.AllowedTypes) && !is(Algebraic == Algebraic!RhsTypes))
{
import core.lifetime: forward;
Expand Down Expand Up @@ -2159,7 +2159,7 @@ struct Algebraic(T__...)
{
///
static if (isCopyable!(const T) || is(Unqual!T == T))
this(T value)
this(return T value)
{
import core.lifetime: forward;
static if (is(T == typeof(null)))
Expand Down Expand Up @@ -2239,7 +2239,7 @@ struct Algebraic(T__...)

static if (__traits(compiles, (ref T a, ref T b) { moveEmplace(a, b); }))
///
ref opAssign(T rhs) return @trusted
ref opAssign(return T rhs) return @trusted
{
static foreach (T; MetaInfo__)
__traits(getMember, this, T.tag) = T.Type.init;
Expand Down Expand Up @@ -4142,6 +4142,25 @@ unittest
static assert(is(typeof(r) == Variant!(long, string)));
}

version(mir_core_test)
@safe unittest
{
// dip1000 memory corruption test
// https://issues.dlang.org/show_bug.cgi?id=24242
Variant!(void, long[]) gen() @safe {
Variant!(void, long[]) v = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
return v;
}

auto v = gen();
v.match!(
() { assert(false); },
(val) {
assert(val == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
}
);
}

package auto trustedAllAttr(T)(scope T t) @trusted
{
import std.traits;
Expand Down
Loading