Skip to content

Commit 8f0d587

Browse files
committed
Merge pull request #3688 from 9rnsr/fix12970
Issue 12970 - Enclosing @System attribute is precedence than postfix @safe
2 parents a6a2682 + 8ffe47a commit 8f0d587

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/func.c

+2
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,8 @@ void FuncDeclaration::semantic(Scope *sc)
470470
if (tf->isnogc) sc->stc |= STCnogc;
471471
if (tf->isproperty) sc->stc |= STCproperty;
472472
if (tf->purity == PUREfwdref) sc->stc |= STCpure;
473+
if (tf->trust != TRUSTdefault)
474+
sc->stc &= ~(STCsafe | STCsystem | STCtrusted);
473475
if (tf->trust == TRUSTsafe) sc->stc |= STCsafe;
474476
if (tf->trust == TRUSTsystem) sc->stc |= STCsystem;
475477
if (tf->trust == TRUSTtrusted) sc->stc |= STCtrusted;

test/compilable/testInference.d

+31
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,37 @@ alias FP12704 = typeof(function() { foo12704(); });
504504
static assert(is(FP12704 == void function() @system));
505505

506506
/***************************************************/
507+
// 12970
508+
509+
@system { @safe void f12970a() {} }
510+
@system { void f12970b() @safe {} }
511+
static assert(is(typeof(&f12970a) == void function() @safe));
512+
static assert(is(typeof(&f12970b) == void function() @safe));
513+
514+
@system { @trusted void f12970c() {} }
515+
@system { void f12970d() @trusted {} }
516+
static assert(is(typeof(&f12970c) == void function() @trusted));
517+
static assert(is(typeof(&f12970d) == void function() @trusted));
518+
519+
@safe { @system void f12970e() {} }
520+
@safe { void f12970f() @system {} }
521+
static assert(is(typeof(&f12970e) == void function() @system));
522+
static assert(is(typeof(&f12970f) == void function() @system));
523+
524+
@safe { @trusted void f12970g() {} }
525+
@safe { void f12970h() @trusted {} }
526+
static assert(is(typeof(&f12970g) == void function() @trusted));
527+
static assert(is(typeof(&f12970h) == void function() @trusted));
528+
529+
@trusted { @safe void f12970i() {} }
530+
@trusted { void f12970j() @safe {} }
531+
static assert(is(typeof(&f12970i) == void function() @safe));
532+
static assert(is(typeof(&f12970j) == void function() @safe));
533+
534+
@trusted { @system void f12970k() {} }
535+
@trusted { void f12970l() @system {} }
536+
static assert(is(typeof(&f12970k) == void function() @system));
537+
static assert(is(typeof(&f12970l) == void function() @system));
507538

508539
// Add more tests regarding inferences later.
509540

0 commit comments

Comments
 (0)