dmd icon indicating copy to clipboard operation
dmd copied to clipboard

Incorrect function contract syntax segfaults the compiler.

Open jnms-me opened this issue 6 months ago • 1 comments

Mistakingly I wrote out(expr) instead of out(; expr) on a ctor. In this specific case it segfaults the compiler:

abstract class C1 {}

class C2 : C1
{
    bool member;

    this()
    out (member)
    {
    }
}

Seems to happen at src/dmd/dsymbolsem.d+2425.

jnms-me avatar May 24 '25 18:05 jnms-me

Without inheriting from C1, dmd gives:

outid.d(7): Error: constructor `outid.C2.this` `in` and `out` contracts can only appear without a body when they are virtual interface functions or abstract

The problem seems to be that fbody is null after parsing, but it gets generated, so the above error is not triggered:

    if (!funcdecl.fbody && !funcdecl.allowsContractWithoutBody())
        .error(funcdecl.loc, "%s `%s` `in` and `out` contracts can only appear without a body when they are virtual interface functions or abstract", funcdecl.kind, funcdecl.toPrettyChars);

ntrel avatar May 26 '25 13:05 ntrel