Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing anonymous proc params to templates may fail #18648

Closed
etan-k opened this issue Aug 5, 2021 · 1 comment · Fixed by #24525
Closed

Passing anonymous proc params to templates may fail #18648

etan-k opened this issue Aug 5, 2021 · 1 comment · Fixed by #24525

Comments

@etan-k
Copy link

etan-k commented Aug 5, 2021

Passing an anonymous proc to a template may fail under Nim 1.2.12.

Example

type
  X* = ref object
    bar: proc (p: proc(v: openArray[byte]))

template foo(x: X, p: proc(v: openArray[byte])) =
  x.bar(p)

X().foo(proc(v: openArray[byte]) = discard @v)

Current Output

Error: internal error: expr: param not init v_4602025

Expected Output

Compilation should succeed

Possible Solution

  • Defining a named proc and passing the proc by name works fine.
  • Using a proc instead of a template works fine.

Additional Information

  • This bug is only present on the 1.2 branch of Nim.
  • On 1.4, the bug has been fixed as of 341be0b.
  • Backporting said commit on top of 1.2 fixes the bug, but this may introduce breaking changes as the AST representation of procs is modified.
$ nim -v
Nim Compiler Version 1.2.13 [MacOSX: amd64]
Compiled at 2021-08-05
Copyright (c) 2006-2020 by Andreas Rumpf

git hash: 76560576d2dd8ab1876fd4f81029d55467088354
active boot switches: -d:release
@metagn
Copy link
Collaborator

metagn commented Sep 26, 2024

As mentioned in the issue, works in 1.4 and now

metagn added a commit to metagn/Nim that referenced this issue Dec 8, 2024
@Araq Araq closed this as completed in aeb3fe9 Dec 9, 2024
narimiran pushed a commit that referenced this issue Jan 14, 2025
closes #6013, closes #7009, closes #9190, closes #12487, closes #12831,
closes #13184, closes #13252, closes #14860, closes #14877, closes
#14894, closes #14917, closes #16153, closes #16439, closes #17779,
closes #18074, closes #18202, closes #18314, closes #18648, closes
#19063, closes #19446, closes #20065, closes #20367, closes #22126,
closes #22820, closes #22888, closes #23020, closes #23287, closes
#23510

(cherry picked from commit aeb3fe9)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants