Fix two small bugs, add new example to test

This commit is contained in:
Sofia 2025-07-29 23:16:56 +03:00
parent c7aacfe756
commit 8f7b785664
3 changed files with 33 additions and 2 deletions

View File

@ -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;
}

View File

@ -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, &param_t)
.new_var(param.name.clone(), mutable, &param_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))),

View File

@ -152,3 +152,8 @@ fn associated_functions() {
Some(4),
);
}
#[test]
fn mutable_inner_functions() {
test(include_str!("../../examples/mutable_inner.reid"), "test", Some(0));
}