diff --git a/compiler/src/dmd/traits.d b/compiler/src/dmd/traits.d index 21ec3ab0e189..28f459916b97 100644 --- a/compiler/src/dmd/traits.d +++ b/compiler/src/dmd/traits.d @@ -1909,7 +1909,7 @@ Expression semanticTraits(TraitsExp e, Scope* sc) StringExp se = ex ? ex.ctfeInterpret().toStringExp() : null; if (!ex || !se || se.len == 0) { - e.error("string expected as argument of __traits `%s` instead of `%s`", e.ident.toChars(), ex.toChars()); + e.error("string expected as argument of __traits `%s` instead of `%s`", e.ident.toChars(), (*e.args)[0].toChars()); return ErrorExp.get(); } se = se.toUTF8(sc); diff --git a/compiler/test/fail_compilation/test24065.d b/compiler/test/fail_compilation/test24065.d new file mode 100644 index 000000000000..9e4ebbf4d163 --- /dev/null +++ b/compiler/test/fail_compilation/test24065.d @@ -0,0 +1,18 @@ +// https://issues.dlang.org/show_bug.cgi?id=24065 + +/* +TEST_OUTPUT: +--- +fail_compilation/test24065.d(12): Error: string expected as argument of __traits `getTargetInfo` instead of `int` +fail_compilation/test24065.d(15): Error: string expected as argument of __traits `getTargetInfo` instead of `foo` +fail_compilation/test24065.d(18): Error: string expected as argument of __traits `getTargetInfo` instead of `e` +--- +*/ + +auto s1 = __traits(getTargetInfo, int); + +void foo() {} +auto s2 = __traits(getTargetInfo, foo); + +enum e; +auto s3 = __traits(getTargetInfo, e);