Fix two small bugs, add new example to test
This commit is contained in:
parent
c7aacfe756
commit
8f7b785664
25
examples/mutable_inner.reid
Normal file
25
examples/mutable_inner.reid
Normal 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;
|
||||
}
|
@ -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))),
|
||||
|
@ -152,3 +152,8 @@ fn associated_functions() {
|
||||
Some(4),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mutable_inner_functions() {
|
||||
test(include_str!("../../examples/mutable_inner.reid"), "test", Some(0));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user