aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Kronqvist <joel.kronqvist@iki.fi>2025-08-18 13:56:58 +0300
committerJoel Kronqvist <joel.kronqvist@iki.fi>2025-08-18 13:56:58 +0300
commit183311b872406e1928851a29a953c07954653297 (patch)
treec636bcbc40c3ff22ae2a74a9cafd625ecc1e0267
parent6ce77dfc296c24d43ac1e3b2daffec0a7e485891 (diff)
downloadmyslip-183311b872406e1928851a29a953c07954653297.tar.gz
myslip-183311b872406e1928851a29a953c07954653297.zip
fix: refined [x] to x conversion, think (not true) and (vector 1)
-rw-r--r--src/type/check.rs7
-rw-r--r--src/type/conversion.rs7
2 files changed, 7 insertions, 7 deletions
diff --git a/src/type/check.rs b/src/type/check.rs
index f1c4a2b..b0311d1 100644
--- a/src/type/check.rs
+++ b/src/type/check.rs
@@ -348,13 +348,6 @@ impl SExp {
let opertype = (*op).infer_type(ctx.clone())?;
let argstype = (*l).infer_list_type(ctx)?;
- // makes [x] x
- let argstype = match argstype {
- List(v) if v.get(0).is_some() && v.get(1).is_none() =>
- v.get(0).unwrap().clone(),
- t => t,
- };
-
let conv_args = match (opertype.clone(), argstype.clone()) {
(Arrow(from, _), a) => match a.clone().convert(&*from) {
Ok(s) => Ok(s),
diff --git a/src/type/conversion.rs b/src/type/conversion.rs
index 844632f..ab858e6 100644
--- a/src/type/conversion.rs
+++ b/src/type/conversion.rs
@@ -12,6 +12,7 @@ impl Type {
/// 1. (T T ... T T) -> (T ...)
/// 2. self = concrete and other = variable type => self,
/// 3. arrow types and lists are mapped
+ /// 4. makes [self] self if self == other
pub fn convert(self, other: &Type) -> Result<Type, ()> {
let (ty, ctx) = self.convert_ctx(other)?;
let mut checks = HashMap::new();
@@ -83,6 +84,12 @@ impl Type {
Ok((vecof(convt), ctx))
},
+ // at the end, because it'd be nice to know in the
+ // guard that the conversion from v to t2 works, and
+ // if it doesn't, try something else, but now everyhting
+ // has already been tried so this is safe
+ (List(v), t2) if v.len() == 1 => v[0].clone().convert_ctx(t2),
+
_ => Err(())
}
}