Skip to content

Commit

Permalink
fix crash with undeclared proc type pragma macro in generics
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed Dec 2, 2024
1 parent 5340005 commit ac15cfa
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/semtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions tests/pragmas/tundeclaredgenericmacro.nim
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ac15cfa

Please sign in to comment.