fix #19700 Crash when passing a template to a generic functio… (#20567)

fix nim-lang#19700 Crash when passing a template to a generic function expecting a procedure
This commit is contained in:
Bung
2022-10-15 13:15:58 +08:00
committed by GitHub
parent 57574eaf31
commit 0510a2be0d
2 changed files with 12 additions and 0 deletions

View File

@@ -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)

10
tests/template/t19700.nim Normal file
View File

@@ -0,0 +1,10 @@
discard """
errormsg: "type mismatch: got <Obj, Obj, template (x: untyped, y: untyped): untyped>"
"""
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, `!=`)