Skip to content

Commit

Permalink
Fix Issue 22686 - ICE: dmd segfaults on invalid member reference in s…
Browse files Browse the repository at this point in the history
…tatic function (#13557)
  • Loading branch information
RazvanN7 committed Jan 21, 2022
1 parent 26f5e0c commit f470805
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/dmd/expressionsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -4088,6 +4088,15 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
// Type is a "delegate to" or "pointer to" the function literal
if ((exp.fd.isNested() && exp.fd.tok == TOK.delegate_) || (exp.tok == TOK.reserved && exp.fd.treq && exp.fd.treq.ty == Tdelegate))
{
// https://issues.dlang.org/show_bug.cgi?id=22686
// if the delegate return type is an error
// abort semantic of the FuncExp and propagate
// the error
if (exp.fd.type.isTypeError())
{
e = ErrorExp.get();
goto Ldone;
}
exp.type = new TypeDelegate(exp.fd.type.isTypeFunction());
exp.type = exp.type.typeSemantic(exp.loc, sc);

Expand Down
21 changes: 21 additions & 0 deletions test/fail_compilation/test22686.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// https://issues.dlang.org/show_bug.cgi?id=22686

/*
TEST_OUTPUT:
---
fail_compilation/test22686.d(15): Error: `this` is only defined in non-static member functions, not `create`
---
*/

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

0 comments on commit f470805

Please sign in to comment.