Skip to content

indexing over a statically declared string with a statically declared int raises FieldDefect. #1604

@Luyten-Orion

Description

@Luyten-Orion

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcompiler/msgsCompiler output and diagnostic subsystem: error and warnig reporting, information, debugginggood first issueEasy-to-start-with issue requiring no in-depth knowledge or complex implementation.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions