I have a strange error that seems to be a compiler bug.
I have the following code in its own module, let's say stringrecord.nim.
type
StringRecord* {.importcpp, header: "StringRecord.h".} = object
size*: csize_t
`string`*: ptr UncheckedArray[char]
proc toStringRecord*(str: string): StringRecord =
return StringRecord(size: uint(str.len), `string`: cast[ptr UncheckedArray[char]](cstring(str)))
proc toString*(sr: StringRecord): string =
if sr.size != 0:
result = newString(sr.size)
copyMem(result[0].addr, sr.`string`, sr.size)
else:
result = ""
If compiling this in a small test program it compiles without any problems. I have a larger project where this file is imported, often at top level and there I get the following error.
... stringrecord.nim(21, 27) Error: system module needs: nimAsgnStrV2
Tip: 2 messages have been suppressed, use --verbose to show them.
nimble.nim(246) buildFromDir
Error: Build failed for the package: ...
It is basically in the toString function that any operation on the string type will trigger the error. This forces me to copy the function toString to every file that uses it for now which is inconvenient. Unfortunately I can't provide you with the entire project which is too big but something there makes the nim compiler believe that nimAsgnStrV2 doesn't exist which is always imported from the system module by default.
Any idea where to begin to look?