Skip to content

Commit

Permalink
Fix Issue 21956 - Issue 21956 - ice on foreach over an AA of noreturn
Browse files Browse the repository at this point in the history
  • Loading branch information
RazvanN7 committed Jul 8, 2022
1 parent 53955b6 commit 12e60d7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/dmd/expressionsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -8900,6 +8900,16 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
if ((t1.ty != Tstruct && t1.ty != Tclass && e2x.checkValue()) ||
e2x.checkSharedAccess(sc))
return setError();

if (e2x.type.isTypeNoreturn() && !e2x.isAssertExp() && !e2x.isThrowExp() && !e2x.isCallExp())
{
auto msg = new StringExp(e2x.loc, "Accessed expression of type `noreturn`");
msg.type = Type.tstring;
e2x = new AssertExp(e2x.loc, IntegerExp.literal!0, msg);
e2x.type = Type.tnoreturn;
return setResult(e2x);

}
exp.e2 = e2x;
}

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

noreturn[noreturn] nrnr;

void gun()
{
foreach (a; nrnr){}
}

int main()
{
noreturn[] empty;
int val;
foreach(el; empty) val++;
return val;
}

0 comments on commit 12e60d7

Please sign in to comment.