diff options
author | Joel Kronqvist <joel.kronqvist@iki.fi> | 2025-08-16 02:42:43 +0300 |
---|---|---|
committer | Joel Kronqvist <joel.kronqvist@iki.fi> | 2025-08-16 02:42:43 +0300 |
commit | fad9bf51e9ecd48473046a5e7bb9b5005893ae89 (patch) | |
tree | a66df4303bf32cc25ec336708019c083d7d5b10d | |
parent | 4030f96b6ee7dba16848169d377cfd2f5979d992 (diff) | |
download | myslip-fad9bf51e9ecd48473046a5e7bb9b5005893ae89.tar.gz myslip-fad9bf51e9ecd48473046a5e7bb9b5005893ae89.zip |
fix: conversions between vectors, they were needed for some functions, but now it's stricter than before
-rw-r--r-- | src/type/conversion.rs | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/src/type/conversion.rs b/src/type/conversion.rs index 37ebc46..1ada0d3 100644 --- a/src/type/conversion.rs +++ b/src/type/conversion.rs @@ -101,11 +101,21 @@ impl Type { && v1.get(1) != None => { match (v1.get(1), x) { - (Some(a), b) => a.lgst_ctx(&b, ctx), + (Some(a), b) => { + let res = a.lgst_ctx(&b, ctx); + res + }, _ => panic!("unreachable") } }, + (VecOf(a), VecOf(b)) => { + match &**b { + VarType(s) => (vecof(vt(s)), ctx), + _ => (vt("T"), ctx) + } + }, + (Arrow(a1, a2), Arrow(b1, b2)) => { let (t1, newctx) = a1.lgst_ctx(b1, ctx); ctx = newctx; @@ -268,6 +278,8 @@ impl Type { v[1].clone().into_type(x) }, + (VecOf(a), VecOf(b)) => Ok(vecof(a.clone().into_type(&b)?)), + (List(v1), List(v2)) if v1.len() == v2.len() => { let mut res = vec![]; for (t1, t2) in v1.into_iter().zip(v2) { @@ -363,6 +375,11 @@ mod tests { List(vec![vt("T"), vt("T")]) ); + assert_eq!( + vecof(Integer).least_general_supertype(&vecof(vt("T"))), + vecof(vt("T")) + ); + } #[test] @@ -433,6 +450,23 @@ mod tests { vecof(vt("T")) ); + assert_eq!( + List(vec![VecType, vecof(Integer)]).least_general_supertype( + &vecof(vt("T")) + ), + vecof(vt("T")) + ); + + assert_eq!( + List(vec![ + List(vec![VecType, vecof(Integer)]), + List(vec![VecType, vecof(Integer)]) + ]).least_general_supertype( + &List(vec![vecof(vt("T")), vecof(vt("T"))]) + ), + List(vec![vecof(vt("T")), vecof(vt("T"))]) + ); + } } |