diff options
author | tomsmeding <tom.smeding@gmail.com> | 2017-09-02 10:18:40 +0200 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2017-09-02 10:18:40 +0200 |
commit | 35b17357b5b55e73c6bbc59e7dae094412b7b02a (patch) | |
tree | e3c9aa9d884a4a1c485df6f2494aca103f0351f5 /TypeCheck.hs | |
parent | 2a54765a590e1d393442262002885adcbfe156cd (diff) |
Fully support structs
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 |