nim-works/nimskull

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

开放

#1,604 创建于 2025年8月29日

 (1 条评论) (0 个反应) (0 位负责人)Nim (39 个派生)auto 404
bugcompiler/msgsgood first issue

仓库指标

星标
 (346 个星标)
PR 合并指标
 (30 天内没有已合并 PR)

描述

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

贡献者指南