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

Crash when applying foreach to dynamically sized array #193

Closed
marcauberer opened this issue Aug 25, 2022 · 2 comments · Fixed by #208
Closed

Crash when applying foreach to dynamically sized array #193

marcauberer opened this issue Aug 25, 2022 · 2 comments · Fixed by #208
Assignees
Labels
bug Something isn't working
Milestone

Comments

@marcauberer
Copy link
Member

From the Sudoku example:

foreach int[size] row : grid {
    foreach int cell : row {
        printf("%d ", cell);
    }
    printf("\n");
}
@marcauberer marcauberer added the bug Something isn't working label Aug 25, 2022
@marcauberer marcauberer added this to the 0.11.0 milestone Aug 25, 2022
@marcauberer marcauberer self-assigned this Aug 25, 2022
@marcauberer marcauberer modified the milestones: 0.11.0, 0.12.0 Sep 13, 2022
@marcauberer marcauberer changed the title Crash wen applying foreach to dynamically sized array Crash when applying foreach to dynamically sized array Oct 6, 2022
@marcauberer
Copy link
Member Author

marcauberer commented Oct 6, 2022

After further investigation it turns out that the real problem is another one.

This works:

p print(int[SIZE][SIZE] _) {
    int[SIZE][SIZE] grid = {
        { 3, 0, 6, 5, 0, 8, 4, 0, 0 },
        { 5, 2, 0, 0, 0, 0, 0, 0, 0 },
        { 0, 8, 7, 0, 0, 0, 0, 3, 1 },
        { 0, 0, 3, 0, 1, 0, 0, 8, 0 },
        { 9, 0, 0, 8, 6, 3, 0, 0, 5 },
        { 0, 5, 0, 0, 9, 0, 6, 0, 0 },
        { 1, 3, 0, 0, 0, 0, 2, 5, 0 },
        { 0, 0, 0, 0, 0, 0, 0, 7, 4 },
        { 0, 0, 5, 2, 0, 6, 3, 0, 0 }
    };

    foreach int[SIZE] row : grid {
        foreach int cell : row {
            printf("%d ", cell);
        }
        printf("\n");
    }
}

while this crashes the compiler:

p print(int[SIZE][SIZE] grid) {
    foreach int[SIZE] row : grid {
        foreach int cell : row {
            printf("%d ", cell);
        }
        printf("\n");
    }
}

So it seams that parameters behave differently than var declarations.

@marcauberer marcauberer mentioned this issue Oct 7, 2022
marcauberer added a commit that referenced this issue Oct 8, 2022
@marcauberer
Copy link
Member Author

The solution is now to not allow dynamically sized arrays as function/procedure parameters.

marcauberer added a commit that referenced this issue Oct 8, 2022
* Rename arg to param

* Fix #193
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant