From d0b7898ad72f7715aaee2dbb086adeb3ef1df53a Mon Sep 17 00:00:00 2001 From: Selimaj Dev Date: Fri, 17 Apr 2026 04:06:29 +0200 Subject: [PATCH] Identifier fields --- semantic/src/scope.rs | 19 ++++++++++++++----- test/src/main.ms | 8 ++++++-- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/semantic/src/scope.rs b/semantic/src/scope.rs index 8eada56..a395701 100644 --- a/semantic/src/scope.rs +++ b/semantic/src/scope.rs @@ -84,8 +84,8 @@ impl LocalScope { pub fn walk_postfixes( self: &Arc, - initial: &Box, - postfixes: &Vec, + initial: &mut Box, + postfixes: &mut Vec, ) -> Option> { let mut current_type = self.get_type_from_expr(initial)?; @@ -93,7 +93,9 @@ impl LocalScope { match postfix { Postfix::FieldAccess(id) => match &*current_type { TypeRef::Struct(s) => { - current_type = s.fields.get(id)?.var_type.clone(); + let field = s.fields.get(id)?; + *id = field.name.clone(); + current_type = field.var_type.clone(); } _ => unimplemented!(), }, @@ -111,7 +113,10 @@ impl LocalScope { Some(current_type) } - pub fn get_type_from_expr(self: &Arc, expr: &ast::Expression) -> Option> { + pub fn get_type_from_expr( + self: &Arc, + expr: &mut ast::Expression, + ) -> Option> { match expr { ast::Expression::IntLiteral(_) => self .parent @@ -133,7 +138,11 @@ impl LocalScope { .get_reference(&"string".to_string()) .map(|r| r.var_type.clone()), - ast::Expression::Identifier(id) => self.get_reference(id).map(|r| r.var_type.clone()), + ast::Expression::Identifier(id) => { + let rf = self.get_reference(id)?; + *id = rf.name.clone(); + Some(rf.var_type.clone()) + } ast::Expression::Postfix { initial, postfixes } => { self.walk_postfixes(initial, postfixes) diff --git a/test/src/main.ms b/test/src/main.ms index d53a617..cf9b82a 100644 --- a/test/src/main.ms +++ b/test/src/main.ms @@ -1,5 +1,9 @@ -function test(): int { } +struct MyType { + x: int, +} + +function test(): MyType { } function add() { - let output = test(); + let output = test().x; }