[Issue 20724] New: Compiler fails to infer @safe
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Tue Apr  7 07:34:37 UTC 2020
    
    
  
https://issues.dlang.org/show_bug.cgi?id=20724
          Issue ID: 20724
           Summary: Compiler fails to infer @safe
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: andrej.mitrovich at gmail.com
-----
public void hash (T) (scope const auto ref T record) // @safe  // uncomment to
compile
    if (is(T == struct))
{
    foreach (const ref field; record.tupleof)
    {
        hash(field);
    }
}
public void hash (T) (scope const auto ref T[] records) @safe
{
    foreach (ref record; records)
        hash(record);
}
@safe void main ()
{
    struct Foo
    {
        Foo[] foo;
    }
    Foo foo;
    hash(foo);
}
-----
$ dmd test.d
$ test.d(15): Error: @safe function test.hash!(Foo).hash cannot call @system
function test.hash!(Foo).hash
$ test.d(3):        test.hash!(Foo).hash is declared here
Uncommenting '@safe' makes it compile. The safety should have been inferred.
--
    
    
More information about the Digitalmars-d-bugs
mailing list