Skip to content

Commit

Permalink
fix: alternate approach
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Vitkov committed Aug 7, 2023
1 parent c6e4d88 commit dfc0ba0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
11 changes: 0 additions & 11 deletions crates/noirc_frontend/src/hir/type_check/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,6 @@ impl<'interner> TypeChecker<'interner> {
source: Source::Assignment,
}
});

if let (Type::Function(_, _, env_a), Type::Function(_, _, env_b)) =
(&lvalue_type, &expr_type)
{
env_a.unify(env_b, span, &mut self.errors, || TypeCheckError::TypeMismatchWithSource {
rhs: expr_type.clone(),
lhs: lvalue_type.clone(),
span,
source: Source::Assignment,
});
}
}

/// Type check an lvalue - the left hand side of an assignment statement.
Expand Down
8 changes: 6 additions & 2 deletions crates/noirc_frontend/src/hir_def/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1206,12 +1206,14 @@ impl Type {
}
}

(Function(params_a, ret_a, _env_a), Function(params_b, ret_b, _env_b)) => {
(Function(params_a, ret_a, env_a), Function(params_b, ret_b, env_b)) => {
if params_a.len() == params_b.len() {
for (a, b) in params_a.iter().zip(params_b.iter()) {
a.try_unify(b, span)?;
}

env_a.try_unify(env_b, span)?;

ret_b.try_unify(ret_a, span)
} else {
Err(SpanKind::None)
Expand Down Expand Up @@ -1413,12 +1415,14 @@ impl Type {
}
}

(Function(params_a, ret_a, _env_a), Function(params_b, ret_b, _env_b)) => {
(Function(params_a, ret_a, env_a), Function(params_b, ret_b, env_b)) => {
if params_a.len() == params_b.len() {
for (a, b) in params_a.iter().zip(params_b) {
a.is_subtype_of(b, span)?;
}

env_a.is_subtype_of(env_b, span)?;

// return types are contravariant, so this must be ret_b <: ret_a instead of the reverse
ret_b.is_subtype_of(ret_a, span)
} else {
Expand Down

0 comments on commit dfc0ba0

Please sign in to comment.