mojo icon indicating copy to clipboard operation
mojo copied to clipboard

[BUG]: `[]` notation of `Dictionary` doesn't pick the right overload

Open soraros opened this issue 11 months ago • 0 comments

Bug description

There are two overloads:

fn __setitem__(self: Self, key: PythonObject, value: PythonObject): ...
# and
fn __setitem__(self: Self, key: PythonObject, value: Self): ...

and the compiler is not able to pick the second one when [] notation is used.

Steps to reproduce

from python import Python as py

fn main() raises:
  var d = py.dict()
  d["test"] = d             # error: cannot implicitly convert 'Dictionary' value to 'PythonObject' in assignment
  d.__setitem__("test", d)  # works fine

System information

Mojo 24.1 on Docker, Intel Mac

soraros avatar Mar 08 '24 18:03 soraros