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

Associated constant defined via another associated constant cannot be compiled if used in entry functions #6544

Open
ironcev opened this issue Sep 13, 2024 · 0 comments
Labels
bug Something isn't working compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen compiler General compiler. Should eventually become more specific as the issue is triaged

Comments

@ironcev
Copy link
Member

ironcev commented Sep 13, 2024

If an associated constant is defined via another associated constant and used in entry functions (main, contract functions) compiler will emit an error that it cannot be initialized. E.g.:

script;

struct S {}

impl S {
    const S_A: u8 = 11;
    const S_B: u8 = Self::S_A;  // <<<--- S_B defined via S_A.
    // ERROR:             ^^^ Could not evaluate initializer to a const declaration.
}

fn main() {
    let _ = S::S_B; // <<<--- S_B used in main().
    // If we comment out the above line, the code compiles.
}

When fixing this issue, adjust the associated_const_in_decls_of_other_constants test which is linked to this issue via GitHub link in the test TODO.

@ironcev ironcev added bug Something isn't working compiler General compiler. Should eventually become more specific as the issue is triaged compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen labels Sep 13, 2024
ironcev added a commit that referenced this issue Sep 14, 2024
…ges (#6545)

## Description

This PR adds additional tests for constants. Those test cases are
important for the implementation of #6351 which will completely
restructure compilation of constants.

Tests for recursive `const` definitions should also be considered before
we start implementing `const fn` and `const trait`. In particular, we
want to better track and provide precise error messages in case of
unintended attempt to recursively define a constant in a complex
situation that includes `const fn` and `const trait`.

Related to #6534, #6537, #6538, #6539, #6540, #6543, and #6544.

## Checklist

- [x] I have linked to any relevant issues.
- [ ] I have commented my code, particularly in hard-to-understand
areas.
- [ ] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [ ] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen compiler General compiler. Should eventually become more specific as the issue is triaged
Projects
None yet
Development

No branches or pull requests

1 participant