Skip to content

Commit

Permalink
Merge ece9ced into 8712f4c
Browse files Browse the repository at this point in the history
  • Loading branch information
jfecher authored Sep 11, 2024
2 parents 8712f4c + ece9ced commit 69228bc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions compiler/noirc_frontend/src/elaborator/statements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,13 @@ impl<'context> Elaborator<'context> {
} else {
if let Some(definition) = self.interner.try_definition(ident.id) {
mutable = definition.mutable;

if definition.comptime && !self.in_comptime_context() {
self.push_err(ResolverError::MutatingComptimeInNonComptimeContext {
name: definition.name.clone(),
span: ident.location.span,
});
}
}

let typ = self.interner.definition_type(ident.id).instantiate(self.interner).0;
Expand Down
9 changes: 9 additions & 0 deletions compiler/noirc_frontend/src/hir/resolution/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ pub enum ResolverError {
QuoteInRuntimeCode { span: Span },
#[error("Comptime-only type `{typ}` cannot be used in runtime code")]
ComptimeTypeInRuntimeCode { typ: String, span: Span },
#[error("Comptime variable `{name}` cannot be mutated in a non-comptime context")]
MutatingComptimeInNonComptimeContext { name: String, span: Span },
}

impl ResolverError {
Expand Down Expand Up @@ -522,6 +524,13 @@ impl<'a> From<&'a ResolverError> for Diagnostic {
*span,
)
},
ResolverError::MutatingComptimeInNonComptimeContext { name, span } => {
Diagnostic::simple_error(
format!("Comptime variable `{name}` cannot be mutated in a non-comptime context"),
format!("`{name}` mutated here"),
*span,
)
},
}
}
}

0 comments on commit 69228bc

Please sign in to comment.