From 0510a2be0d6df674aa91ae3f2884d98473cade4c Mon Sep 17 00:00:00 2001 From: Bung Date: Sat, 15 Oct 2022 13:15:58 +0800 Subject: [PATCH] =?UTF-8?q?fix=20#19700=20Crash=20when=20passing=20a=20tem?= =?UTF-8?q?plate=20to=20a=20generic=20functio=E2=80=A6=20(#20567)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix nim-lang#19700 Crash when passing a template to a generic function expecting a procedure --- compiler/sigmatch.nim | 2 ++ tests/template/t19700.nim | 10 ++++++++++ 2 files changed, 12 insertions(+) create mode 100644 tests/template/t19700.nim diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 60b0fe612c..7124315d91 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -2131,6 +2131,8 @@ proc paramTypesMatchAux(m: var TCandidate, f, a: PType, result = c.semInferredLambda(c, m.bindings, arg) elif arg.kind != nkSym: return nil + elif arg.sym.kind in {skMacro, skTemplate}: + return nil else: let inferred = c.semGenerateInstance(c, arg.sym, m.bindings, arg.info) result = newSymNode(inferred, arg.info) diff --git a/tests/template/t19700.nim b/tests/template/t19700.nim new file mode 100644 index 0000000000..cc29449446 --- /dev/null +++ b/tests/template/t19700.nim @@ -0,0 +1,10 @@ +discard """ + errormsg: "type mismatch: got " +""" + +type Obj = object + +proc apply[T, R](a, b: T; f: proc(x, y: T): R): R = f(a, b) + +let a, b = Obj() +discard apply(a, b, `!=`)