diff --git a/src/Typecheck.hs b/src/Typecheck.hs index e4aab3b..d7eeac2 100644 --- a/src/Typecheck.hs +++ b/src/Typecheck.hs @@ -117,9 +117,14 @@ typeCheckStatementExpression (ConstructorCall className args) symtab classes = case find (\(Class name _ _) -> name == className) classes of Nothing -> error $ "Class '" ++ className ++ "' not found." Just (Class _ methods fields) -> - -- Constructor needs the same name as the class + -- Find constructor matching the class name with void return type case find (\(MethodDeclaration retType name params _) -> name == "" && retType == "void") methods of - Nothing -> error $ "No valid constructor found for class '" ++ className ++ "'." + -- If no constructor is found, assume standard constructor with no parameters + Nothing -> + if null args then + TypedStatementExpression className (ConstructorCall className args) + else + error $ "No valid constructor found for class '" ++ className ++ "', but arguments were provided." Just (MethodDeclaration _ _ params _) -> let args' = map (\arg -> typeCheckExpression arg symtab classes) args