Skip to content

Commit

Permalink
fix: Improve error message when multiplying unit values (noir-lang#2950)
Browse files Browse the repository at this point in the history
  • Loading branch information
jfecher authored and Sakapoi committed Oct 19, 2023
1 parent e25ffd7 commit 8f95f78
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
7 changes: 4 additions & 3 deletions compiler/noirc_frontend/src/hir/type_check/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use thiserror::Error;
use crate::hir::resolution::errors::ResolverError;
use crate::hir_def::expr::HirBinaryOp;
use crate::hir_def::types::Type;
use crate::BinaryOpKind;
use crate::FunctionReturnType;
use crate::Signedness;

Expand All @@ -23,8 +24,8 @@ pub enum Source {
StringLen,
#[error("Comparison")]
Comparison,
#[error("BinOp")]
BinOp,
#[error("{0}")]
BinOp(BinaryOpKind),
#[error("Return")]
Return(FunctionReturnType, Span),
}
Expand Down Expand Up @@ -218,7 +219,7 @@ impl From<TypeCheckError> for Diagnostic {
Source::ArrayLen => format!("Can only compare arrays of the same length. Here LHS is of length {expected}, and RHS is {actual}"),
Source::StringLen => format!("Can only compare strings of the same length. Here LHS is of length {expected}, and RHS is {actual}"),
Source::Comparison => format!("Unsupported types for comparison: {expected} and {actual}"),
Source::BinOp => format!("Unsupported types for binary operation: {expected} and {actual}"),
Source::BinOp(kind) => format!("Unsupported types for operator `{kind}`: {expected} and {actual}"),
Source::Return(ret_ty, expr_span) => {
let ret_ty_span = match ret_ty.clone() {
FunctionReturnType::Default(span) => span,
Expand Down
4 changes: 1 addition & 3 deletions compiler/noirc_frontend/src/hir/type_check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1060,8 +1060,6 @@ impl<'interner> TypeChecker<'interner> {
Err(TypeCheckError::InvalidInfixOp { kind: "Tuples", span })
}

(Unit, _) | (_, Unit) => Ok(Unit),

// The result of two Fields is always a witness
(FieldElement, FieldElement) => {
if op.is_bitwise() {
Expand All @@ -1075,7 +1073,7 @@ impl<'interner> TypeChecker<'interner> {
(lhs, rhs) => Err(TypeCheckError::TypeMismatchWithSource {
expected: lhs.clone(),
actual: rhs.clone(),
source: Source::BinOp,
source: Source::BinOp(op.kind),
span,
}),
}
Expand Down

0 comments on commit 8f95f78

Please sign in to comment.