fixes #22284; fixes #22282; don't override original parameters of inferred lambdas (#23368)

fixes #22284
fixes #22282

```
Error: j(uRef, proc (config: F; sources: auto) {.raises: [].} = discard ) can raise an unlisted exception: Exception
```

The problem is that `n.typ.n` contains the effectList which shouldn't
appear in the parameter of a function defintion. We could not simply use
`n.typ.n` as `n[paramsPos]`. The effect lists should be stripped away
anyway.

(cherry picked from commit 320311182c)
This commit is contained in:
ringabout
2024-03-09 18:42:15 +08:00
committed by narimiran
parent e15aa20059
commit 61da33f31b
2 changed files with 25 additions and 1 deletions

View File

@@ -1805,7 +1805,6 @@ proc semInferredLambda(c: PContext, pt: TIdTable, n: PNode): PNode =
n[genericParamsPos] = c.graph.emptyNode
# for LL we need to avoid wrong aliasing
let params = copyTree n.typ.n
n[paramsPos] = params
s.typ = n.typ
for i in 1..<params.len:
if params[i].typ.kind in {tyTypeDesc, tyGenericParam,

25
tests/errmsgs/t22284.nim Normal file
View File

@@ -0,0 +1,25 @@
discard """
errormsg: "j(uRef, proc (config: F; sources: auto) {.raises: [].} = discard ) can raise an unlisted exception: Exception"
"""
import std/macros
macro h(): untyped =
result = newTree(nnkStmtList)
result.add quote do:
new int
type F = object
proc j[SecondarySources](
uRef: ref SecondarySources,
u: proc (config: F, sources: ref SecondarySources)): F =
u(result, uRef)
template programMain(body: untyped) =
proc main {.raises: [].} = body # doesn't SIGSEGV without this {.raises: [].}
main()
programMain:
var uRef = h()
discard j(uRef, u = proc(config: F, sources: auto) {.raises: [].} = discard)