1
0
forked from M-Labs/nac3

core: fix list_slice_assignment assert int type

This commit is contained in:
lyken 2024-07-26 14:59:11 +08:00
parent 8a6dc1c1e1
commit 80e56bc081

View File

@ -7,7 +7,7 @@ use super::{
ArrayLikeIndexer, ArrayLikeValue, ArraySliceValue, ListValue, NDArrayValue,
TypedArrayLikeAdapter, UntypedArrayLikeAccessor,
},
llvm_intrinsics, CodeGenContext, CodeGenerator,
llvm_intrinsics, CodeGenContext, CodeGenerator, Int, Int64, NIntModel,
};
use crate::codegen::classes::TypedArrayLikeAccessor;
use crate::codegen::stmt::gen_for_callback_incrementing;
@ -416,14 +416,27 @@ pub fn list_slice_assignment<'ctx, G: CodeGenerator + ?Sized>(
.unwrap();
let cond_1 = ctx.builder.build_and(dest_step_eq_one, src_slt_dest, "slice_cond_1").unwrap();
let cond = ctx.builder.build_or(src_eq_dest, cond_1, "slice_cond").unwrap();
ctx.make_assert(
generator,
cond,
"0:ValueError",
"attempt to assign sequence of size {0} to slice of size {1} with step size {2}",
[Some(src_slice_len), Some(dest_slice_len), Some(dest_idx.2)],
ctx.current_loc,
);
// TODO: Temporary fix. Rewrite `list_slice_assignment` later
// Exception params should have been i64
{
let param_model = NIntModel(Int64);
let src_slice_len =
Int::from(src_slice_len).s_extend_or_bit_cast(ctx, param_model, "src_slice_len");
let dest_slice_len =
Int::from(dest_slice_len).s_extend_or_bit_cast(ctx, param_model, "dest_slice_len");
let dest_idx_2 = Int::from(dest_idx.2).s_extend_or_bit_cast(ctx, param_model, "dest_idx_2");
ctx.make_assert(
generator,
cond,
"0:ValueError",
"attempt to assign sequence of size {0} to slice of size {1} with step size {2}",
[Some(src_slice_len.value), Some(dest_slice_len.value), Some(dest_idx_2.value)],
ctx.current_loc,
);
}
let new_len = {
let args = vec![