From 6a23452bf4f386a57bcbb4e99c8d27149fe1d10b Mon Sep 17 00:00:00 2001 From: Jasper Jenkins Date: Tue, 17 Mar 2020 02:47:27 -0700 Subject: [PATCH] fix sets of scoped imported enums (#13666) --- compiler/ccgtypes.nim | 3 ++- tests/cpp/enum.hpp | 3 +++ tests/cpp/tenum_set.nim | 9 +++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 tests/cpp/enum.hpp create mode 100644 tests/cpp/tenum_set.nim diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index 759330a3eb..22e9a52171 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -880,7 +880,8 @@ proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet): Rope = m.s[cfsTypes].add(recdesc) elif tfIncompleteStruct notin t.flags: addAbiCheck(m, t, result) of tySet: - result = $t.kind & '_' & getTypeName(m, t.lastSon, hashType t.lastSon) + # Don't use the imported name as it may be scoped: 'Foo::SomeKind' + result = $t.kind & '_' & t.lastSon.typeName & $t.lastSon.hashType m.typeCache[sig] = result if not isImportedType(t): let s = int(getSize(m.config, t)) diff --git a/tests/cpp/enum.hpp b/tests/cpp/enum.hpp new file mode 100644 index 0000000000..268999d68a --- /dev/null +++ b/tests/cpp/enum.hpp @@ -0,0 +1,3 @@ +namespace namespaced { +enum Enum { A, B, C }; +} diff --git a/tests/cpp/tenum_set.nim b/tests/cpp/tenum_set.nim new file mode 100644 index 0000000000..6afed722f4 --- /dev/null +++ b/tests/cpp/tenum_set.nim @@ -0,0 +1,9 @@ +discard """ +targets: "cpp" +output: "{A, B, C}" +""" + +type Enum {.importcpp: "namespaced::Enum", header: "enum.hpp".} = enum A, B, C + +var vals = {low(Enum) .. high(Enum)} +echo vals