Fix type values

This commit is contained in:
2026-04-23 18:10:48 +02:00
parent d8543fb3d0
commit 195172a293
2 changed files with 33 additions and 3 deletions
+26 -2
View File
@@ -90,9 +90,17 @@ impl LocalScope {
pub fn with_statement(self: &Arc<Self>, statement: &mut Statement) { pub fn with_statement(self: &Arc<Self>, statement: &mut Statement) {
match statement { match statement {
Statement::Block(b) => self.clone().with_block(b), Statement::Block(b) => self.clone().with_block(b),
Statement::VarDecl { name, init, .. } => { Statement::VarDecl {
name, init, type_, ..
} => {
if let Some(init) = init { if let Some(init) = init {
let var_type = self.get_type_from_expr(init).unwrap(); let init_type = self.get_type_from_expr(init);
let var_type = type_
.as_mut()
.map(|t| self.get_type_from_type_expr(t))
.or_else(|| Some(init_type))
.unwrap()
.unwrap();
let var_name = name.clone(); let var_name = name.clone();
@@ -193,6 +201,22 @@ impl LocalScope {
Some(current_type) Some(current_type)
} }
pub fn get_type_from_type_expr(
self: &Arc<Self>,
expr: &mut ast::TypeExpr,
) -> Option<Arc<TypeRef>> {
match expr {
ast::TypeExpr::Identifier(id) => {
if let Some(v) = self.get_type_reference(id).map(|r| r.var_type.clone()) {
*id = v.get_name();
Some(v)
} else {
None
}
}
}
}
pub fn get_type_from_expr( pub fn get_type_from_expr(
self: &Arc<Self>, self: &Arc<Self>,
expr: &mut ast::Expression, expr: &mut ast::Expression,
+7 -1
View File
@@ -1,5 +1,11 @@
package main; package main;
public struct Idk {
int a,
int b,
}
int test(int a, int b) { int test(int a, int b) {
return a + b; Idk bro = 10;
return a + b + bro.a;
} }