Skip to content

Commit 479ad16

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

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

compiler/src/dmd/statementsem.d

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4636,7 +4636,13 @@ 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());
4641+
else
4642+
{
4643+
auto a = new Statements();
4644+
stmts.push(new CompoundStatement(Loc.initial, a));
4645+
}
46404646
s = new CompoundStatement(loc, stmts);
46414647
}
46424648

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)