Skip to content

Commit 148ce8b

Browse files
authored
Merge pull request #3 from KostiantynTokar/patch-1
Allow @System pred
2 parents 07dfa97 + e7f49dc commit 148ce8b

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

source/expected.d

+9-8
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,6 @@ version (unittest) {
227227
import std.exception : assertThrown, collectExceptionMsg;
228228
}
229229

230-
@safe:
231-
232230
/++
233231
`Expected!(T, E)` is a type that represents either success or failure.
234232
@@ -402,10 +400,13 @@ struct Expected(T, E = string, Hook = Abort)
402400
// Done, deallocate
403401
static if (isChecked!Hook) bool ch = checked;
404402
destroy(storage.payload);
405-
static if (enableGCScan) pureGcRemoveRange(&storage.payload);
403+
static if (enableGCScan) () @trusted { pureGcRemoveRange(&storage.payload); } ();
406404

407-
pureFree(storage);
408-
storage = null;
405+
() @trusted
406+
{
407+
pureFree(storage);
408+
storage = null;
409+
}();
409410

410411
static if (isChecked!Hook) { if (!ch) onUnchecked(); }
411412
}
@@ -1112,7 +1113,7 @@ static:
11121113
}
11131114

11141115
/// Handler for case when empty error is accessed.
1115-
void onAccessEmptyError() nothrow @nogc
1116+
void onAccessEmptyError() nothrow @nogc @safe
11161117
{
11171118
assert(0, "Error not set");
11181119
}
@@ -1163,7 +1164,7 @@ version (D_Exceptions)
11631164
}
11641165

11651166
/// Handler for case when empty error is accessed.
1166-
void onAccessEmptyError()
1167+
void onAccessEmptyError() @safe
11671168
{
11681169
throw new Unexpected!string("Can't access error on expected value");
11691170
}
@@ -1243,7 +1244,7 @@ static:
12431244
/// Enabled reference counted payload
12441245
immutable bool enableRefCountedPayload = true;
12451246

1246-
void onUnchecked() pure nothrow @nogc { assert(0, "result unchecked"); }
1247+
void onUnchecked() pure nothrow @nogc @safe { assert(0, "result unchecked"); }
12471248
}
12481249

12491250
///

tests/expected.d

+8
Original file line numberDiff line numberDiff line change
@@ -453,3 +453,11 @@ unittest
453453
assert(empty.value == int.init);
454454
assert(empty.error is null);
455455
}
456+
457+
@("system pred")
458+
@system unittest
459+
{
460+
auto foo() @system { return ok; }
461+
static assert(__traits(compiles, ok.andThen!foo));
462+
static assert(__traits(compiles, err("foo").orElse!foo));
463+
}

0 commit comments

Comments
 (0)