mojo
mojo copied to clipboard
[BUG] Cannot call function with same name that is outside struct
Bug Description
If you have a function with the same name inside and outside a struct, then you cannot call the function that it outside the struct from the function that is in the struct. The code example explains this better:
Steps to Reproduce
fn do_something(a: Int, b: Int):
print(a, b)
@value
struct Struct:
var a: Int
var b: Int
fn do_something(self):
do_something(self.a, self.b)
Error:
error: Expression [2]:14:9: cannot access method 'do_something' directly; did you mean 'self.'?
do_something(self.a, self.b)
^~~~~~~~~~~~
self.
Context
This might be intended: https://docs.modular.com/mojo/changelog.html#week-of-2023-02-13
Although if it should be can be debated.
It's not "intended" to be a limitation, but it is a current limitation.
@willghatch fixed this! This in the next release you will be able to access declarations outside structs.
That's awesome! Thanks :D