nim-works/nimskull
Misleading error messages when trying to use nonexistant `[]=`
Aperta
#1490 aperta il 19 gen 2025
bugcompiler/semgood first issue
Metriche repository
- Star
- (346 stelle)
- Metriche merge PR
- (Nessuna PR mergiata in 30 g)
Descrizione
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 [].