modularml / mojo

The Mojo Programming Language
https://docs.modular.com/mojo/manual/
Other
22.92k stars 2.58k forks source link

[BUG] Redefinition of method with identical signatures when they're different #3137

Open gabrieldemarmiesse opened 2 months ago

gabrieldemarmiesse commented 2 months ago

Bug description

I get the following error:

$ mojo trying_stuff2.mojo
/projects/open_source/mojo/trying_stuff2.mojo:5:8: error: redefinition of function '__init__' with identical signature
    fn __init__(inout self, *, some_other_arg: Self):
       ^
/projects/open_source/mojo/trying_stuff2.mojo:2:8: note: previous definition here
    fn __init__(inout self, some_arg: Self):
       ^
mojo: error: failed to parse the provided Mojo source module

While the two signatures are clearly different. it's not possible to have ambiguity in the call of the constructor, so there is no reason for the compiler to disallow it.

Steps to reproduce

struct Something:
    fn __init__(inout self, some_arg: Self):
        pass

    fn __init__(inout self, *, some_other_arg: Self):
        pass

System information

Ubuntu
modular 0.8.0 (39a426b5)
mojo 2024.6.2805 (512c667b)
ematejska commented 2 months ago

Reproduces with mojo 2024.7.1005 (a9695bc7)