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] Using a default value for a List of functions attribute of a struct leads to an OOB error upon access. #3285

Open
thatstoasty opened this issue Jul 22, 2024 · 1 comment
Labels
bug Something isn't working mojo-repo Tag all issues with this label

Comments

@thatstoasty
Copy link
Contributor

thatstoasty commented Jul 22, 2024

Bug description

Given a Struct like

struct A():
    var funcs: List[fn() -> None]

Specifying a default argument value for funcs in the __init__() function signature leads to an OOB error when attempting to access the functions.

Steps to reproduce

Example

fn test() -> None:
    return None


struct Dummy():
    var funcs: List[fn() -> None]

    fn __init__(inout self, funcs: List[fn() -> None] = List[fn() -> None](test)):
        self.funcs = funcs

fn main() raises:
    var d = Dummy()
    for func in d.funcs:
        func[]()

System information

- What OS did you do install Mojo on ? MacOS 14.5
- Provide version information for Mojo by pasting the output of `mojo -v` mojo 2024.7.2205 (9b0e6242)
- Provide Modular CLI version by pasting the output of `modular -v` modular 0.7.1 (28ddab26)
@thatstoasty thatstoasty added bug Something isn't working mojo-repo Tag all issues with this label labels Jul 22, 2024
@thatstoasty
Copy link
Contributor Author

Possibly related to #3126, but this issue still persists. It seems like it has something to do with compile time. When the List of functions is given as a default argument, the pointers to the functions show up as 0x0 when inspecting the List in the debugger. But they only show up as 0x0 when iterating over the list, the pointer addresses look correct up until that point.

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