fix: correct argument order in iterable checks

This commit is contained in:
rclovis
2026-01-30 12:27:53 +01:00
parent 19a841a661
commit bf900922e2
2 changed files with 7 additions and 7 deletions

View File

@@ -190,14 +190,14 @@ pub fn gen_store_target<'ctx, G: CodeGenerator>(
.unwrap()
}
ExprKind::Tuple { elts, .. } => {
let elts: Vec<PointerValue<'ctx>> = elts
let elts = elts
.iter()
.map(|e| {
generator.gen_store_target(ctx, e, name).and_then(|v| {
v.ok_or_else(|| "failed to generate store target".to_string())
})
})
.collect::<Result<_, _>>()?;
.collect::<Result<Vec<_>, _>>()?;
let struct_ty =
ctx.ctx.struct_type(&elts.iter().map(|p| p.get_type().into()).collect_vec(), false);
let struct_ptr = gen_var(ctx, struct_ty, name);

View File

@@ -276,7 +276,7 @@ impl Fold<()> for Inferencer<'_> {
let target = self.fold_expr(*target)?;
let iter = self.fold_expr(*iter)?;
let element_ty = self.check_iterable(&iter, &target)?;
let element_ty = self.check_iterable(&target, &iter)?;
self.unify(element_ty, target.custom.unwrap(), &target.location)?;
let body =
@@ -604,8 +604,8 @@ impl Inferencer<'_> {
/// Check if a type is iterable and return its element type.
fn get_iterable_element_type(
&mut self,
iter: &Expr<Option<Type>>,
target: &Expr<Option<Type>>,
iter: &Expr<Option<Type>>,
) -> Result<Option<Type>, InferenceError> {
let iter_ty = iter.custom.unwrap();
let ty_enum = self.unifier.get_ty(iter_ty);
@@ -716,12 +716,12 @@ impl Inferencer<'_> {
/// Check if a type is iterable. Returns `Ok(())` if iterable, otherwise returns an error.
fn check_iterable(
&mut self,
iter: &Expr<Option<Type>>,
target: &Expr<Option<Type>>,
iter: &Expr<Option<Type>>,
) -> Result<Type, InferenceError> {
let iter_ty = iter.custom.unwrap();
let location = iter.location;
if let Some(elem_ty) = self.get_iterable_element_type(iter, target)? {
if let Some(elem_ty) = self.get_iterable_element_type(target, iter)? {
Ok(elem_ty)
} else {
let iter_ty_str = self.unifier.stringify(iter_ty);
@@ -1173,7 +1173,7 @@ impl Inferencer<'_> {
let iterable = self.fold_expr(args.remove(0))?;
let iterable_ty = iterable.custom.unwrap();
self.check_iterable(&iterable, &promoted_func)?;
self.check_iterable(&promoted_func, &iterable)?;
args_new.push(iterable);
if !args.is_empty() {