From 2f56f148cb377eb1d63c6b48481ea715c76ec6ce Mon Sep 17 00:00:00 2001 From: sofia Date: Tue, 22 Jul 2025 22:41:20 +0300 Subject: [PATCH] Fix assert_known --- reid/src/mir/typecheck.rs | 16 ++++++++++------ reid_src/test.reid | 15 ++++++++++----- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/reid/src/mir/typecheck.rs b/reid/src/mir/typecheck.rs index 8b361ef..eb89319 100644 --- a/reid/src/mir/typecheck.rs +++ b/reid/src/mir/typecheck.rs @@ -762,22 +762,26 @@ impl TypeKind { refs: &TypeRefs, state: &TypecheckPassState, ) -> Result { + self.is_known(refs, state).map(|_| self.clone()) + } + + fn is_known(&self, refs: &TypeRefs, state: &TypecheckPassState) -> Result<(), ErrorKind> { match &self { - TypeKind::Array(type_kind, _) => type_kind.as_ref().assert_known(refs, state), + TypeKind::Array(type_kind, _) => type_kind.as_ref().is_known(refs, state), TypeKind::CustomType(custom_type_key) => state .scope .types .get(custom_type_key) - .map(|_| self.clone()) + .map(|_| ()) .ok_or(ErrorKind::NoSuchType( custom_type_key.0.clone(), state.module_id.unwrap(), )), - TypeKind::Borrow(type_kind, _) => type_kind.assert_known(refs, state), - TypeKind::UserPtr(type_kind) => type_kind.assert_known(refs, state), - TypeKind::CodegenPtr(type_kind) => type_kind.assert_known(refs, state), + TypeKind::Borrow(type_kind, _) => type_kind.is_known(refs, state), + TypeKind::UserPtr(type_kind) => type_kind.is_known(refs, state), + TypeKind::CodegenPtr(type_kind) => type_kind.is_known(refs, state), TypeKind::Vague(vague_type) => Err(ErrorKind::TypeIsVague(*vague_type)), - _ => Ok(self.clone()), + _ => Ok(()), } } } diff --git a/reid_src/test.reid b/reid_src/test.reid index 9d7a3b1..1c451e2 100644 --- a/reid_src/test.reid +++ b/reid_src/test.reid @@ -1,7 +1,12 @@ -struct SDL_Thing {} +fn vec_sub(l: [f32; 3], r: [f32; 3]) -> [f32; 3] { + return [l[0]-r[0], l[1]-r[1], l[2]-r[2]]; +} -extern fn SDL_malloc(size: u64) -> *SDL_Thing; +fn foo(x: f32) { + let a = [x, x, 0.0]; + let b = [x, x, x]; // works + // let b = [x * 0.5, x * 0.5, x]; // does not work + vec_sub(a, b); +} -fn main() { - let pixels = SDL_malloc(4 * 320 * 240); -} \ No newline at end of file +fn main() {} \ No newline at end of file