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

Some issues after importing tables module (with iterators?) #8064

Open
ghost opened this issue Jun 18, 2018 · 5 comments
Open

Some issues after importing tables module (with iterators?) #8064

ghost opened this issue Jun 18, 2018 · 5 comments

Comments

@ghost
Copy link

ghost commented Jun 18, 2018

Sorry, my nim skills are too low to narrow the issues anymore. The only thing I know is that values in the below snippets is some iterator from tables module. And since i don't even know what the reason of the crash is, I cannot even search github for existing issues.


1

Code:

import tables

values

gives

t.nim(3, 1) Error: expression 'values' is of type 'None' and has to be discarded

2. Adding discard to the above code gives -

import tables

discard values
t.nim(3, 1) Error: statement returns no value that can be discarded

In the first snippet the compiler asks to discard value but now it says that nothing can be discarded.


3. This code crashes compiler

import tables

values[1]

crashes compiler with -

t.nim(3, 7) Error: internal error: expr(nkClosedSymChoice); unknown node kind
No stack traceback available
To create a stacktrace, rerun compilation with ./koch temp c <file>

Koch gives -

t.nim(3, 7) Error: internal error: expr(nkClosedSymChoice); unknown node kind
Traceback (most recent call last)
nim.nim(133)             nim
nim.nim(97)              handleCmdLine
main.nim(162)            mainCommand
main.nim(73)             commandCompileToC
modules.nim(124)         compileProject
modules.nim(71)          compileModule
passes.nim(194)          processModule
passes.nim(103)          processTopLevelStmt
cgen.nim(1379)           myProcess
ccgstmts.nim(1146)       genStmts
ccgexprs.nim(2337)       expr
msgs.nim(524)            internalError
msgs.nim(495)            liMessage
msgs.nim(324)            handleError
msgs.nim(314)            quit

4. This code also crashes compiler

import tables

values[1] = 1

Koch gives

nim.nim(133)             nim
nim.nim(97)              handleCmdLine
main.nim(162)            mainCommand
main.nim(73)             commandCompileToC
modules.nim(124)         compileProject
modules.nim(71)          compileModule
passes.nim(194)          processModule
passes.nim(103)          processTopLevelStmt
sem.nim(580)             myProcess
sem.nim(548)             semStmtAndGenerateGenerics
semstmts.nim(1885)       semStmt
semexprs.nim(818)        semExprNoType
semexprs.nim(2431)       semExpr
semexprs.nim(1442)       semAsgn
ast.nim(1402)            skipTypes
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
@andreaferretti
Copy link
Collaborator

values(t) is an iterator over the values in the table t. It is supposed to be used like this:

import tables

let t = {"a": 1, "b":2}.newTable

for x in values(t):
  echo x

I agree that the error messages you got were not very informative

@ghost
Copy link
Author

ghost commented Jun 18, 2018

@andreaferretti
I know how to use an iterator but this is crashing the compiler. See 3 & 4 above. (Internal Error & Segfault)

@andreaferretti
Copy link
Collaborator

I agree - the errors should be handled and reporting should be improved. That's why I added the Error messages label

@ringabout
Copy link
Member

ringabout commented Sep 13, 2021

Example 4 gives proper(?) error messages on devel.

Reduced code for example 3:

type
  A = object
  B = object

proc values[T](o: A, x: T): T = x
proc values[T](o: B, x: T): T = x

values[1]

@bung87
Copy link
Collaborator

bung87 commented Sep 20, 2022

I think only example 1 should take care of for current stage. like Error: expression has no type: values

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

No branches or pull requests

4 participants