nac3artiq: cast none to correct ptr type (#241) #243

Merged
sb10q merged 1 commits from option_fix into master 2022-03-27 07:46:07 +08:00
1 changed files with 18 additions and 3 deletions
Showing only changes of commit 000b128551 - Show all commits

View File

@ -917,9 +917,24 @@ impl InnerResolver {
if let TopLevelDef::Class { fields, .. } = &*definition { if let TopLevelDef::Class { fields, .. } = &*definition {
let values: Result<Option<Vec<_>>, _> = fields let values: Result<Option<Vec<_>>, _> = fields
.iter() .iter()
.map(|(name, _, _)| { .map(|(name, ty, _)| {
self.get_obj_value(py, obj.getattr(&name.to_string())?, ctx, generator).map_err(|e| let v = self.get_obj_value(py, obj.getattr(&name.to_string())?, ctx, generator)
super::CompileError::new_err(format!("Error getting field {}: {}", name, e))) .map_err(|e| super::CompileError::new_err(format!("Error getting field {}: {}", name, e)));
match (v, ctx.unifier.get_ty_immutable(*ty).as_ref()) {
(Ok(Some(v)), TypeEnum::TObj { obj_id, params, .. })
if *obj_id == ctx.primitives.option.get_obj_id(&ctx.unifier) =>
{
let actual_ptr_ty = ctx
.get_llvm_type(generator, *params.iter().next().unwrap().1)
.ptr_type(AddressSpace::Generic);
Ok(Some(ctx.builder.build_bitcast(
v,
actual_ptr_ty,
"option_none_ptr_cast",
)))
}
(v, _) => v,
}
}) })
.collect(); .collect();
let values = values?; let values = values?;