[Issue 19873] unittest should be by default @system even with -preview=dip1000

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Mar 12 08:40:17 UTC 2020


https://issues.dlang.org/show_bug.cgi?id=19873

Walter Bright <bugzilla at digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |WONTFIX

--- Comment #5 from Walter Bright <bugzilla at digitalmars.com> ---
Here's what's happening:

------- reduced test case ----------
void test() {
    int i;
    int* p = &i; // <= `scope` is inferred for `p`
    int*[]  slicep = [p];
}
----------------------

If it is declared:

    scope int*p = &i;

the error will occur regardless of the application of @system. Looking at the
code in escape.d checkAssignEscape():

------------
// Try to infer 'scope' for va if in a function not marked @system
bool inferScope = false;
if (va && sc.func && sc.func.type && sc.func.type.ty == Tfunction)
    inferScope = (cast(TypeFunction)sc.func.type).trust != TRUST.system;
------------
https://github.com/dlang/dmd/blob/master/src/dmd/escape.d#L578

and there it is. It is deliberate. What's going on is there are actually 4
trust levels - system, trusted, safe, and default_. The fourth state default_
is necessary for functions that will have their attributes inferred. I went a
little further here to assume a bit more @safety in default_ functions unless
the user specifically marked it as @system.

As you know, I'd like to see @safe as the default. While this issue is a bug,
it's in the direction we need to go anyway so it shouldn't be "fixed".

--


More information about the Digitalmars-d-bugs mailing list