aboutsummaryrefslogtreecommitdiff
path: root/src/type/check.rs
diff options
context:
space:
mode:
authorJoel Kronqvist <joel.kronqvist@iki.fi>2025-08-18 13:38:57 +0300
committerJoel Kronqvist <joel.kronqvist@iki.fi>2025-08-18 13:38:57 +0300
commit6ce77dfc296c24d43ac1e3b2daffec0a7e485891 (patch)
treec59adb488bef01a396340c7f4df8f52c00fefd20 /src/type/check.rs
parent57c6323c15e257d4620f9d02a54e704d25bd2084 (diff)
downloadmyslip-6ce77dfc296c24d43ac1e3b2daffec0a7e485891.tar.gz
myslip-6ce77dfc296c24d43ac1e3b2daffec0a7e485891.zip
refactor: change conversions to use a stricter function with deduplicated code
Diffstat (limited to 'src/type/check.rs')
-rw-r--r--src/type/check.rs17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/type/check.rs b/src/type/check.rs
index a54ffc2..f1c4a2b 100644
--- a/src/type/check.rs
+++ b/src/type/check.rs
@@ -330,7 +330,9 @@ impl SExp {
}
match &ty {
None => ty = Some(arm.infer_type(newctx)?),
- Some(t) => ty = Some(t.least_general_supertype(&arm.infer_type(newctx.clone())?)),
+ Some(t) => if arm.infer_type(newctx)? != *t {
+ return Err(OtherError);
+ },
}
}
if !has_wildcard {
@@ -346,8 +348,15 @@ 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().into_type(&*from) {
+ (Arrow(from, _), a) => match a.clone().convert(&*from) {
Ok(s) => Ok(s),
Err(()) => Err(InvalidArgList {
arglist: (**l).clone(),
@@ -370,9 +379,9 @@ impl SExp {
opertype.infer_generics(&conv_args)?
};
- match (opertype, argstype) {
+ match (opertype, conv_args) {
(Arrow(a, b), c) => {
- if c.aka(&*a) {
+ if c == *a {
Ok(*b)
} else {
Err(InvalidArgList {