From 75272498c4ba093ee0a0ab1ea63685b1da205a0b Mon Sep 17 00:00:00 2001 From: MisterChaos96 Date: Tue, 7 May 2024 08:20:10 +0200 Subject: [PATCH] fixed typechecker trying to find a field of a class in the symboltable --- src/Ast.hs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Ast.hs b/src/Ast.hs index 411fc01..83ccaa1 100644 --- a/src/Ast.hs +++ b/src/Ast.hs @@ -202,8 +202,8 @@ typeCheckExpression (BinaryOperation op expr1 expr2) symtab classes = else error "Logical OR operation requires two operands of type boolean" NameResolution -> - case (expr1', expr2') of - (TypedExpression t1 (Reference obj), TypedExpression t2 (Reference member)) -> + case (expr1', expr2) of + (TypedExpression t1 (Reference obj), Reference member) -> -- Lookup the class type of obj from the symbol table let objectType = lookupType obj symtab classDetails = find (\(Class className _ _) -> className == objectType) classes @@ -213,7 +213,7 @@ typeCheckExpression (BinaryOperation op expr1 expr2) symtab classes = let fieldTypes = [dt | VariableDeclaration dt id _ <- fields, id == member] methodTypes = [dt | MethodDeclaration dt id _ _ <- methods, id == member] in case fieldTypes ++ methodTypes of - [resolvedType] -> TypedExpression resolvedType (BinaryOperation op expr1' expr2') + [resolvedType] -> TypedExpression resolvedType (BinaryOperation op expr1' (TypedExpression resolvedType (Reference member))) [] -> error $ "Member '" ++ member ++ "' not found in class '" ++ objectType ++ "'" _ -> error $ "Ambiguous reference to '" ++ member ++ "' in class '" ++ objectType ++ "'" Nothing -> error $ "Object '" ++ obj ++ "' does not correspond to a known class" @@ -241,7 +241,7 @@ typeCheckExpression (StatementExpressionExpression stmtExpr) symtab classes = in TypedExpression (getTypeFromStmtExpr stmtExpr') (StatementExpressionExpression stmtExpr') -- ********************************** Type Checking: StatementExpressions ********************************** - +-- TODO: Implement type checking for StatementExpressions typeCheckStatementExpression :: StatementExpression -> [(Identifier, DataType)] -> [Class] -> StatementExpression typeCheckStatementExpression (Assignment id expr) symtab classes = let expr' = typeCheckExpression expr symtab classes