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 error when storing function whose input/output types are parameterized in struct #2788

Closed
Brian-M-J opened this issue May 22, 2024 · 0 comments
Labels
bug Something isn't working mojo-repo Tag all issues with this label

Comments

@Brian-M-J
Copy link
Contributor

Brian-M-J commented May 22, 2024

Bug description

When running the code snippet below, I get the following compiler error:

/source/prog.mojo:14:37: error: invalid initialization: argument #1 cannot be converted from 'fn(num: Int) -> String' to 'fn(Int) -> String'
    var a = FuncyStruct[Int, String](convert)
            ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
/source/prog.mojo:2:8: note: function declared here
struct FuncyStruct[I: AnyType, O: AnyType]:
       ^
mojo: error: failed to parse the provided Mojo source module

I was expecting the code to work fine and print 16. The compiler seems to consider the argument name as part of the type of the function. That's just an implementation detail and shouldn't be important to it.

Steps to reproduce

Run the following code to reproduce the error:

@value
struct FuncyStruct[I: AnyType, O: AnyType]:
    var func: fn (I) -> O
 
    fn apply(self, in_: I) -> O:
        return self.func(in_)
 
 
fn convert(num: Int) -> String:
    return str(num + 10)
 
 
fn main():
    var a = FuncyStruct[Int, String](convert)
    print(a.apply(6))
 

System information

The Mojo Playground as of 22-05-2024.
@Brian-M-J Brian-M-J added bug Something isn't working mojo-repo Tag all issues with this label labels May 22, 2024
@linear linear bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 18, 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