diff --git a/compiler/src/dmd/statementsem.d b/compiler/src/dmd/statementsem.d index b2617e44354b..9ff4549a5122 100644 --- a/compiler/src/dmd/statementsem.d +++ b/compiler/src/dmd/statementsem.d @@ -605,7 +605,7 @@ Statement statementSemanticVisit(Statement s, Scope* sc) * } finally { v1.~this(); } * where controlflow = `for` or `if` */ - private Statment expandInit(S)(S cfs) + Statment expandInit(S)(S cfs) { auto ainit = new Statements(); ainit.push(cfs._init); @@ -1642,6 +1642,11 @@ Statement statementSemanticVisit(Statement s, Scope* sc) /* https://dlang.org/spec/statement.html#IfStatement */ + if (ifs._init) + { + result = expandInit(ifs) + return; + } // check in syntax level ifs.condition = checkAssignmentAsCondition(ifs.condition, sc); diff --git a/compiler/test/runnable/controlflow_init.d b/compiler/test/runnable/controlflow_init.d new file mode 100644 index 000000000000..1624d951454d --- /dev/null +++ b/compiler/test/runnable/controlflow_init.d @@ -0,0 +1,12 @@ + + +int main() +{ + if (int a = 4; a) + { + + } + else + assert(0); + return 0; +}