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

Bug with implicit conversion to proc types within varargs #20353

Open
Hi02hi opened this issue Sep 14, 2022 · 1 comment
Open

Bug with implicit conversion to proc types within varargs #20353

Hi02hi opened this issue Sep 14, 2022 · 1 comment

Comments

@Hi02hi
Copy link

Hi02hi commented Sep 14, 2022

What happened?

I was trying to have a function which uses both procedures and varargs, but it refused to implicitly convert

type F = proc (x: int)

func exampleF(x: int) = 
  discard

func exampleF2(x: int) = 
  discard

proc applyF(x: int, f1, f2: F) = 
  f1(x)
  f2(x)

applyF(3, exampleF, exampleF2)

works but

# ...

proc applyF(x: int, fs: varargs[F]) = 
  for f in fs:
    f(x)

applyF(3, exampleF, exampleF2)

complains that the example F's are not actually F's

I can manually convert them by doing

# ...

proc applyF(x: int, fs: varargs[F]) = 
  for f in fs:
    f(x)

applyF(3, F(exampleF), F(exampleF2))

but note that both of these work, proving implicit conversion is allowed in other cases

proc applyF(x: int, fs: varargs[F]) = 
  for f in fs:
    f(x)

let
  test1: F = exampleF
  test2: F = exampleF2

applyF(3, test1, test2)
# ...

proc applyF(x: int, fs: varargs[F]) = 
  for f in fs:
    f(x)

applyF(3, [F(exampleF), exampleF2])

Nim Version

Nim Compiler Version 1.6.6 [Linux: amd64]
Compiled at 2022-05-05
Copyright (c) 2006-2021 by Andreas Rumpf

git hash: 0565a70
active boot switches: -d:release

Current Standard Output Logs

No response

Expected Standard Output Logs

No response

Possible Solution

Currently, I am using the last code snippet there as a workaround, but it would be nice if the implicit conversion would be consistent.

Additional Information

Thank you for the nice form for bug reports :)

@bung87
Copy link
Collaborator

bung87 commented Dec 10, 2022

need change to type F = proc (x: int){.nimcall.} , the F proc type without call conversation is closure, so it doesn't match, I know the error message is not obvious.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants