diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 5a0968ba55cb5..7b5b17f9c7d49 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -1819,7 +1819,15 @@ proc semInferredLambda(c: PContext, pt: TIdTable, n: PNode): PNode = #incl(s.flags, sfFromGeneric) #s.owner = original + let originalReturnType = n.typ[0] n = replaceTypesInBody(c, pt, n, original) + if originalReturnType != nil and originalReturnType.kind == tyAnything: + # the return type should not be set to a previous binding of `auto` + # this could alternatively be done by changing tyAnything to + # differentiate based on which place it's inferring the type of + # (i.e. a unique instance of tyAnything for every reference to `auto`), + # but for now this is sufficient as we only care to infer return types + n.typ[0] = originalReturnType result = n s.ast = result n[namePos].sym = s diff --git a/tests/overload/t23200.nim b/tests/overload/t23200.nim new file mode 100644 index 0000000000000..3eccfb2b8159f --- /dev/null +++ b/tests/overload/t23200.nim @@ -0,0 +1,16 @@ +import std/[sugar, sequtils] + +proc dosomething(iter: int -> (iterator: int)) = + discard + +proc dosomething(iter: int -> seq[int]) = + discard + +proc makeSeq(x: int): seq[int] = + @[x] + +# Works fine with 1.6.12 and 1.6.14 +dosomething(makeSeq) + +# Works with 1.6.12, fails with 1.6.14 +dosomething((y) => makeSeq(y)) diff --git a/tests/types/t15836_2.nim b/tests/types/t15836_2.nim index 9afef416a88db..6a16e2d2227e7 100644 --- a/tests/types/t15836_2.nim +++ b/tests/types/t15836_2.nim @@ -1,8 +1,3 @@ - -discard """ - action: "compile" - disabled: true -""" import std/sugar type Tensor[T] = object