From df6c9c8a35b6d9959021bcb2b3ee16d6bfdf3232 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Tue, 21 Sep 2021 11:29:51 +0800 Subject: [PATCH] fix #11 --- nac3core/src/codegen/expr.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/nac3core/src/codegen/expr.rs b/nac3core/src/codegen/expr.rs index ea24cce6..e5aa9b6e 100644 --- a/nac3core/src/codegen/expr.rs +++ b/nac3core/src/codegen/expr.rs @@ -126,14 +126,15 @@ impl<'ctx, 'a> CodeGenContext<'ctx, 'a> { fun_id = Some(*id); } } - let fun_id = fun_id.unwrap(); - let ty = self.get_llvm_type(fun.0.ret).into_pointer_type(); let zelf_ty: BasicTypeEnum = ty.get_element_type().try_into().unwrap(); let zelf = self.builder.build_alloca(zelf_ty, "alloca").into(); - let mut sign = fun.0.clone(); - sign.ret = self.primitives.none; - self.gen_call(Some((fun.0.ret, zelf)), (&sign, fun_id), params); + // call `__init__` if there is one + if let Some(fun_id) = fun_id { + let mut sign = fun.0.clone(); + sign.ret = self.primitives.none; + self.gen_call(Some((fun.0.ret, zelf)), (&sign, fun_id), params); + } return Some(zelf); } }