www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22686] New: ICE: dmd segfaults on invalid member reference in

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

          Issue ID: 22686
           Summary: ICE: dmd segfaults on invalid member reference in
                    static function
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: critical
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: hsteoh quickfur.ath.cx

Reduced code:
----------
struct S
{
    int[] data;
    static auto create()
    {
        auto self = &this;
        return {
            assert(data.length);
            return self;
        };
    }
}
----------

Compiler version: DMD64 D Compiler v2.098.0-430-g8041bcdec

Compiler output:
----------
test.d(6): Error: `this` is only defined in non-static member functions, not
`create`
Segmentation fault
----------

Expected behaviour: compiler should not segfault after rejecting the invalid
code that tries to look up a non-static struct member from a static function.

This code was reduced from a larger module. I've tried to reduce this code as
much as possible, but can't get farther than this. Removing the assert makes
the segfault go away. Unwrapping the delegate also makes the segfault go away.
The int[] array was reduced from an array of structs, but the array itself
can't be removed or changed to a non-array type without making the segfault go
away.

--
Jan 17 2022