From 8f7b785664aeb9176803adf34d0fe1cc8aea99c9 Mon Sep 17 00:00:00 2001 From: sofia Date: Tue, 29 Jul 2025 23:16:56 +0300 Subject: [PATCH] Fix two small bugs, add new example to test --- examples/mutable_inner.reid | 25 +++++++++++++++++++++++++ reid/src/mir/typecheck/typeinference.rs | 5 +++-- reid/tests/e2e.rs | 5 +++++ 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 examples/mutable_inner.reid diff --git a/examples/mutable_inner.reid b/examples/mutable_inner.reid new file mode 100644 index 0000000..3fe6005 --- /dev/null +++ b/examples/mutable_inner.reid @@ -0,0 +1,25 @@ +struct Game {} + +impl Game { + pub fn run_frame(&mut self) {} +} + +struct Platform { + game: Game, +} + +impl Platform { + pub fn new() -> Platform { + return Platform { game: Game {} }; + } + + pub fn run_frame(&mut self) { + *self.game.run_frame(); + } +} + +fn main() -> i32 { + let mut platform = Platform::new(); + platform.run_frame(); + return 0; +} \ No newline at end of file diff --git a/reid/src/mir/typecheck/typeinference.rs b/reid/src/mir/typecheck/typeinference.rs index c14baf0..491be16 100644 --- a/reid/src/mir/typecheck/typeinference.rs +++ b/reid/src/mir/typecheck/typeinference.rs @@ -171,8 +171,9 @@ impl FunctionDefinition { let scope_refs = ScopeTypeRefs::from(type_refs); for param in &self.parameters { let param_t = state.or_else(param.ty.assert_unvague(), Vague(Unknown), self.signature()); + let mutable = matches!(param_t, TypeKind::Borrow(_, true)); let res = scope_refs - .new_var(param.name.clone(), false, ¶m_t) + .new_var(param.name.clone(), mutable, ¶m_t) .or(Err(ErrorKind::VariableAlreadyDefined(param.name.clone()))); state.ok(res, self.signature()); } @@ -605,7 +606,7 @@ impl Expression { .parameters .get_mut(0) .expect("Unknown-type associated function NEEDS to always have at least one parameter!"); - let param_ty = first_param.infer_types(state, type_refs).unwrap().resolve_deep(); + let param_ty = first_param.infer_types(state, type_refs)?.resolve_deep(); *type_kind = state .or_else( param_ty.ok_or(ErrorKind::CouldNotInferType(format!("{}", first_param))), diff --git a/reid/tests/e2e.rs b/reid/tests/e2e.rs index d83ffa2..d0fa6a3 100644 --- a/reid/tests/e2e.rs +++ b/reid/tests/e2e.rs @@ -152,3 +152,8 @@ fn associated_functions() { Some(4), ); } + +#[test] +fn mutable_inner_functions() { + test(include_str!("../../examples/mutable_inner.reid"), "test", Some(0)); +}