mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
fix crash with undeclared proc type pragma macro in generics (#24490)
fixes #24489
This commit is contained in:
@@ -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
|
||||
|
||||
32
tests/pragmas/tundeclaredgenericmacro.nim
Normal file
32
tests/pragmas/tundeclaredgenericmacro.nim
Normal 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
|
||||
Reference in New Issue
Block a user