-3

Here's my code (I'm using Nim v1.2.0):

var test_table = initTable[int, string]()

When I compile I get a confusing error message that doesn't even refer to the line of code above:

Error: internal error: genTypeInfo(tyNone)
No stack traceback available
To create a stacktrace, rerun compilation with ./koch temp c <file>

However when I remove this line there are no errors. Is my code wrong or is this a bug in the Nim compiler?

Jason
  • 531
  • 6
  • 19
  • 2
    https://stackoverflow.com/help/minimal-reproducible-example – xbello Apr 16 '20 at 07:59
  • This code is 100% correct, and not the cause of your Error. You can get an error on a simple `echo anything` if `anything` is not echo-able, but that doesn't make `echo` the root of the problem. – xbello Apr 16 '20 at 08:02
  • It doesn't get more minimal than a single line of code that has no dependencies. Does this work in your environment? If so, which version of nim are you using? – Jason Apr 16 '20 at 08:33
  • You missed "reproducible". I'm using 1.2.0: `import tables \n var test_table = initTable[int, string]() \n echo test_table`, compiles perfectly and echoes `{:}`, the expected empty table. – xbello Apr 16 '20 at 08:52
  • The problem seems to jump around, even with dev 1.3.1, different lines of code seem to cause the same internal error. So this is likely memory corruption. – Jason Apr 16 '20 at 09:12

1 Answers1

1

I fixed this error by changing another line of code:

test_seq: seq = @[ "a", "b", "c" ]

to:

test_seq = @[ "a", "b", "c" ]

But I have no idea why this would remove the error. It looks like a strange bug in the Nim compiler (tested on both v1.2.0 and current dev code v1.3.1).

Jason
  • 531
  • 6
  • 19
  • 3
    As I expected, there were more code than you provided in your question. Your problem is that the first line is wrong. You have to be explicit with the type you will store in your seq, e.g. `var test_seq: seq[string] = @["a", "b", "c"]` – xbello Apr 16 '20 at 09:24
  • The Nim compiler is so smart that it infers the `seq[string]` bit in your second line. – xbello Apr 16 '20 at 09:26
  • You found the underlying problem: when I specified seq only the compiler errored out, but if I specify no type or the correct type of seq[string] then it works. Thanks! – Jason Apr 16 '20 at 10:21
  • 1
    This doesn't happen with --gc:arc – shirleyquirk Sep 10 '20 at 01:11