diff --git a/reid-llvm-lib/src/builder.rs b/reid-llvm-lib/src/builder.rs index d08c97b..e3bbbd9 100644 --- a/reid-llvm-lib/src/builder.rs +++ b/reid-llvm-lib/src/builder.rs @@ -251,10 +251,14 @@ impl Builder { Ok(()) } Alloca(_, _) => Ok(()), - Load(ptr, _) => { - if let Ok(ty) = ptr.get_type(&self) { - if let Type::Ptr(_) = ty { - Ok(()) + Load(ptr, load_ty) => { + if let Ok(ptr_ty) = ptr.get_type(&self) { + if let Type::Ptr(ptr_ty_inner) = ptr_ty { + if *ptr_ty_inner == load_ty { + Ok(()) + } else { + Err(()) + } } else { Err(()) } @@ -332,7 +336,7 @@ impl InstructionValue { FunctionCall(function_value, _) => Ok(builder.function_data(function_value).ret), Phi(values) => values.first().ok_or(()).and_then(|v| v.get_type(&builder)), Alloca(_, ty) => Ok(Type::Ptr(Box::new(ty.clone()))), - Load(_, ty) => Ok(Type::Ptr(Box::new(ty.clone()))), + Load(_, ty) => Ok(ty.clone()), Store(_, value) => value.get_type(builder), } } diff --git a/reid/examples/reid/mutable.reid b/reid/examples/reid/mutable.reid index 4d75cd4..22b59a5 100644 --- a/reid/examples/reid/mutable.reid +++ b/reid/examples/reid/mutable.reid @@ -6,10 +6,11 @@ fn indirection() -> bool { fn main() -> u16 { let mut test = 5; + let heehoo = 10; if indirection() { test = 11; } - return test; + return test + heehoo; } diff --git a/reid/src/mir/typecheck.rs b/reid/src/mir/typecheck.rs index 8ff13c7..be8c979 100644 --- a/reid/src/mir/typecheck.rs +++ b/reid/src/mir/typecheck.rs @@ -38,6 +38,8 @@ pub enum ErrorKind { VariableNotMutable(String), #[error("Function {0} was given {1} parameters, but {2} were expected")] InvalidAmountParameters(String, usize, usize), + #[error("Unable to infer type {0}")] + TypeNotInferrable(TypeKind), } /// Struct used to implement a type-checking pass that can be performed on the @@ -194,6 +196,10 @@ impl Block { ); let res_t = if res_t.known().is_err() { + // state.ok::<_, Infallible>( + // Err(ErrorKind::TypeNotInferrable(res_t)), + // variable_reference.2 + expression.1, + // ); // Unable to infer variable type even from expression! Default it let res_t = state.or_else(res_t.or_default(), Vague(Unknown), variable_reference.2); @@ -552,8 +558,6 @@ impl Literal { (L::Vague(VagueL::Number(v)), U32) => L::U32(v as u32), (L::Vague(VagueL::Number(v)), U64) => L::U64(v as u64), (L::Vague(VagueL::Number(v)), U128) => L::U128(v as u128), - // Default type for number literal if unable to find true type. - (L::Vague(VagueL::Number(v)), Vague(Number)) => L::I32(v as i32), (_, Vague(_)) => self, _ => Err(ErrorKind::LiteralIncompatible(self, hint))?, })