diff --git a/compiler/sem/semstmts.nim b/compiler/sem/semstmts.nim index 5acc11c8df9..9052ceeb6b7 100644 --- a/compiler/sem/semstmts.nim +++ b/compiler/sem/semstmts.nim @@ -2182,45 +2182,48 @@ proc semProcAnnotation(c: PContext, prc: PNode): PNode = proc semInferredLambda(c: PContext, pt: TIdTable, n: PNode): PNode {.nosinks.} = ## used for resolving 'auto' in lambdas based on their callsite addInNimDebugUtils(c.config, "semInferredLambda", n, result) - var n = n let original = n[namePos].sym let s = original #copySym(original, false) #incl(s.flags, sfFromGeneric) #s.owner = original - n = instantiateTypesInBody(c, pt, n, original) - result = n + result = instantiateTypesInBody(c, pt, n, original) s.ast = result - n[namePos].sym = s - n[genericParamsPos] = c.graph.emptyNode + result[namePos].sym = s + result[genericParamsPos] = c.graph.emptyNode # for LL we need to avoid wrong aliasing - n[paramsPos] = newNodeI(nkFormalParams, n[paramsPos].info, n.typ.n.len) - for i, p in n.typ.n.pairs: - n[paramsPos][i] = + result[paramsPos] = newNodeI(nkFormalParams, result[paramsPos].info, + result.typ.n.len) + for i, p in result.typ.n.pairs: + result[paramsPos][i] = case i of 0: # return type - newNodeIT(nkType, n.info, n.typ[0]) + newNodeIT(nkType, n.info, result.typ[0]) else: # copy instantiated parameters - n.typ.n[i] - s.typ = n.typ - let params = n.typ.n - for i in 1..= formalLen - 1 and # last or finished passing args f < formalLen and # still have more formal params - m.callee.n[f].typ.isVarargsUntyped: # current formal is varargs untped + m.callee.n[f].typ.isVarargsUntyped: # current formal is varargs untyped formal = m.callee.n[f].sym incl(marker, formal.position) diff --git a/tests/lang_callable/generics/tauto_inference_failure_due_to_body_error.nim b/tests/lang_callable/generics/tauto_inference_failure_due_to_body_error.nim new file mode 100644 index 00000000000..4c3a7f57a58 --- /dev/null +++ b/tests/lang_callable/generics/tauto_inference_failure_due_to_body_error.nim @@ -0,0 +1,13 @@ +discard """ + description: "Fail lambda inference due to error within the body." + errormsg: "undeclared identifier: 'i'" + line: 13 +""" + +# This is a regression test, ensure we report errors inside lambdas during +# inference + +proc test(p: proc(x: int)) = + discard + +test proc(e: auto) = i \ No newline at end of file