Skip to content

Commit

Permalink
address review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomocavalieri committed Dec 16, 2024
1 parent d280253 commit ffbca4f
Showing 1 changed file with 21 additions and 29 deletions.
50 changes: 21 additions & 29 deletions compiler-core/src/type_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,29 +442,35 @@ impl Type {
///
pub fn same_as(&self, other: &Self) -> bool {
match (self, other) {
(Type::Named { .. }, Type::Fn { .. } | Type::Tuple { .. }) => false,
(one @ Type::Named { .. }, Type::Var { type_ }) => {
type_.as_ref().borrow().same_as_other_type(one)
(Type::Var { type_: var }, type_) | (type_, Type::Var { type_: var }) => {
var.as_ref().borrow().same_as_other_type(type_)
}

(Type::Named { .. }, Type::Fn { .. } | Type::Tuple { .. }) => false,
(
Type::Named {
package,
module,
name,
args,
..
},
Type::Named {
package: other_package,
module: other_module,
name: other_name,
args: other_args,
..
},
) => package == other_package && module == other_module && name == other_name,
) => {
package == other_package
&& module == other_module
&& name == other_name
&& args == other_args
}

(Type::Fn { .. }, Type::Named { .. } | Type::Tuple { .. }) => false,
(one @ Type::Fn { .. }, Type::Var { type_ }) => {
type_.as_ref().borrow().same_as_other_type(one)
}

(
Type::Fn { args, retrn },
Type::Fn {
Expand All @@ -480,12 +486,7 @@ impl Type {
&& retrn.same_as(other_retrn)
}

(Type::Var { type_ }, other) => type_.as_ref().borrow().same_as_other_type(other),

(Type::Tuple { .. }, Type::Fn { .. } | Type::Named { .. }) => false,
(one @ Type::Tuple { .. }, Type::Var { type_ }) => {
type_.as_ref().borrow().same_as_other_type(one)
}
(Type::Tuple { elems }, Type::Tuple { elems: other_elems }) => {
elems.len() == other_elems.len()
&& elems
Expand Down Expand Up @@ -526,27 +527,18 @@ impl TypeVar {
#[must_use]
fn same_as(&self, other: &Self) -> bool {
match (self, other) {
(TypeVar::Unbound { id }, TypeVar::Unbound { id: other_id }) => id == other_id,
(TypeVar::Unbound { .. }, TypeVar::Generic { .. }) => false,
(one @ TypeVar::Unbound { .. }, TypeVar::Link { type_ }) => {
one.same_as_other_type(type_)
}

(TypeVar::Link { type_ }, TypeVar::Link { type_: other_type }) => {
type_.same_as(other_type)
}
(TypeVar::Link { type_ }, other @ TypeVar::Unbound { .. }) => {
other.same_as_other_type(type_)
}
(TypeVar::Link { type_ }, other @ TypeVar::Generic { .. }) => {
other.same_as_other_type(type_)
}

(TypeVar::Generic { id }, TypeVar::Generic { id: other_id }) => id == other_id,
(TypeVar::Generic { .. }, TypeVar::Unbound { .. }) => false,
(one @ TypeVar::Generic { .. }, TypeVar::Link { type_ }) => {
one.same_as_other_type(type_)
}
(type_var, TypeVar::Link { type_: link })
| (TypeVar::Link { type_: link }, type_var) => type_var.same_as_other_type(link),

(TypeVar::Unbound { id }, TypeVar::Unbound { id: other_id })
| (TypeVar::Generic { id }, TypeVar::Generic { id: other_id }) => id == other_id,

(TypeVar::Unbound { .. }, TypeVar::Generic { .. })
| (TypeVar::Generic { .. }, TypeVar::Unbound { .. }) => false,
}
}
}
Expand Down

0 comments on commit ffbca4f

Please sign in to comment.