From 94a63eef9a5da8441d17e1f5214c1823056bcf68 Mon Sep 17 00:00:00 2001 From: Andrii Riabushenko Date: Sat, 8 Dec 2018 11:35:18 +0000 Subject: [PATCH 1/3] Fix hintXDeclaredButNotUsed for enum fields marked as used --- compiler/lookups.nim | 3 ++- tests/pragmas/tused.nim | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/compiler/lookups.nim b/compiler/lookups.nim index 2fb4e52411..91d6bd7452 100644 --- a/compiler/lookups.nim +++ b/compiler/lookups.nim @@ -169,7 +169,8 @@ proc ensureNoMissingOrUnusedSymbols(c: PContext; scope: PScope) = getSymRepr(c.config, s)) inc missingImpls elif {sfUsed, sfExported} * s.flags == {}: - if s.kind notin {skForVar, skParam, skMethod, skUnknown, skGenericParam}: + if s.kind notin {skForVar, skParam, skMethod, skUnknown, skGenericParam} and + not (s.kind == skEnumField and {sfUsed, sfExported} * s.owner.flags != {}): # XXX: implicit type params are currently skTypes # maybe they can be made skGenericParam as well. if s.typ != nil and tfImplicitTypeParam notin s.typ.flags and diff --git a/tests/pragmas/tused.nim b/tests/pragmas/tused.nim index 83c62b7bbf..eb9cb08aae 100644 --- a/tests/pragmas/tused.nim +++ b/tests/pragmas/tused.nim @@ -31,5 +31,10 @@ block: implementArithOpsNew(int) echoAdd 3, 5 +type + MyEnum {.used.} = enum + Val1, Val2, Val3 + + static: echo "compile end" From 5f9234e5cbea12e01286d0789dc4ae6d4b537dbb Mon Sep 17 00:00:00 2001 From: Andrii Riabushenko Date: Sat, 8 Dec 2018 11:39:11 +0000 Subject: [PATCH 2/3] add comment, fixes #9896 --- tests/pragmas/tused.nim | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/pragmas/tused.nim b/tests/pragmas/tused.nim index eb9cb08aae..dce8541469 100644 --- a/tests/pragmas/tused.nim +++ b/tests/pragmas/tused.nim @@ -31,6 +31,7 @@ block: implementArithOpsNew(int) echoAdd 3, 5 +# issue #9896 type MyEnum {.used.} = enum Val1, Val2, Val3 From e03fb08c24b33a6e25d61da93ae07bd08c9ae648 Mon Sep 17 00:00:00 2001 From: Andrii Riabushenko Date: Sun, 9 Dec 2018 00:05:57 +0000 Subject: [PATCH 3/3] change approach --- compiler/lookups.nim | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/compiler/lookups.nim b/compiler/lookups.nim index 91d6bd7452..db03ac2e05 100644 --- a/compiler/lookups.nim +++ b/compiler/lookups.nim @@ -169,8 +169,7 @@ proc ensureNoMissingOrUnusedSymbols(c: PContext; scope: PScope) = getSymRepr(c.config, s)) inc missingImpls elif {sfUsed, sfExported} * s.flags == {}: - if s.kind notin {skForVar, skParam, skMethod, skUnknown, skGenericParam} and - not (s.kind == skEnumField and {sfUsed, sfExported} * s.owner.flags != {}): + if s.kind notin {skForVar, skParam, skMethod, skUnknown, skGenericParam, skEnumField}: # XXX: implicit type params are currently skTypes # maybe they can be made skGenericParam as well. if s.typ != nil and tfImplicitTypeParam notin s.typ.flags and