Skip to content

Table.withValue: compiler IndexDefect when using >= with imported overloads #25655

@fox0430

Description

@fox0430

Nim Version

Nim Compiler Version 2.3.1 [Linux: amd64]
Compiled at 2026-03-25
Copyright (c) 2006-2026 by Andreas Rumpf

git hash: 158d59c
active boot switches: -d:release

Description

The compiler crashes with IndexDefect: index 1 not in 0 .. 0 when using >= or > on a dereferenced withValue pointer, if a separate module defines func >= overloads.

# dep.nim

type Foo* = distinct int

func `>=`*(a, b: Foo): bool {.inline.} = int(a) >= int(b)
# main.nim

import std/tables

import dep

proc f() =
  var t = initTable[string, int]()
  t.withValue("k", v):
    if v[] >= 0:  # CRASH: >= with v[] dereference + imported >= overloads
      discard

Notes

  • <, <=, ==, != do not crash
  • let x = v[]; if x >= 0: does not crash
  • Defining func >= in the same file does not crash — must be imported

Current Output

Hint: used config file '/home/user/.local/share/grabnim/nim-devel/config/nim.cfg' [Conf]
Hint: used config file '/home/user/.local/share/grabnim/nim-devel/config/config.nims' [Conf]
Hint: used config file '/home/user/Nim/async-kafka/tests/config.nims' [Conf]
....................................................................................fatal.nim(62)            sysFatal
Error: unhandled exception: index 1 not in 0 .. 0 [IndexDefect]

Expected Output


Known Workarounds

No response

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions