nim c -r bugs/t01_error_context.nim
lib/system/sysio.nim(351, 20) Error: cannot 'importc' variable at compile time
the error doesn't show the right context where error occurs.
import strutils, sequtils
# replace this with some path to some text file
const input = "/Users/timothee/git_clone/LPATHBench/agraph"
proc testCTFE():auto=
let lines0 = toSeq(input.lines)
# let lines0 = input.lines()
echo lines0
result = 0
const res1=testCTFE()
# let res1=testCTFE()
echo $("res1", res1)
In D the error is more helpful and points to user source code, eg:
void main(){
import core.stdc.stdio;
enum s=printf("hello\n");
}
dmd -o- main.d
main.d(3): Error: printf cannot be interpreted at compile time, because it has no available source code
The error shows exactly where the problem is.
The error shows exactly where the problem is.
On Nim side, but not on user side. It would be a real time saver if the compiler would mention line 7 in the user code, which I _guess_ is the cause. Looking at line 351 of sysio can be confusing, because it is in the context of open and the user never consciously calls that function. In some cases it is not straightforward to make the connection back to user code due to several steps of indirection.
Might be related to https://github.com/nim-lang/Nim/issues/6763
Most helpful comment
On Nim side, but not on user side. It would be a real time saver if the compiler would mention line 7 in the user code, which I _guess_ is the cause. Looking at line 351 of sysio can be confusing, because it is in the context of
openand the user never consciously calls that function. In some cases it is not straightforward to make the connection back to user code due to several steps of indirection.Might be related to https://github.com/nim-lang/Nim/issues/6763