Error: internal error: (filename: compiler/sem.nim, line: 144)
(It's the line in sem.nim that goes "internalAssert sfGenSym in result.flags".)
I made a tiny example of this in a file called bug_template.nim to try to figure out what feature was the cause, but I realized that there is some compiler caching that is responsible. Eg.
nimrod c --run bug_template.nim # works cp -a bug_template.nim vec.nim nimrod c --run vec.nim # gives the error above
I removed the local nimcache. I didn't see anything in /tmp that could have been the cause. This behavior persists. It's not clear based on the compiler help how one can do a "deep clean" of the compiler. Suggestions?
Removing the cache directory didn't help.
So I thought it was some caching issue, but there was some other cache that was affecting it. Is there some workaround that doesn't involve renaming files every time this starts happening? I am happy to help with debugging.
$ cp vec.nim bug_template.nim $ gvim bug_template.nim $ nimrod c --run bug_template.nim config/nimrod.cfg(38, 2) Hint: added path: '<...>/.babel/pkgs/' [Path] Hint: used config file '<...>/Nimrod/config/nimrod.cfg' [Conf] Hint: system [Processing] lib/system/ansi_c.nim(81, 12) Warning: undeclared conditional symbol; use --symbol to declare it: nimSigSetjmp [User] lib/system/ansi_c.nim(81, 42) Warning: undeclared conditional symbol; use --symbol to declare it: nimStdSetjmp [User] lib/system/ansi_c.nim(88, 12) Warning: undeclared conditional symbol; use --symbol to declare it: nimRawSetjmp [User] lib/system/ansi_c.nim(88, 42) Warning: undeclared conditional symbol; use --symbol to declare it: nimStdSetjmp [User] Hint: bug_template [Processing] bug_template.nim(157, 12) Info: instantiation from here bug_template.nim(149, 43) Info: instantiation from here bug_template.nim(60, 42) Info: instantiation from here bug_template.nim(157, 12) Info: instantiation from here bug_template.nim(149, 43) Info: instantiation from here bug_template.nim(60, 42) Info: instantiation from here Error: internal error: (filename: compiler/sem.nim, line: 144) No stack traceback available
BUT, I went to the minimal version and renamed the vec field to asdf (shown below) and it...succeeded...? It works fine as vec.nim or bug_template.nim. If you rename "asdf" to "vec" then vec.nim fails with the sem.nim error. Does this help locate the cause?
# Type
template defineVectorType(tvec: expr, n: expr) {.immediate.} =
type tvec* {.pure, final.}[Scalar] = object
asdf: array[0..n-1, Scalar]
# Constructor
template defineConstructor(tvec: expr, vecn: expr, n: expr) {.immediate.} =
proc vecn*[Scalar](ary: array[0..n-1, Scalar]): tvec[Scalar] {.inline.} =
result.asdf = ary
# Class instantiation
# tvec - typename
# vecn - constructor
# n - dimension
template defineVector(tvec: expr, vecn: expr, n: expr) {.immediate.} =
defineVectorType(tvec, n)
defineConstructor(tvec, vecn, n)
defineVector(TVec2, vec2, 2)
# Unit tests
when isMainModule:
import unittest
test "constructors":
let a = vec2([1.0, 2.0])
check(a.asdf == [1.0, 2.0])
Does this help locate the cause?
Well no, because I know the cause and it's as I explained and you confirmed. So it's a field instead of a proc name, doesn't matter.
It compiles and runs successfully via
$ nimrod c --run vec.nim
There are 3 lines annotated with
# ERROR: causes sem.nim line 144 error
As the comment indicates, uncommenting any one of them results in the error. If you believe this code is somehow unreasonable (except for the somewhat arbitrary use of "asdf", of course), then I would appreciate any advice as to how or whether I can get it to define the commented operators and compile+pass my tests.
Filed a bug with a minimal example: https://github.com/Araq/Nimrod/issues/1562
Problem is with defining /= within a double-nested template.