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

nim jsondoc -o:doc.json filename.nim fails when sequences without a type are used #14066

Closed
faulander opened this issue Apr 22, 2020 · 4 comments · Fixed by #14135
Closed

nim jsondoc -o:doc.json filename.nim fails when sequences without a type are used #14066

faulander opened this issue Apr 22, 2020 · 4 comments · Fixed by #14135

Comments

@faulander
Copy link

faulander commented Apr 22, 2020

Running "nim jsondoc -o:doc.json filename.nim" results in:
Error: unhandled exception: index out of bounds, the container is empty [IndexError]

Example

proc hashesToStr(hashes: seq): string = 
  var h:string
  if hashes.len == 0:
      result = ""
  else:
    for hash in hashes:
      h = h & hash & "|"
    h = h[0 .. len(h)-2] # cuts of the last |
    result = h

Additional Information

Already discussed and found a workaround with PMunch on IRC.

$ nim -v
Nim Compiler Version 1.2.0
@metagn
Copy link
Collaborator

metagn commented Apr 22, 2020

Unrelated to the issue, and not a workaround, can be marked as offtopic, just an FYI: instead of doing str = str & ... (creates a new string) you should do str &= ... which is actually an alias for str.add(...) (modifies the existing string), and instead of doing str = str[0.. newlen - 1] (creates a copy) you should do str.setLen(newlen) (doesn't create a copy).

@PMunch
Copy link
Contributor

PMunch commented Apr 22, 2020

The issue is that it assumes that seq in the signature has a type and fails when it doesn't. Should be a simple fix in compiler/types.nim:598 and it should be fixed similarly for the other types with the same behaviour. I'll fix it, just wanted to have an issue so I didn't forget.

By the way, what is the tyOpt type that can be found next to seq in the code?

@Araq
Copy link
Member

Araq commented Apr 27, 2020

By the way, what is the tyOpt type that can be found next to seq in the code?

It is a builtin "opt[T]" type, it's dead code.

@PMunch
Copy link
Contributor

PMunch commented Apr 27, 2020

Right, should I just make that into an assert false or something then?

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

Successfully merging a pull request may close this issue.

4 participants