modular
modular copied to clipboard
[BUG] Redefinition of method with identical signatures when they're different
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)
Reproduces with mojo 2024.7.1005 (a9695bc7)
It's been fixed as of mojo 25.1.0.dev2025011705 (92b12ebe), the following compiles successfully:
struct Something:
fn __init__(out self):
print("init")
fn __init__(out self, some_arg: Self):
print("first init")
fn __init__(out self, *, some_other_arg: Self):
print("second init")
fn main():
s = Something()
s2 = Something(s)
s3 = Something(some_other_arg=s)