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

document or improve behavior of varargsLen in procs (differs from behavior in templates) #18463

Open
timotheecour opened this issue Jul 8, 2021 · 0 comments

Comments

@timotheecour
Copy link
Member

timotheecour commented Jul 8, 2021

in procs, varargs is a RT construct, whereas in templates it's a CT construct. This leads to surprising behavior for varargsLen for users unaware of this subtlety.

refs #18418 (comment) /cc @quantimnot

I just found system.varargsLen but it seems to be broken.

Example

proc a0(b: varargs[string]) =
  let s2 = len(b) # len not available at CT for good reasons
  echo s2
proc a1(b: varargs[string]) =
  const s1 = varargsLen(b)
  let s2 = varargsLen(b)
  echo (s1, s2)
template a2(b: varargs[string]) =
  const s1 = varargsLen(b)
  let s2 = varargsLen(b)
  echo (s1, s2)
a0()
a0("x1")
a0("x1", "x2")

a1()
a1("x1")
a1("x1", "x2")

a2()
a2("x1")
a2("x1", "x2")

Current Output

0
1
2
(1, 1)
(1, 1)
(1, 1)
(0, 0)
(1, 1)
(2, 2)

Expected Output

either:

  • give CT error for varargsLen inside a proc (a1)
  • give CT error for varargsLen inside a a proc (a1) but only if used in a static context, otherwise make it equal to len

and document this with a runnableExamples

Additional Information

1.5.1 0d74f60
note: also need to consider macros, besides proc and template

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

1 participant