From 6ce77dfc296c24d43ac1e3b2daffec0a7e485891 Mon Sep 17 00:00:00 2001 From: Joel Kronqvist Date: Mon, 18 Aug 2025 13:38:57 +0300 Subject: refactor: change conversions to use a stricter function with deduplicated code --- src/type/check.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/type/check.rs') 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 { -- cgit v1.2.3