Skip to content

const variables declared not in global scope don't seem to be respecting the const keyword #2076

@mohammadfawaz

Description

@mohammadfawaz

The following compiles but X is not actually constant evaluated. If we move the definition of X to the global scope, then we get an error saying Could not evaluate initializer to a const declaration. as expected.

script;

fn bla(x: u64) -> u64 {
    x + 1
}

fn main() -> u64 {
    const X = bla(0);
    X
}

It is possible that this behavior is desirable. If so, we should properly document it. If not, then this is a bug.

Metadata

Metadata

Assignees

Labels

P: criticalShould be looked at before anything elsebugSomething isn't workingcompiler: frontendEverything to do with type checking, control flow analysis, and everything between parsing and IRgencompiler: irIRgen and sway-ir including optimization passesteam:compilerCompiler Team

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions