From dd8cbf5fca7becf43b5cec07ecf7e579308e2e7a Mon Sep 17 00:00:00 2001 From: Araq Date: Fri, 17 Feb 2017 17:44:52 +0100 Subject: [PATCH] fixes #5404 --- compiler/ccgtypes.nim | 8 +++++++- tests/ccgbugs/tmangle_field.nim | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 tests/ccgbugs/tmangle_field.nim diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index e30fe5598b..29d4e23c97 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -24,7 +24,13 @@ proc isKeyword(w: PIdent): bool = proc mangleField(m: BModule; name: PIdent): string = result = mangle(name.s) - if isKeyword(name) or m.g.config.cppDefines.contains(result): + # fields are tricky to get right and thanks to generic types producing + # duplicates we can end up mangling the same field multiple times. However + # if we do so, the 'cppDefines' table might be modified in the meantime + # meaning we produce inconsistent field names (see bug #5404). + # Hence we do not check for ``m.g.config.cppDefines.contains(result)`` here + # anymore: + if isKeyword(name): result.add "_0" when false: diff --git a/tests/ccgbugs/tmangle_field.nim b/tests/ccgbugs/tmangle_field.nim new file mode 100644 index 0000000000..9e4012b8b1 --- /dev/null +++ b/tests/ccgbugs/tmangle_field.nim @@ -0,0 +1,16 @@ +discard """ +""" + +# bug #5404 + +import parseopt2 + +{.emit: """typedef struct { + int key; +} foo;""".} + +type foo* {.importc: "foo", nodecl.} = object + key* {.importc: "key".}: cint + +for kind, key, value in parseopt2.getopt(): + discard