diff --git a/compiler/src/dmd/hdrgen.d b/compiler/src/dmd/hdrgen.d index a44fb2877a95..f3c6bbb56b63 100644 --- a/compiler/src/dmd/hdrgen.d +++ b/compiler/src/dmd/hdrgen.d @@ -1858,9 +1858,9 @@ void toCBuffer(Dsymbol s, ref OutBuffer buf, ref HdrGenState hgs) if (stcToBuffer(buf, d.storage_class)) buf.writeByte(' '); buf.writestring("invariant"); - if(auto es = d.fbody.isExpStatement()) + auto es = d.fbody.isExpStatement(); + if (es && es.exp && es.exp.op == EXP.assert_) { - assert(es.exp && es.exp.op == EXP.assert_); buf.writestring(" ("); (cast(AssertExp)es.exp).e1.expressionToBuffer(buf, hgs); buf.writestring(");"); diff --git a/compiler/test/compilable/extra-files/vcg-ast.d.cg b/compiler/test/compilable/extra-files/vcg-ast.d.cg index 640cba43ed67..e6a9ca384f22 100644 --- a/compiler/test/compilable/extra-files/vcg-ast.d.cg +++ b/compiler/test/compilable/extra-files/vcg-ast.d.cg @@ -100,6 +100,12 @@ void main() values(); return 0; } +import imports.vcg_ast_import; +template imported() +{ + import imported = imports.vcg_ast_import; +} +alias myImport = vcg_ast_import; R!int { struct _R @@ -126,6 +132,21 @@ mixin _d_cmain!(); } } } +imported!() +{ + import object; + struct O + { + invariant + { + } + invariant + { + __invariant0(); + } + } + +} RTInfo!(C) { enum immutable(void)* RTInfo = null; @@ -150,4 +171,3 @@ RTInfo!(_R) enum immutable(void)* RTInfo = null; } - diff --git a/compiler/test/compilable/imports/vcg_ast_import.d b/compiler/test/compilable/imports/vcg_ast_import.d new file mode 100644 index 000000000000..a2064c0d175b --- /dev/null +++ b/compiler/test/compilable/imports/vcg_ast_import.d @@ -0,0 +1,4 @@ +struct O +{ + invariant() {} +} diff --git a/compiler/test/compilable/vcg-ast.d b/compiler/test/compilable/vcg-ast.d index 4a7b8bc33c48..9197441affea 100644 --- a/compiler/test/compilable/vcg-ast.d +++ b/compiler/test/compilable/vcg-ast.d @@ -2,6 +2,7 @@ REQUIRED_ARGS: -vcg-ast -o- PERMUTE_ARGS: OUTPUT_FILES: compilable/vcg-ast.d.cg +EXTRA_FILES: imports/vcg_ast_import.d TEST_OUTPUT_FILE: extra-files/vcg-ast.d.cg */ @@ -63,3 +64,14 @@ void main() { values!wchar_t; } + +// https://issues.dlang.org/show_bug.cgi?id=24764 + +import imports.vcg_ast_import; + +template imported() +{ + import imported = imports.vcg_ast_import; +} + +alias myImport = imported!();