summary refs log tree commit diff stats
path: root/tests/pragmas
diff options
context:
space:
mode:
authorClyybber <darkmine956@gmail.com>2021-04-21 15:28:42 +0200
committerGitHub <noreply@github.com>2021-04-21 15:28:42 +0200
commit7c64e49d452607fa246b54e931c057ed172b264a (patch)
tree4cc63bfbc9cb531fcf4ba6771725e6d0b528f7f2 /tests/pragmas
parentda1c1a711780e21a372ef70f9080aebe5b9ef987 (diff)
downloadNim-7c64e49d452607fa246b54e931c057ed172b264a.tar.gz
getCustomPragmaVal priority/override fixes (#17725)
* Adhere left-to-right rule for custom pragma priority

* Improve error message for no custom pragmas

* custom pragmas on var/let sym take priority over its type ones

* Workaround & bug
Diffstat (limited to 'tests/pragmas')
-rw-r--r--tests/pragmas/tcustom_pragma.nim10
1 files changed, 10 insertions, 0 deletions
diff --git a/tests/pragmas/tcustom_pragma.nim b/tests/pragmas/tcustom_pragma.nim
index 30b08b44e..3ef5bdcb6 100644
--- a/tests/pragmas/tcustom_pragma.nim
+++ b/tests/pragmas/tcustom_pragma.nim
@@ -165,11 +165,14 @@ type
 let a {.defaultValue(4).}: proc(x: int)  = nil
 var b: MyAnnotatedProcType = nil
 var c: proc(x: int): void {.defaultValue(5).}  = nil
+var d {.defaultValue(44).}: MyAnnotatedProcType = nil
 static:
   doAssert hasCustomPragma(a, defaultValue)
   doAssert hasCustomPragma(MyAnnotatedProcType, defaultValue)
   doAssert hasCustomPragma(b, defaultValue)
   doAssert hasCustomPragma(typeof(c), defaultValue)
+  doAssert getCustomPragmaVal(d, defaultValue) == 44
+  doAssert getCustomPragmaVal(typeof(d), defaultValue) == 4
 
 # bug #8371
 template thingy {.pragma.}
@@ -405,3 +408,10 @@ template hehe(key, val: string, haha) {.pragma.}
 type A {.haha, hoho, haha, hehe("hi", "hu", "he").} = int
 
 assert A.getCustomPragmaVal(hehe) == (key: "hi", val: "hu", haha: "he")
+
+template hehe(key, val: int) {.pragma.}
+
+var bb {.haha, hoho, hehe(1, 2), haha, hehe("hi", "hu", "he").} = 3
+
+# left-to-right priority/override order for getCustomPragmaVal
+assert bb.getCustomPragmaVal(hehe) == (key: "hi", val: "hu", haha: "he")