on master help sign in
fix type checking in attribute equality restrictions
commitf1f00f73c6800d180c4d52ec0c7304854d2ef092 authorAgentM <agentm@themactionfaction.com> dateSat 13 Jun 2015, 12:38 (11 years ago) parent6ea5f34
2 files changed+12−6
ProjectM36/Attribute.hs+1−1 ProjectM36/RelationalExpression.hs+11−5
ProjectM36/Attribute.hs+1−1
@@ -17,7 +17,7 @@ null :: Attributes -> Bool
1717null = V.null
1818
1919attributesFromList :: [Attribute] -> Attributes
20−attributesFromList = V.fromList -- . L.nub
20+attributesFromList = V.fromList -- . L.nub --too expensive
2121
2222attributeName :: Attribute -> AttributeName
2323attributeName (Attribute name _) = name
ProjectM36/RelationalExpression.hs+11−5
@@ -378,12 +378,18 @@ predicateRestrictionFilter context _ (RelationalExprPredicate relExpr) = case ru
378378 else
379379 Left $ PredicateExpressionError "Relational restriction filter must evaluate to 'true' or 'false'"
380380
381−predicateRestrictionFilter context _ (AttributeEqualityPredicate attrName atomexpr) = Right $ \tupleIn -> case atomForAttributeName attrName tupleIn of
382− Left _ -> False
383− Right atomIn ->
384− case evalAtomExpr tupleIn context atomexpr of
381+predicateRestrictionFilter context attrs (AttributeEqualityPredicate attrName atomExpr) = do
382+ attr <- A.attributeForName attrName attrs
383+ atomExprType <- typeFromAtomExpr attrs context atomExpr
384+ if atomExprType /= A.atomType attr then
385+ Left $ TupleAttributeTypeMismatchError (A.attributesFromList [attr])
386+ else
387+ Right $ \tupleIn -> case atomForAttributeName attrName tupleIn of
385388 Left _ -> False
386− Right atomCmp -> atomCmp == atomIn
389+ Right atomIn ->
390+ case evalAtomExpr tupleIn context atomExpr of
391+ Left _ -> False
392+ Right atomCmp -> atomCmp == atomIn
387393
388394-- in the future, it would be useful to do typechecking on the attribute and atom expr filters in advance
389395predicateRestrictionFilter context attrs (AtomExprPredicate atomExpr) = do