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

toSeq result can't be assigned to a const inside a generic proc #14192

Closed
dawkot opened this issue May 2, 2020 · 2 comments
Closed

toSeq result can't be assigned to a const inside a generic proc #14192

dawkot opened this issue May 2, 2020 · 2 comments

Comments

@dawkot
Copy link

dawkot commented May 2, 2020

Example

import sequtils

proc myProc[T](x: T) =
  const myConst = toSeq(1..3)

myProc 123

Current Output

/usercode/in.nim(6, 8) template/generic instantiation of `myProc` from here
/playground/nim/lib/pure/collections/sequtils.nim(712, 11) Error: cannot evaluate at compile time: i`gensym3690237

Workaround

import sugar

proc myProc[T](x: T) =
  const myConst = collect(newSeq, for i in 1..3: i)

myProc 123

Additional Information

  • Nim 1.2.0
@metagn
Copy link
Collaborator

metagn commented May 2, 2020

Compiler SIGSEGVs if you do:

import sequtils

proc myProc[T](x: T) =
  const myConst = static(toSeq(1..3))

myProc 123

@timotheecour
Copy link
Member

timotheecour commented Jun 25, 2020

  • @dawkot this has nothing to do with generics, when you state can't be assigned to a const inside a generic proc you really have to check whether it would instead work inside a non-generic.
    It turns out it also doesn't work:
when true:
  import sequtils
  proc myProc() =
    const myConst = toSeq(1..3)
  myProc()

=> same error

and in fact this is a duplicate of #13795

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

3 participants