mojo icon indicating copy to clipboard operation
mojo copied to clipboard

[BUG] Cannot call function with same name that is outside struct

Open sa- opened this issue 1 year ago • 2 comments

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

sa- avatar May 24 '23 21:05 sa-

This might be intended: https://docs.modular.com/mojo/changelog.html#week-of-2023-02-13

Although if it should be can be debated.

DayDun avatar May 24 '23 22:05 DayDun

It's not "intended" to be a limitation, but it is a current limitation.

Mogball avatar May 24 '23 23:05 Mogball

@willghatch fixed this! This in the next release you will be able to access declarations outside structs.

Mogball avatar Jul 18 '23 18:07 Mogball

That's awesome! Thanks :D

sa- avatar Jul 18 '23 18:07 sa-