Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Can't create the trait Divmodable #2597

Open
gabrieldemarmiesse opened this issue May 9, 2024 · 1 comment
Open

[BUG] Can't create the trait Divmodable #2597

gabrieldemarmiesse opened this issue May 9, 2024 · 1 comment
Labels
bug Something isn't working mojo-repo Tag all issues with this label

Comments

@gabrieldemarmiesse
Copy link
Contributor

gabrieldemarmiesse commented May 9, 2024

Bug description

The goal here was to create a trait Divmodable which accepts anything implementing __divmod__. By trying to do this, we get a very strange error. See below. Maybe I'm just misusing traits and I'm missing something.

Steps to reproduce

trait Divmodable(CollectionElement):
    fn __divmod__(self: Self, other: Self) -> Tuple[Self, Self]:
        ...
 
def main():
    pass
$ mojo trying_stuff.mojo
/projects/open_source/mojo/trying_stuff.mojo:3:53: error: no '__copyinit__' candidates have type 'fn(inout self: T, existing: T, /) -> None'
    fn __divmod__(self: Self, other: Self) -> Tuple[Self, Self]:
                                                    ^~~~
/projects/open_source/mojo/trying_stuff.mojo:3:53: error: 'Tuple' parameter #0 has 'CollectionElement' type, but value has type 'Divmodable'
    fn __divmod__(self: Self, other: Self) -> Tuple[Self, Self]:
                                                    ^~~~
/projects/open_source/mojo/trying_stuff.mojo:1:1: note: 'Tuple' declared here
 
^
mojo: error: failed to parse the provided Mojo source module

System information

ubuntu 22.04 in wsl

modular 0.7.2 (d0adc668)
mojo 2024.5.822 (2cfed0ad)
@gabrieldemarmiesse gabrieldemarmiesse added bug Something isn't working mojo-repo Tag all issues with this label labels May 9, 2024
Copy link
Collaborator

Errors are updated with the latest nightly build (mojo 2024.5.2805 (87564503)):

error: no '__moveinit__' candidates have type 'fn(inout self: T, owned existing: T, /) -> None'

    fn __divmod__(self: Self, other: Self) -> Tuple[Self, Self]:

                                                    ^~~~

error: 'Tuple' parameter #0 has 'Movable' type, but value has type 'Divmodable'

    fn __divmod__(self: Self, other: Self) -> Tuple[Self, Self]:

                                                    ^~~~

note: 'Tuple' declared here

trait Divmodable(CollectionElement):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mojo-repo Tag all issues with this label
Projects
None yet
Development

No branches or pull requests

2 participants