>type main.d void f(T)(){} void main() { return f; } >dmd main f(T) Internal error: e2ir.c 644
Not a D2 bug. Fails even in DMD 0.165.
This is clearly invalid code.
This is happening because when return exp; is changed into exp; return;, the semantic pass never gets run on the expression. ------- PATCH: iin statement.c, around line 3464, in Statement *ReturnStatement::semantic(Scope *sc) ===== /* Replace: * return exp; * with: * exp; return; */ Statement *s = new ExpStatement(loc, exp); + s->semantic(sc); ========== CAUTION: This patch also disallows code like " void foo() { return 7; }" This shows up several bugs in Phobos and in the DMD test suite. If there's a reason why such bug-prone code should continue to be accepted, a more complicated patch will be required.
Fixed dmd 1.049 and 2.034