nim-works/nimskull

indexing over a statically declared string with a statically declared int raises `FieldDefect`.

Open

#1,604 opened on Aug 29, 2025

 (1 comment) (0 reactions) (0 assignees)Nim (39 forks)auto 404
bugcompiler/msgsgood first issue

Repository metrics

Stars
 (346 stars)
PR merge metrics
 (PR metrics pending)

Description

Specification

When using a constant int that is higher than the length of a constant string (haven't tested arrays as a whole), the compiler crashes instead of giving a meaningful error message.

Example

discard "a"[1]

Actual Output

(Debug compiler)

nim.nim                  nim
nim.nim                  handleCmdLine
main.nim                 mainCommand
main.nim                 compileToBackend
main.nim                 commandCompileToC
modules.nim              compileProject
modules.nim              compileModule
passes.nim               processModule
passes.nim               processTopLevelStmt
sem.nim                  myProcess
sem.nim                  semStmtAndGenerateGenerics nkStmtList 383904 /var/home/chronos/test/main.nim(1, 0)
sempass2.nim             trackStmt
sempass2.nim             track
msgs.nim                 handleReport
cli_reporter.nim         legacyReportBridge
cli_reporter.nim         astDiagToLegacyReport
ast_types.nim            len
fatal.nim                sysFatal
Error: unhandled exception: field 'sons' is not accessible for type 'TNode' using 'kind = nkStrLit' [FieldDefect]

Expected Output

Either an index defect or an error at compile time.

Error: unhandled exception: index 1 not in 0 .. 0 [IndexDefect]

Possible Solution

Additional Information

References

Contributor guide