subtype constraint: prefer to assign rhs variable

This commit is contained in:
Michael Sippel 2025-06-01 12:14:27 +02:00
parent e962e467a4
commit 76ffd8ba73
Signed by: senvas
GPG key ID: F96CF119C34B64A6
2 changed files with 11 additions and 9 deletions
src
constraint_system
test

View file

@ -20,15 +20,6 @@ impl ConstraintSystem {
Variables
*/
(t, TypeTerm::TypeID(TypeID::Var(v))) => {
//eprintln!("t <= variable");
if self.add_lower_subtype_bound(v, t.clone()).is_ok() {
Ok(TypeTerm::unit())
} else {
Err(ConstraintError{ addr: unification_pair.addr, t1: TypeTerm::TypeID(TypeID::Var(v)), t2: t })
}
}
(TypeTerm::TypeID(TypeID::Var(v)), t) => {
//eprintln!("variable <= t");
if self.add_upper_subtype_bound(v, t.clone()).is_ok() {
@ -39,6 +30,15 @@ impl ConstraintSystem {
}
(t, TypeTerm::TypeID(TypeID::Var(v))) => {
//eprintln!("t <= variable");
if self.add_lower_subtype_bound(v, t.clone()).is_ok() {
Ok(TypeTerm::unit())
} else {
Err(ConstraintError{ addr: unification_pair.addr, t1: TypeTerm::TypeID(TypeID::Var(v)), t2: t })
}
}
/*
Atoms
*/

View file

@ -247,6 +247,7 @@ fn test_morphism_path4() {
seq_repr: None,
item_morph: Box::new(MorphismInstance::Primitive {
σ: vec![
(dict.get_typeid(&"DstRadix".into()).unwrap(), TypeTerm::Num(16)),
(dict.get_typeid(&"Radix".into()).unwrap(), TypeTerm::Num(16)),
].into_iter().collect(),
ψ: TypeTerm::unit(),
@ -318,6 +319,7 @@ fn test_morphism_path_posint() {
},
MorphismInstance::Primitive {
σ: vec![
(dict.get_typeid(&"DstRadix".into()).unwrap(), TypeTerm::Num(16)),
(dict.get_typeid(&"Radix".into()).unwrap(), TypeTerm::Num(16)),
].into_iter().collect(),
ψ: TypeTerm::unit(),