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] Compiler reporting argument exclusivity issue misleadingly. #3855

Open
samufi opened this issue Dec 10, 2024 · 0 comments
Open

[BUG] Compiler reporting argument exclusivity issue misleadingly. #3855

samufi opened this issue Dec 10, 2024 · 0 comments
Labels
bug Something isn't working mojo-repo Tag all issues with this label

Comments

@samufi
Copy link

samufi commented Dec 10, 2024

Bug description

When constructing a function with a ref argument and an argument exclusivity issue, the compiler gives a misleading error message.

Steps to reproduce

Consider the folloeing code:

@value
struct MyElement:
    var a: Int

struct MyType:
    var a: Int
    var l: List[MyElement]
    
    fn __init__(inout self, a: Int):
        self.a = a
        self.l = List[MyElement]()

    fn do(inout self, ref[self.l] e: MyElement, b: Int):
        e.a = b
        self.a = b

fn main():
    t = MyType(1)
    t.l.append(MyElement(1))
    t.do(t.l[0], 1)

Here, do should be invalid, as it violates argument exclusivity. However, the compiler errors with

error: invalid call to 'do': method argument #0 cannot be converted from 'MyElement' to 'Reference['MyElement', ...]
    t.do(t.l[0], 1)
    ~~~~^~~~~~~~~~~
note: operand origin 't.l' doesn't match expected origin '*[0,0].l'
    t.do(t.l[0], 1)
            ^
function declared here
    fn do(inout self, ref[self.l] e: MyElement, b: Int):
       ^
mojo: error: failed to parse the provided Mojo source module

System information

- Ubuntu 22.04.5 in WSL 2 on Windows 10
- mojo 24.6.0.dev2024120105 (78dab9b8)
- magic 0.4.0 - (based on pixi 0.33.0)
@samufi samufi added bug Something isn't working mojo-repo Tag all issues with this label labels Dec 10, 2024
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

1 participant