Skip to content

Commit

Permalink
add specific error for attempting string[x] = ".."
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljklein committed Mar 21, 2024
1 parent 13eb71b commit f603355
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion compiler/noirc_frontend/src/hir/type_check/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ pub enum TypeCheckError {
method_name: String,
span: Span,
},
#[error("Strings do not support indexed assignment")]
StringIndexAssign { span: Span },
}

impl TypeCheckError {
Expand Down Expand Up @@ -237,7 +239,8 @@ impl From<TypeCheckError> for Diagnostic {
| TypeCheckError::ConstrainedReferenceToUnconstrained { span }
| TypeCheckError::UnconstrainedReferenceToConstrained { span }
| TypeCheckError::UnconstrainedSliceReturnToConstrained { span }
| TypeCheckError::NonConstantSliceLength { span } => {
| TypeCheckError::NonConstantSliceLength { span }
| TypeCheckError::StringIndexAssign { span } => {
Diagnostic::simple_error(error.to_string(), String::new(), span)
}
TypeCheckError::PublicReturnType { typ, span } => Diagnostic::simple_error(
Expand Down
7 changes: 7 additions & 0 deletions compiler/noirc_frontend/src/hir/type_check/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,13 @@ impl<'interner> TypeChecker<'interner> {
Type::Array(_, elem_type) => *elem_type,
Type::Slice(elem_type) => *elem_type,
Type::Error => Type::Error,
Type::String(_) => {
let (_lvalue_name, lvalue_span) = self.get_lvalue_name_and_span(&lvalue);
self.errors.push(TypeCheckError::StringIndexAssign {
span: lvalue_span,
});
Type::Error
}
other => {
// TODO: Need a better span here
self.errors.push(TypeCheckError::TypeMismatch {
Expand Down

0 comments on commit f603355

Please sign in to comment.