Skip to content

Commit

Permalink
account for nil return type in tyProc sumGeneric (#23250)
Browse files Browse the repository at this point in the history
fixes #23249
  • Loading branch information
metagn authored Jan 23, 2024
1 parent be0b847 commit ee984f8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/sigmatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ proc sumGeneric(t: PType): int =
result += sumGeneric(a)
break
of tyProc:
result += sumGeneric(t.returnType)
if t.returnType != nil:
result += sumGeneric(t.returnType)
for _, a in t.paramTypes:
result += sumGeneric(a)
break
Expand Down
17 changes: 17 additions & 0 deletions tests/overload/t23249.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# issue #23249

type Control* = object
proc onAction*(c: Control, handler: proc(e: int) {.gcsafe.}) = discard
proc onAction*(c: Control, handler: proc() {.gcsafe.}) = discard

template setControlHandlerBlock(c: Control, p: untyped, a: untyped) =
when compiles(c.p(nil)):
c.p() do() {.gcsafe.}: a
else:
c.p = proc() {.gcsafe.} =
a

proc mkLayout() =
var b: Control
setControlHandlerBlock(b, onAction):
echo "hi"

0 comments on commit ee984f8

Please sign in to comment.