nim-works/nimskull

Misleading error messages when trying to use nonexistant `[]=`

Open

#1,490 opened on Jan 19, 2025

 (4 comments) (0 reactions) (0 assignees)Nim (39 forks)auto 404
bugcompiler/semgood first issue

Repository metrics

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

Description

Example

type X = object
template `[]`(x: X, i: int) = 0
var x: X
x[0] = 1

Actual Output

bug.nim(5, 2) Error: type mismatch: got <X, int literal(0)>
but expected one of:
proc `[]`(s: string; i: BackwardsIndex): char
  first type mismatch at position: 0
      [ ... many examples later ... ]
template `[]`(x: X; i: int)
  first type mismatch at position: 0

expression: `[]`(x, 0)

Expected Output

bug.nim(5, 2) Error: type mismatch: got <X, int literal(0), int literal(1)>
but expected one of:
proc `[]=`(s: var string; i: BackwardsIndex; x: char)
  first type mismatch at position: 0
      [ ... many examples later ... ]

expression: `[]=`(x, 0, 1)

I was super confused because my [] template was appearing there, but didn't realize it was missing the []= and not [].

Contributor guide