You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think the Mojo compiler is not able to infer the correct types when there is a trait inheritance, and we use conditional conformance with two versions of the same method, like the __init__() below.
This is making a potential keyed-string x2 speed-up to fail: #3436
❯ mojo parametrized_traits.mojo
/home/msaelices/src/mojo-examples/parametrized_traits.mojo:37:20: error: no matching function in initialization
print(HashedKey(x).hash)
~~~~~~~~~^~~
/home/msaelices/src/mojo-examples/parametrized_traits.mojo:27:8: note: candidate not viable: could not deduce parameter 'K' of parent struct 'HashedKey'
fn __init__[K: Hashable](inout self, key: K):
^
/home/msaelices/src/mojo-examples/parametrized_traits.mojo:23:8: note: struct declared here
struct HashedKey[K: Hashable]:
^
/home/msaelices/src/mojo-examples/parametrized_traits.mojo:37:20: note: failed to infer parameter #0, parameter isn't used in any argument
print(HashedKey(x).hash)
~~~~~~~~~^~~
/home/msaelices/src/mojo-examples/parametrized_traits.mojo:31:8: note: candidate not viable: could not deduce parameter 'K' of parent struct 'HashedKey'
fn __init__[K: SizedHashable](inout self, key: K):
^
/home/msaelices/src/mojo-examples/parametrized_traits.mojo:23:8: note: struct declared here
struct HashedKey[K: Hashable]:
^
/home/msaelices/src/mojo-examples/parametrized_traits.mojo:37:20: note: failed to infer parameter #0, parameter isn't used in any argument
print(HashedKey(x).hash)
~~~~~~~~~^~~
/home/msaelices/src/mojo-examples/parametrized_traits.mojo:28:20: error: cannot implicitly convert 'K' value to 'K' in assignment
self.key = key
^~~
/home/msaelices/src/mojo-examples/parametrized_traits.mojo:32:20: error: cannot implicitly convert 'K' value to 'K' in assignment
self.key = key
^~~
mojo: error: failed to parse the provided Mojo source module
It's funny to receive a cannot implicitly convert 'K' value to 'K' in assignment error :)
Thanks to @helehex , I know that it can be fixed by explicitly type the self object, like so:
msaelices
changed the title
[BUG] Cannot implicitly convert 'K' value to 'K' in assignment in parametrized traits
[BUG] cannot implicitly convert 'K' value to 'K' in assignment in parametrized traits
Aug 31, 2024
msaelices
changed the title
[BUG] cannot implicitly convert 'K' value to 'K' in assignment in parametrized traits
[BUG] cannot implicitly convert 'K' value to 'K' in assignment in condicional conformance
Aug 31, 2024
Bug description
I think the Mojo compiler is not able to infer the correct types when there is a trait inheritance, and we use conditional conformance with two versions of the same method, like the
__init__()
below.This is making a potential keyed-string x2 speed-up to fail: #3436
Steps to reproduce
Test code for reproducing the issue:
This is the error when compiling:
It's funny to receive a
cannot implicitly convert 'K' value to 'K' in assignment
error :)Thanks to @helehex , I know that it can be fixed by explicitly type the
self
object, like so:To me, this should not be needed and be inferred by the compiler.
System information
❯ cat /etc/lsb-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=22.04 DISTRIB_CODENAME=jammy DISTRIB_DESCRIPTION="Ubuntu 22.04.4 LTS"
The text was updated successfully, but these errors were encountered: