Skip to content

Misleading error messages when trying to use nonexistant []= #1490

Open
@DiThi

Description

@DiThi

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 [].

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcompiler/semRelated to semantic-analysis system of the compilergood first issueEasy-to-start-with issue with no in-depth knowledge or complex implementation required.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions