Skip to content

Commit 25e4c8d

Browse files
committed
Fix #21769: Segfault with static foreach on tuple struct
1 parent 0b9e7b2 commit 25e4c8d

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

compiler/src/dmd/statementsem.d

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4636,7 +4636,8 @@ public auto makeTupleForeach(Scope* sc, bool isStatic, bool isDecl, ForeachState
46364636
decls.append(Dsymbol.arraySyntaxCopy(dbody));
46374637
else
46384638
{
4639-
stmts.push(fs._body.syntaxCopy());
4639+
if (fs.body)
4640+
stmts.push(fs._body.syntaxCopy());
46404641
s = new CompoundStatement(loc, stmts);
46414642
}
46424643

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*TEST_OUTPUT:
2+
---
3+
1
4+
s
5+
---
6+
*/
7+
struct Tuple(S...)
8+
{
9+
S fields;
10+
alias fields this;
11+
}
12+
13+
void f()
14+
{
15+
enum t = Tuple!(int, string)(1, "s");
16+
17+
static foreach (a; t)
18+
pragma(msg, a);
19+
}

0 commit comments

Comments
 (0)