Skip to content

bogus error when the RHS of Table.[]= is not a compatible type #1439

Open
@alaviss

Description

@alaviss

Example

import std/tables

var o: Table[int, string]
o[0] = 0

Actual Output

test.nim(4, 2) Error: type mismatch: got <Table[system.int, system.string], int literal(0)>
but expected one of:
proc `[]`(s: string; i: BackwardsIndex): char
  first type mismatch at position: 0
proc `[]`(s: var string; i: BackwardsIndex): var char
  first type mismatch at position: 0
proc `[]`[A, B](t: OrderedTableRef[A, B]; key: A): var B
  first type mismatch at position: 0
proc `[]`[A, B](t: OrderedTable[A, B]; key: A): B
  first type mismatch at position: 0
proc `[]`[A, B](t: TableRef[A, B]; key: A): var B
  first type mismatch at position: 0
proc `[]`[A, B](t: Table[A, B]; key: A): B
  first type mismatch at position: 0
proc `[]`[A, B](t: var OrderedTable[A, B]; key: A): var B
  first type mismatch at position: 0
proc `[]`[A, B](t: var Table[A, B]; key: A): var B
  first type mismatch at position: 0
proc `[]`[A](t: CountTableRef[A]; key: A): int
  first type mismatch at position: 0
proc `[]`[A](t: CountTable[A]; key: A): 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: Ordinal](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: Ordinal](s: string; x: HSlice[T, U]): string
  first type mismatch at position: 0
proc `[]`[T; U, V: Ordinal](s: openArray[T]; x: HSlice[U, V]): seq[T]
  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 `[]`(a: WideCStringObj; idx: int): Utf16Char
  first type mismatch at position: 0
template `[]`(s: string; i: int): char
  first type mismatch at position: 0

expression: `[]`(o, 0)

Expected Output

Something that says the last 0 is not a compatible type

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcompiler/semRelated to semantic-analysis system of the compiler

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions