From ee984f8836740cb64d88c622ff652e396751edee Mon Sep 17 00:00:00 2001 From: metagn Date: Wed, 24 Jan 2024 00:00:34 +0300 Subject: [PATCH] account for nil return type in tyProc sumGeneric (#23250) fixes #23249 --- compiler/sigmatch.nim | 3 ++- tests/overload/t23249.nim | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 tests/overload/t23249.nim diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index b4d8759811..a0de33ed50 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -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 diff --git a/tests/overload/t23249.nim b/tests/overload/t23249.nim new file mode 100644 index 0000000000..f4657833b9 --- /dev/null +++ b/tests/overload/t23249.nim @@ -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"