diff --git a/semantic/src/scope.rs b/semantic/src/scope.rs index 92e8a3d..40bd9ee 100644 --- a/semantic/src/scope.rs +++ b/semantic/src/scope.rs @@ -3,7 +3,7 @@ use std::{ sync::{Arc, Mutex}, }; -use parser::ast::{self, ParamList, Statement}; +use parser::ast::{self, ParamList, Postfix, Statement}; use crate::{ hir::{FunctionRef, TopLevelHirScope, TypeRef, VarRef}, @@ -83,6 +83,30 @@ impl LocalScope { } } + pub fn walk_postfixes( + self: &Arc, + initial: &Box, + postfixes: &Vec, + ) -> Option> { + let mut current_type = self.get_type_from_expr(initial)?; + + dbg!(current_type.clone(), initial, postfixes); + + for postfix in postfixes { + match postfix { + Postfix::FieldAccess(id) => match &*current_type { + TypeRef::Struct(s) => { + current_type = s.fields.get(id)?.var_type.clone(); + } + _ => unimplemented!(), + }, + _ => unimplemented!(), + } + } + + Some(current_type) + } + pub fn get_type_from_expr(self: &Arc, expr: &ast::Expression) -> Option> { match expr { ast::Expression::IntLiteral(_) => { @@ -131,6 +155,10 @@ impl LocalScope { _ => None, }, + ast::Expression::Postfix { initial, postfixes } => { + self.walk_postfixes(initial, postfixes) + } + _ => unimplemented!(), } } diff --git a/test/src/main.ms b/test/src/main.ms index 0af918c..d2f6e1a 100644 --- a/test/src/main.ms +++ b/test/src/main.ms @@ -1,5 +1,9 @@ -function add(a: int, b: int) { - let myVar = 10; +struct Test { + x: int +} - let test = myVar; -} \ No newline at end of file +function add() { + let output = test().x; +} + +function test(): Test { } \ No newline at end of file