diff --git a/compiler/src/dmd/dsymbolsem.d b/compiler/src/dmd/dsymbolsem.d index 26e9c92d6c..0443b32441 100644 --- a/compiler/src/dmd/dsymbolsem.d +++ b/compiler/src/dmd/dsymbolsem.d @@ -2528,9 +2528,14 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor if (!em.ed.isAnonymous()) em.ed.memtype = t; } + const errors = global.startGagging(); Expression e = new IntegerExp(em.loc, 0, t); e = e.ctfeInterpret(); - + if (global.endGagging(errors)) + { + error(em.loc, "cannot generate 0 value of type `%s` for `%s`", + t.toChars(), em.toChars()); + } // save origValue for better json output em.origValue = e; diff --git a/compiler/test/fail_compilation/diag7477.d b/compiler/test/fail_compilation/diag7477.d index b82b33de94..b14a3c5df6 100644 --- a/compiler/test/fail_compilation/diag7477.d +++ b/compiler/test/fail_compilation/diag7477.d @@ -1,8 +1,8 @@ /* TEST_OUTPUT: --- -fail_compilation/diag7477.d(13): Error: integral constant must be scalar type, not `Foo` -fail_compilation/diag7477.d(20): Error: integral constant must be scalar type, not `string` +fail_compilation/diag7477.d(13): Error: cannot generate 0 value of type `Foo` for `a` +fail_compilation/diag7477.d(20): Error: cannot generate 0 value of type `string` for `a` --- */