-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Labels
Description
sigmatch error is unhelpful and incorrect with []
Example
type Foo* = object
type Idx = csize_t
proc `[]`(s: var Foo, idx: Idx): int = discard
var a: Foo
for i in 0..<3: discard a[i]
Current Output
several bugs:
- position is incorrect (0 vs 1)
- showAllMismatches:on trick isn't used
- extended diagnostic isn't shown
Error: type mismatch: got <Foo, int>
but expected one of:
proc `[]`(s: string; i: BackwardsIndex): char
first type mismatch at position: 0
proc `[]`(s: var Foo; idx: Idx): int
first type mismatch at position: 0
proc `[]`[I: Ordinal; T](a: T; i: I): T
first type mismatch at position: 0
proc `[]`[Idx, T, U, V](a: array[Idx, T]; x: HSlice[U, V]): seq[T]
first type mismatch at position: 0
proc `[]`[Idx, T](a: array[Idx, T]; i: BackwardsIndex): T
first type mismatch at position: 0
proc `[]`[Idx, T](a: var array[Idx, T]; i: BackwardsIndex): var T
first type mismatch at position: 0
proc `[]`[T, U, V](s: openArray[T]; x: HSlice[U, V]): seq[T]
first type mismatch at position: 0
proc `[]`[T, U](s: string; x: HSlice[T, U]): string
first type mismatch at position: 0
proc `[]`[T](s: openArray[T]; i: BackwardsIndex): T
first type mismatch at position: 0
proc `[]`[T](s: var openArray[T]; i: BackwardsIndex): var T
first type mismatch at position: 0
template `[]`(s: string; i: int): char
first type mismatch at position: 0
expression: `[]`(a, i)
for i in 0..<3: discard a[i]
Expected Output
same as for other procs, eg:
when true:
type Foo* = object
type Idx = csize_t
proc get(s: var Foo, idx: Idx): int = discard
proc get(s: var string, idx: Idx): int = discard
var a: Foo
for i in 0..<3: discard a.get(i)
Error: type mismatch: got <Foo, int>
but expected one of:
proc get(s: var Foo; idx: Idx): int
first type mismatch at position: 2
required type for idx: Idx
but expression 'i' is of type: int
1 other mismatching symbols have been suppressed; compile with --showAllMismatches:on to see them
expression: get(a, i)
for i in 0..<3: discard a.get(i)
Possible Solution
- fix this so that it works like for other procs;
[]
should not be special - (unrelated) I also want to show where the symbol is defined (trivial PR away, the code is already there for 'declared at xxx`)
Additional Information
devel 1.3.5 754a196d4739b17fc0783d8e4b025d38bbcc4e32