From 35b17357b5b55e73c6bbc59e7dae094412b7b02a Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Sat, 2 Sep 2017 10:18:40 +0200 Subject: Fully support structs --- TypeCheck.hs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'TypeCheck.hs') diff --git a/TypeCheck.hs b/TypeCheck.hs index 2b05df1..6d8134d 100644 --- a/TypeCheck.hs +++ b/TypeCheck.hs @@ -259,7 +259,7 @@ annotateExpr db (EGet st n _) = do Nothing -> Left $ "Struct of type " ++ pretty stt ++ " has no member named '" ++ n ++ "'" Just (t, _) -> return $ EGet st' n (Just t) - Just stt -> Left $ "Use of non-struct type " ++ pretty stt ++ " as dot-indexed expression" + Just t -> Left $ "Use of non-struct type " ++ pretty t ++ " as dot-indexed expression" annotateExpr db (ECast t e) = do e' <- annotateExpr db e let typ = fromJust (typeof e') @@ -293,6 +293,15 @@ annotateAsExpr db (AESubscript ae expr _) = do TArr t _ -> return $ AESubscript ae' expr' (Just t) t -> Left $ "Indexed expression '" ++ pretty ae ++ "' has non-array type " ++ pretty t ++ " in assignment expression" +annotateAsExpr db (AEGet ae n _) = do + ae' <- annotateAsExpr db ae + case typeof ae' of + Nothing -> Left $ "Use of void value in dot-indexed assignment expression" + Just stt@(TStruct ms) -> case find ((==n) . snd) ms of + Nothing -> Left $ "Struct of type " ++ pretty stt ++ " has no member named '" ++ n ++ + "' in assignment expression" + Just (t, _) -> return $ AEGet ae' n (Just t) + Just t -> Left $ "Use of non-struct type " ++ pretty t ++ " as dot-indexed assignment expression" resolveType :: TypeDB -> Type -> Error Type -- cgit v1.2.3-54-g00ecf