Nim
Nim copied to clipboard
Compiler fails when reading a float64 from a stringstream in a const context
Description
The compiler throws an error when trying to run the following code with nim r main.nim:
import std/streams
const hello = block:
let strm = newStringStream("12345678")
strm.readFloat64
echo hello
Nim Version
Nim Compiler Version 2.1.1 [Linux: amd64] Compiled at 2024-03-30 Copyright (c) 2006-2024 by Andreas Rumpf
git hash: cf00b2fd9e00909ac6368ece9515f0e020d7813d active boot switches: -d:release
Current Output
Hint: used config file '/home/tsoj/.choosenim/toolchains/nim-#devel/config/nim.cfg' [Conf]
Hint: used config file '/home/tsoj/.choosenim/toolchains/nim-#devel/config/config.nims' [Conf]
......................................................................fatal.nim(53) sysFatal
Error: unhandled exception: field 'sym' is not accessible for type 'TNode' using 'kind = nkNilLit' [FieldDefect]
Expected Output
6.821320051701325e-38
Possible Solution
No response
Additional Information
Replacing the const with a let works, i.e. this compiles:
import std/streams
let hello = block:
let strm = newStringStream("12345678")
strm.readFloat64
echo hello
What also works is reading a char:
import std/streams
const hello = block:
let strm = newStringStream("12345678")
strm.readChar
echo hello
!nim c
import std/streams
const hello = block:
let strm = newStringStream("12345678")
strm.readFloat64
echo hello
:penguin: Linux bisect by @ringabout (member)
devel :-1: FAIL
Output
Error: Command failed: nim c --run -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
fatal.nim(53) sysFatal
Error: unhandled exception: field 'sym' is not accessible for type 'TNode' using 'kind = nkNilLit' [FieldDefect]
IR
Compiled filesize0 bytes (0 bytes)
Stats
- Started
2024-04-02T12:05:45 - Finished
2024-04-02T12:05:45 - Duration
AST
nnkStmtList.newTree(
nnkImportStmt.newTree(
nnkInfix.newTree(
newIdentNode("/"),
newIdentNode("std"),
newIdentNode("streams")
)
),
nnkConstSection.newTree(
nnkConstDef.newTree(
newIdentNode("hello"),
newEmptyNode(),
nnkBlockStmt.newTree(
newEmptyNode(),
nnkStmtList.newTree(
nnkLetSection.newTree(
nnkIdentDefs.newTree(
newIdentNode("strm"),
newEmptyNode(),
nnkCall.newTree(
newIdentNode("newStringStream"),
newLit("12345678")
)
)
),
nnkDotExpr.newTree(
newIdentNode("strm"),
newIdentNode("readFloat64")
)
)
)
)
),
nnkCommand.newTree(
newIdentNode("echo"),
newIdentNode("hello")
)
)
stable :-1: FAIL
Output
Error: Command failed: nim c --run -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
fatal.nim(53) sysFatal
Error: unhandled exception: field 'sym' is not accessible for type 'TNode' using 'kind = nkNilLit' [FieldDefect]
IR
Compiled filesize0 bytes (0 bytes)
Stats
- Started
2024-04-02T12:05:45 - Finished
2024-04-02T12:05:46 - Duration
AST
nnkStmtList.newTree(
nnkImportStmt.newTree(
nnkInfix.newTree(
newIdentNode("/"),
newIdentNode("std"),
newIdentNode("streams")
)
),
nnkConstSection.newTree(
nnkConstDef.newTree(
newIdentNode("hello"),
newEmptyNode(),
nnkBlockStmt.newTree(
newEmptyNode(),
nnkStmtList.newTree(
nnkLetSection.newTree(
nnkIdentDefs.newTree(
newIdentNode("strm"),
newEmptyNode(),
nnkCall.newTree(
newIdentNode("newStringStream"),
newLit("12345678")
)
)
),
nnkDotExpr.newTree(
newIdentNode("strm"),
newIdentNode("readFloat64")
)
)
)
)
),
nnkCommand.newTree(
newIdentNode("echo"),
newIdentNode("hello")
)
)
2.0.2 :-1: FAIL
Output
Error: Command failed: nim c --run -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
fatal.nim(53) sysFatal
Error: unhandled exception: field 'sym' is not accessible for type 'TNode' using 'kind = nkNilLit' [FieldDefect]
IR
Compiled filesize0 bytes (0 bytes)
Stats
- Started
2024-04-02T12:05:46 - Finished
2024-04-02T12:05:46 - Duration
AST
nnkStmtList.newTree(
nnkImportStmt.newTree(
nnkInfix.newTree(
newIdentNode("/"),
newIdentNode("std"),
newIdentNode("streams")
)
),
nnkConstSection.newTree(
nnkConstDef.newTree(
newIdentNode("hello"),
newEmptyNode(),
nnkBlockStmt.newTree(
newEmptyNode(),
nnkStmtList.newTree(
nnkLetSection.newTree(
nnkIdentDefs.newTree(
newIdentNode("strm"),
newEmptyNode(),
nnkCall.newTree(
newIdentNode("newStringStream"),
newLit("12345678")
)
)
),
nnkDotExpr.newTree(
newIdentNode("strm"),
newIdentNode("readFloat64")
)
)
)
)
),
nnkCommand.newTree(
newIdentNode("echo"),
newIdentNode("hello")
)
)
1.6.14 :-1: FAIL
Output
Error: Command failed: nim c --run -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
fatal.nim(54) sysFatal
Error: unhandled exception: field 'sym' is not accessible for type 'TNode' using 'kind = nkNilLit' [FieldDefect]
IR
Compiled filesize0 bytes (0 bytes)
Stats
- Started
2024-04-02T12:05:51 - Finished
2024-04-02T12:05:51 - Duration
AST
nnkStmtList.newTree(
nnkImportStmt.newTree(
nnkInfix.newTree(
newIdentNode("/"),
newIdentNode("std"),
newIdentNode("streams")
)
),
nnkConstSection.newTree(
nnkConstDef.newTree(
newIdentNode("hello"),
newEmptyNode(),
nnkBlockStmt.newTree(
newEmptyNode(),
nnkStmtList.newTree(
nnkLetSection.newTree(
nnkIdentDefs.newTree(
newIdentNode("strm"),
newEmptyNode(),
nnkCall.newTree(
newIdentNode("newStringStream"),
newLit("12345678")
)
)
),
nnkDotExpr.newTree(
newIdentNode("strm"),
newIdentNode("readFloat64")
)
)
)
)
),
nnkCommand.newTree(
newIdentNode("echo"),
newIdentNode("hello")
)
)
1.4.8 :-1: FAIL
Output
Error: Command failed: nim c --run -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
fatal.nim(49) sysFatal
Error: unhandled exception: 'sym' is not accessible using discriminant 'kind' of type 'TNode' [FieldDefect]
IR
Compiled filesize0 bytes (0 bytes)
Stats
- Started
2024-04-02T12:05:53 - Finished
2024-04-02T12:05:54 - Duration
AST
nnkStmtList.newTree(
nnkImportStmt.newTree(
nnkInfix.newTree(
newIdentNode("/"),
newIdentNode("std"),
newIdentNode("streams")
)
),
nnkConstSection.newTree(
nnkConstDef.newTree(
newIdentNode("hello"),
newEmptyNode(),
nnkBlockStmt.newTree(
newEmptyNode(),
nnkStmtList.newTree(
nnkLetSection.newTree(
nnkIdentDefs.newTree(
newIdentNode("strm"),
newEmptyNode(),
nnkCall.newTree(
newIdentNode("newStringStream"),
newLit("12345678")
)
)
),
nnkDotExpr.newTree(
newIdentNode("strm"),
newIdentNode("readFloat64")
)
)
)
)
),
nnkCommand.newTree(
newIdentNode("echo"),
newIdentNode("hello")
)
)
1.2.18 :-1: FAIL
Output
Error: Command failed: nim c --run -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/.choosenim/toolchains/nim-1.2.18/lib/system/memory.nim(13, 5) Error: cannot 'importc' variable at compile time; c_memcpy
IR
Compiled filesize0 bytes (0 bytes)
Stats
- Started
2024-04-02T12:05:56 - Finished
2024-04-02T12:05:56 - Duration
AST
nnkStmtList.newTree(
nnkImportStmt.newTree(
nnkInfix.newTree(
newIdentNode("/"),
newIdentNode("std"),
newIdentNode("streams")
)
),
nnkConstSection.newTree(
nnkConstDef.newTree(
newIdentNode("hello"),
newEmptyNode(),
nnkBlockStmt.newTree(
newEmptyNode(),
nnkStmtList.newTree(
nnkLetSection.newTree(
nnkIdentDefs.newTree(
newIdentNode("strm"),
newEmptyNode(),
nnkCall.newTree(
newIdentNode("newStringStream"),
newLit("12345678")
)
)
),
nnkDotExpr.newTree(
newIdentNode("strm"),
newIdentNode("readFloat64")
)
)
)
)
),
nnkCommand.newTree(
newIdentNode("echo"),
newIdentNode("hello")
)
)
1.0.10 :-1: FAIL
Output
Error: Command failed: nim c --run -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
stack trace: (most recent call last)
/home/runner/work/Nim/Nim/temp.nim(4, 7)
/home/runner/.choosenim/toolchains/nim-1.0.10/lib/pure/streams.nim(805, 7) readFloat64
/home/runner/.choosenim/toolchains/nim-1.0.10/lib/pure/streams.nim(368, 14) read
/home/runner/.choosenim/toolchains/nim-1.0.10/lib/pure/streams.nim(225, 26) readData
/home/runner/.choosenim/toolchains/nim-1.0.10/lib/pure/streams.nim(1046, 27) ssReadData
/home/runner/.choosenim/toolchains/nim-1.0.10/lib/pure/streams.nim(1046, 27) Error: limited VM support for 'addr'
IR
Compiled filesize0 bytes (0 bytes)
Stats
- Started
2024-04-02T12:05:59 - Finished
2024-04-02T12:05:59 - Duration
AST
nnkStmtList.newTree(
nnkImportStmt.newTree(
nnkInfix.newTree(
newIdentNode("/"),
newIdentNode("std"),
newIdentNode("streams")
)
),
nnkConstSection.newTree(
nnkConstDef.newTree(
newIdentNode("hello"),
newEmptyNode(),
nnkBlockStmt.newTree(
newEmptyNode(),
nnkStmtList.newTree(
nnkLetSection.newTree(
nnkIdentDefs.newTree(
newIdentNode("strm"),
newEmptyNode(),
nnkCall.newTree(
newIdentNode("newStringStream"),
newLit("12345678")
)
)
),
nnkDotExpr.newTree(
newIdentNode("strm"),
newIdentNode("readFloat64")
)
)
)
)
),
nnkCommand.newTree(
newIdentNode("echo"),
newIdentNode("hello")
)
)
Stats
- GCC
11.4.0 - Clang
14.0.0 - NodeJS
19.1 - Created
2024-04-02T12:05:10Z - Comments
1 - Commands
nim c --run -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
:robot: Bug found in 18 minutes bisecting 7 commits at 0 commits per second
It doesn't seem that readFloat64 supports VM or JS
Likely related, the following example also doesn't work:
import std/[streams]
static:
var strm = newStringStream()
strm.write ""
Output:
Hint: used config file '/home/tsoj/.choosenim/toolchains/nim-#devel/config/nim.cfg' [Conf]
Hint: used config file '/home/tsoj/.choosenim/toolchains/nim-#devel/config/config.nims' [Conf]
......................................................................fatal.nim(53) sysFatal
Error: unhandled exception: field 'sym' is not accessible for type 'TNode' using 'kind = nkNilLit' [FieldDefect]
strm.write ""
VM was tended to support write but in fact doesn't.
write invokes writeData whenvm, which invokes writeDataImpl field.
But that field was skipped to initialized ^impl, thus nil.