This commit is contained in:
pca006132 2021-07-16 13:59:08 +08:00
parent 62736bd4bf
commit 8b078dfa1b
2 changed files with 10 additions and 10 deletions

View File

@ -216,7 +216,7 @@ mod test {
("v2", "List[int]"), ("v2", "List[int]"),
], ],
(("v1", "v2"), "Cannot unify TTuple with TList") (("v1", "v2"), "Cannot unify TTuple with TList")
; "kind mismatch" ; "type mismatch"
)] )]
#[test_case(2, #[test_case(2,
&[ &[

View File

@ -164,7 +164,7 @@ impl TypeEnum {
} }
// e.g. List <: Var // e.g. List <: Var
pub fn kind_le(&self, other: &TypeEnum) -> bool { pub fn type_le(&self, other: &TypeEnum) -> bool {
let a = self.get_int(); let a = self.get_int();
let b = other.get_int(); let b = other.get_int();
(a % b) == 0 (a % b) == 0
@ -236,7 +236,7 @@ impl Unifier {
let (ty_a, ty_b) = { let (ty_a, ty_b) = {
// simplify our pattern matching... // simplify our pattern matching...
if ty_a_cell.borrow().kind_le(&ty_b_cell.borrow()) { if ty_a_cell.borrow().type_le(&ty_b_cell.borrow()) {
swap(&mut a, &mut b); swap(&mut a, &mut b);
swap(&mut ty_a_cell, &mut ty_b_cell); swap(&mut ty_a_cell, &mut ty_b_cell);
} }
@ -289,7 +289,7 @@ impl Unifier {
self.set_a_to_b(a, b); self.set_a_to_b(a, b);
} }
_ => { _ => {
return self.report_kind_error(&*ty_a, &*ty_b); return self.incompatible_types(&*ty_a, &*ty_b);
} }
} }
} }
@ -307,7 +307,7 @@ impl Unifier {
} }
self.set_a_to_b(a, b); self.set_a_to_b(a, b);
} else { } else {
return self.report_kind_error(&*ty_a, &*ty_b); return self.incompatible_types(&*ty_a, &*ty_b);
} }
} }
TypeEnum::TList { ty: ty1 } => { TypeEnum::TList { ty: ty1 } => {
@ -315,7 +315,7 @@ impl Unifier {
self.unify(*ty1, ty2)?; self.unify(*ty1, ty2)?;
self.set_a_to_b(a, b); self.set_a_to_b(a, b);
} else { } else {
return self.report_kind_error(&*ty_a, &*ty_b); return self.incompatible_types(&*ty_a, &*ty_b);
} }
} }
TypeEnum::TRecord { fields: fields1 } => { TypeEnum::TRecord { fields: fields1 } => {
@ -355,7 +355,7 @@ impl Unifier {
self.set_a_to_b(a, b); self.set_a_to_b(a, b);
} }
_ => { _ => {
return self.report_kind_error(&*ty_a, &*ty_b); return self.incompatible_types(&*ty_a, &*ty_b);
} }
} }
} }
@ -378,7 +378,7 @@ impl Unifier {
} }
self.set_a_to_b(a, b); self.set_a_to_b(a, b);
} else { } else {
return self.report_kind_error(&*ty_a, &*ty_b); return self.incompatible_types(&*ty_a, &*ty_b);
} }
} }
TypeEnum::TVirtual { ty: ty1 } => { TypeEnum::TVirtual { ty: ty1 } => {
@ -386,7 +386,7 @@ impl Unifier {
self.unify(*ty1, *ty2)?; self.unify(*ty1, *ty2)?;
self.set_a_to_b(a, b); self.set_a_to_b(a, b);
} else { } else {
return self.report_kind_error(&*ty_a, &*ty_b); return self.incompatible_types(&*ty_a, &*ty_b);
} }
} }
_ => unimplemented!(), _ => unimplemented!(),
@ -402,7 +402,7 @@ impl Unifier {
table.union_value(a, ty_b); table.union_value(a, ty_b);
} }
fn report_kind_error(&self, a: &TypeEnum, b: &TypeEnum) -> Result<(), String> { fn incompatible_types(&self, a: &TypeEnum, b: &TypeEnum) -> Result<(), String> {
Err(format!( Err(format!(
"Cannot unify {} with {}", "Cannot unify {} with {}",
a.get_type_name(), a.get_type_name(),