From 16ec7b681bf314b42a685428ce91d3234459405f Mon Sep 17 00:00:00 2001 From: Walter Bright Date: Tue, 16 May 2023 00:07:19 -0700 Subject: [PATCH] fix Issue 23913 - __traits(getMember) fails for some C symbols (#15234) --- compiler/src/dmd/expressionsem.d | 12 +++++++++++- compiler/test/compilable/imports/library.c | 5 +++++ compiler/test/compilable/test23913.d | 7 +++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 compiler/test/compilable/imports/library.c create mode 100644 compiler/test/compilable/test23913.d diff --git a/compiler/src/dmd/expressionsem.d b/compiler/src/dmd/expressionsem.d index 987c42cdc7..bdad3a2726 100644 --- a/compiler/src/dmd/expressionsem.d +++ b/compiler/src/dmd/expressionsem.d @@ -13175,10 +13175,20 @@ Expression dotIdSemanticProp(DotIdExp exp, Scope* sc, bool gag) Expression se = new ScopeExp(exp.loc, imp.pkg); return se.expressionSemantic(sc); } + + if (auto attr = s.isAttribDeclaration()) + { + if (auto sm = ie.sds.search(exp.loc, exp.ident, flags)) + { + auto es = new DsymbolExp(exp.loc, sm); + return es; + } + } + // BUG: handle other cases like in IdentifierExp::semantic() debug { - printf("s = '%s', kind = '%s'\n", s.toChars(), s.kind()); + printf("s = %p '%s', kind = '%s'\n", s, s.toChars(), s.kind()); } assert(0); } diff --git a/compiler/test/compilable/imports/library.c b/compiler/test/compilable/imports/library.c new file mode 100644 index 0000000000..4951e46557 --- /dev/null +++ b/compiler/test/compilable/imports/library.c @@ -0,0 +1,5 @@ +typedef enum SomeEnum +{ + foo = 0, + bar = -10000, +} SomeEnum; diff --git a/compiler/test/compilable/test23913.d b/compiler/test/compilable/test23913.d new file mode 100644 index 0000000000..e39c6dec31 --- /dev/null +++ b/compiler/test/compilable/test23913.d @@ -0,0 +1,7 @@ +// EXTRA_FILES: imports/library.c + +// https://issues.dlang.org/show_bug.cgi?id=23913 + +import imports.library; + +alias x = __traits(getMember, imports.library, "SomeEnum");