diff options
Diffstat (limited to 'TypeCheck.hs')
-rw-r--r-- | TypeCheck.hs | 11 |
1 files changed, 10 insertions, 1 deletions
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 |