From 72423fa56068d2bad5f8f38f85ac7e68f942115f Mon Sep 17 00:00:00 2001 From: jjv360 Date: Sat, 24 Dec 2022 15:50:59 +0200 Subject: [PATCH] Fix quoted method names not getting exported (ie setters) --- ExternalClassTest.nim | 4 ++++ classes.nimble | 2 +- src/classes.nim | 8 ++++---- test.nim | 4 ++++ 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/ExternalClassTest.nim b/ExternalClassTest.nim index f69e90d..b0b1c30 100644 --- a/ExternalClassTest.nim +++ b/ExternalClassTest.nim @@ -8,5 +8,9 @@ class ExternalClass: method testStatic {.static.} = discard + var testCustomSetterValue = 6 + method testCustomSetter(): int = this.testCustomSetterValue + method `testCustomSetter=`(v: int) = this.testCustomSetterValue = v + singleton ExternalSingleton: var v1 = 3 \ No newline at end of file diff --git a/classes.nimble b/classes.nimble index f177430..b0ade87 100644 --- a/classes.nimble +++ b/classes.nimble @@ -1,5 +1,5 @@ # Package -version = "0.2.12" +version = "0.2.13" author = "jjv360" description = "Adds class support to Nim." license = "MIT" diff --git a/src/classes.nim b/src/classes.nim index eadd6c0..152d337 100644 --- a/src/classes.nim +++ b/src/classes.nim @@ -427,7 +427,7 @@ proc createClassStructure(head: NimNode, bodyNode: NimNode, result: NimNode, isS # methodNode.pragma.add(newNimNode(nnkPragma).add(ident"base")) # Make sure it's exported - if methodNode[0].kind == nnkIdent: + if methodNode[0].kind == nnkIdent or methodNode[0].kind == nnkAccQuoted: methodNode[0] = newTree(nnkPostfix, ident"*", methodNode[0]) # Add it @@ -688,7 +688,7 @@ proc createClassStructure(head: NimNode, bodyNode: NimNode, result: NimNode, isS # Make sure it's exported - if methodNode[0].kind == nnkIdent: + if methodNode[0].kind == nnkIdent or methodNode[0].kind == nnkAccQuoted: methodNode[0] = newTree(nnkPostfix, ident"*", methodNode[0]) # Add it @@ -770,8 +770,8 @@ proc createClassStructure(head: NimNode, bodyNode: NimNode, result: NimNode, isS return `sharedVarName` ) - # if $className == "AsyncCls": - # echo result.repr + # if $className == "ExternalClass": + # echo result.repr # Export new keyword which was imported from our lib # let newIdent = ident"new" diff --git a/test.nim b/test.nim index 180f979..fa457ff 100644 --- a/test.nim +++ b/test.nim @@ -101,6 +101,10 @@ let customGetterSetter = CustomGetterSetter.init() customGetterSetter.v2 = 7 assert(customGetterSetter.v2 == 7) +let externalGetterSetter = ExternalClass.init() +externalGetterSetter.testCustomSetter = 8 +assert(externalGetterSetter.testCustomSetter == 8) +