fix crash with undeclared proc type pragma macro in generics (#24490)

fixes #24489
This commit is contained in:
metagn
2024-12-02 07:21:12 +03:00
committed by GitHub
parent 5340005869
commit 05bba15623
2 changed files with 33 additions and 1 deletions

View File

@@ -1867,7 +1867,7 @@ proc applyTypeSectionPragmas(c: PContext; pragmas, operand: PNode): PNode =
x.add(operand.copyTreeWithoutNode(p))
# recursion assures that this works for multiple macro annotations too:
var r = semOverloadedCall(c, x, x, {skMacro, skTemplate}, {efNoUndeclared})
if r != nil:
if r != nil and (r.typ == nil or r.typ.kind != tyFromExpr):
doAssert r[0].kind == nkSym
let m = r[0].sym
case m.kind

View File

@@ -0,0 +1,32 @@
import std/[asyncdispatch, httpclient, strutils, json, times]
type
Tree[T] = object
x: T
rr: seq[Tree[T]]
I = Tree[int]
F = Tree[Future[string]]
proc title(t: I): Future[string] {.async,gcsafe.} =
let cli = newAsyncHttpClient()
let c = await cli.getContent("https://jsonplaceholder.typicode.com/todos/" & $t.x)
c.parseJson()["title"].getStr()
proc map[T,U](t: T, f: proc (x: T): U{.async.gcsafe.}): U = #[tt.Error
^ invalid pragma: async.gcsafe]#
result.x = f(t)
for r in t.rr:
result.rr.add map(r, f)
proc f(t: F, l: int) {.async.} =
echo repeat(' ', l), (await t.x)
for r in t.rr:
await f(r, l+1)
proc asyncMain() {.async.} =
let t = I(x: 1, rr: @[I(x: 2), I(x: 3, rr: @[I(x: 4), I(x: 5)])])
await f(map[I,F](t, title), 0)
let a = now()
waitFor asyncMain()
echo now() - a