Fix getting custom pragma from generic object (#20481)

* Merge devel

Add another test case

* Fix test

Use getCustomPragmaVal instead of hasCustomPragma

Co-authored-by: Clay Sweetser <Varriount@users.noreply.github.com>
This commit is contained in:
Jake Leahy 2023-01-12 12:44:33 +11:00 • committed by GitHub
commit 1e52423774
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View file

@ -157,3 +157,21 @@ block: # bug #19020
static:
doAssert $bar.getCustomPragmaVal(typ) == "foo"
doAssert $bar.getCustomPragmaVal(typ) == "foo"
block hasCustomPragmaGeneric:
template examplePragma() {.pragma.}
type
Foo[T] {.examplePragma.} = object
x {.examplePragma.}: T
var f: Foo[string]
doAssert f.hasCustomPragma(examplePragma)
doAssert f.x.hasCustomPragma(examplePragma)
block getCustomPragmaValGeneric:
template examplePragma(x: int) {.pragma.}
type
Foo[T] {.examplePragma(42).} = object
x {.examplePragma(25).}: T
var f: Foo[string]
doAssert f.getCustomPragmaVal(examplePragma) == 42
doAssert f.x.getCustomPragmaVal(examplePragma) == 25