diff --git a/src/PrettyPrinter/Expression.hs b/src/PrettyPrinter/Expression.hs index 1582f2b..9673842 100644 --- a/src/PrettyPrinter/Expression.hs +++ b/src/PrettyPrinter/Expression.hs @@ -13,7 +13,7 @@ printExpression ExplicitEmpty = "[]" printExpression (ExplicitVariable name coer) | "item" `isPrefixOf` name = printCoercion coer $ pretty (replacePrefix "item" name "x") | otherwise = printCoercion coer $ pretty name -printExpression (Value "empty" coer) = printCoercion coer "[]" +printExpression (Value "empty" coer) = error $ show coer --printCoercion coer "[]" printExpression (Value s coer) = printCoercion coer $ pretty s printExpression (ExplicitKeyword k) = pretty k printExpression (ExplicitEnumCall name val coer) = printCoercion coer $ pretty name <> pretty val diff --git a/src/PrettyPrinter/Type.hs b/src/PrettyPrinter/Type.hs index 7b8920a..b6ed3d2 100644 --- a/src/PrettyPrinter/Type.hs +++ b/src/PrettyPrinter/Type.hs @@ -32,12 +32,12 @@ superToAttribute typ = MakeTypeAttribute "super" (MakeType typ (BasicType "Objec printAttributes :: String -> [Condition] -> [TypeAttribute] -> Doc a printAttributes objName conditions ats | MakeCondition Nothing (Keyword "one-of") `elem` conditions = vcat [nest 4 $ vcat $ - zipWith (<>) ("" : repeat "| ") (map (printSumType objName) (increaseBound ats)) ++ map printCondition conditions, " deriving (Eq)"] + zipWith (<>) ("" : repeat "| ") (map (printSumType objName) (increaseBound ats)) ++ map printCondition conditions, " deriving (Show, Eq)"] | null ats = emptyDoc | length ats < 2 = vcat [nest 4 $ vcat $ - zipWith (<>) ("" : repeat "| ") (map (printSumType objName) ats) ++ map printCondition conditions, " deriving (Eq)", printDefault objName (objName ++ capitalize (attributeName (head ats))) ats] + zipWith (<>) ("" : repeat "| ") (map (printSumType objName) ats) ++ map printCondition conditions, " deriving (Show, Eq)", printDefault objName (objName ++ capitalize (attributeName (head ats))) ats] | otherwise = vcat [nest 4 $ vcat ("Make" <> pretty objName <+> "{" : - punctuate comma (map (printAttribute objName) ats) ++ map printCondition conditions), "}"] <+> "deriving (Eq)" <> line <> printDefault objName ("Make" ++ objName) ats + punctuate comma (map (printAttribute objName) ats) ++ map printCondition conditions), "}"] <+> "deriving (Show, Eq)" <> line <> printDefault objName ("Make" ++ objName) ats -- |Converts a TypeAttribute into a haskell valid Doc printAttribute :: String -> TypeAttribute -> Doc a diff --git a/src/Semantic/ExpressionChecker.hs b/src/Semantic/ExpressionChecker.hs index ed5abb8..8256a10 100644 --- a/src/Semantic/ExpressionChecker.hs +++ b/src/Semantic/ExpressionChecker.hs @@ -222,12 +222,12 @@ checkExpression defT symbolMap (IfElse cond ex1 ex2) = Left err -> Left $ ErrorInsideFunction $ show err Right thenExp -> case checkExpression defT symbolMap ex2 of Left err -> Left $ ErrorInsideFunction $ show err - Right elseExp -> - Right $ ExplicitIfElse (condType, condCoerce) - (thenExp, MakeCoercion [MakeIdCoercion $ typeFromExpression thenExp] - (MakeCardinalityIdCoercion $ toCardinality $ cardinalityCoercion $ returnCoercion thenExp)) - (elseExp, MakeCoercion [MakeIdCoercion $ typeFromExpression elseExp] - (MakeCardinalityIdCoercion $ toCardinality $ cardinalityCoercion $ returnCoercion elseExp)) (returnCoercion thenExp) + Right elseExp -> case returnCoercion elseExp `coercionIncluded` returnCoercion thenExp of + Left _ -> Left $ IfExpressionsDifferentTypes (show thenExp) (show elseExp) + Right c -> Right $ ExplicitIfElse (condType, condCoerce) + (thenExp, MakeCoercion [MakeIdCoercion $ typeFromExpression thenExp] + (MakeCardinalityIdCoercion $ toCardinality $ cardinalityCoercion $ returnCoercion thenExp)) + (elseExp, c) (returnCoercion thenExp) --(typeMatch ex1Type ex2Type, smallestBound ex1Card ex2Type) -- |TODO Handle nested lists and lists with parens