on master help sign in
Merge branch 'master' into 146_compressdb
commitd59c0f75a205e62b70997fe852d5eb246343ee6e authorAgentM <agentm@themactionfaction.com> dateSat 23 Sep 2017, 10:29 (9 years ago) parent7e7cb57b1b6311
2 files changed+16−8
src/lib/ProjectM36/RelationalExpression.hs+6−6 test/TutorialD/Interpreter.hs+10−2
src/lib/ProjectM36/RelationalExpression.hs+6−6
@@ -399,7 +399,7 @@ evalDatabaseContextExpr (AddTypeConstructor tConsDef dConsDefList) = do
399399 errs@(_:_) -> pure $ Just (someErrors errs)
400400 [] | T.null tConsName || not (isUpper (T.head tConsName)) -> pure $ Just (InvalidAtomTypeName tConsName)
401401 | isJust (findTypeConstructor tConsName oldTypes) -> pure $ Just (AtomTypeNameInUseError tConsName)
402− | otherwise -> do
402+ | otherwise -> do
403403 let newTypes = oldTypes ++ [(tConsDef, dConsDefList)]
404404 putStateContext $ currentContext { typeConstructorMapping = newTypes }
405405 pure Nothing
@@ -766,11 +766,11 @@ typeFromAtomExpr attrs (AttributeAtomExpr attrName) = do
766766 Right aType -> pure (Right aType)
767767 Left err@(NoSuchAttributeNamesError _) -> case rstate of
768768 RelationalExprStateAttrsElems _ attrs' -> case A.attributeForName attrName attrs' of
769− Left err' -> pure (error "SPAMMO2" $ Left err')
769+ Left err' -> pure (Left err')
770770 Right attr -> pure (Right (A.atomType attr))
771− RelationalExprStateElems _ -> pure (error (show attrs) $ Left err)
771+ RelationalExprStateElems _ -> pure (Left err)
772772 RelationalExprStateTupleElems _ tup -> case atomForAttributeName attrName tup of
773− Left err' -> pure (error "STAMP" $ Left err')
773+ Left err' -> pure (Left err')
774774 Right atom -> pure (Right (atomTypeForAtom atom))
775775 Left err -> pure (Left err)
776776typeFromAtomExpr _ (NakedAtomExpr atom) = pure (Right (atomTypeForAtom atom))
@@ -808,12 +808,12 @@ verifyAtomExprTypes :: Relation -> AtomExpr -> AtomType -> RelationalExprState (
808808verifyAtomExprTypes relIn (AttributeAtomExpr attrName) expectedType = runExceptT $ do
809809 rstate <- lift ask
810810 case A.atomTypeForAttributeName attrName (attributes relIn) of
811− Right aType -> pure aType
811+ Right aType -> either throwE pure (atomTypeVerify expectedType aType)
812812 (Left err@(NoSuchAttributeNamesError _)) -> case rstate of
813813 RelationalExprStateTupleElems _ _ -> throwE err
814814 RelationalExprStateElems _ -> throwE err
815815 RelationalExprStateAttrsElems _ attrs -> case A.attributeForName attrName attrs of
816− Left err' -> throwE (error "GONK" err')
816+ Left err' -> throwE err'
817817 Right attrType -> either throwE pure (atomTypeVerify expectedType (A.atomType attrType))
818818 Left err -> throwE err
819819verifyAtomExprTypes _ (NakedAtomExpr atom) expectedType = pure (atomTypeVerify expectedType (atomTypeForAtom atom))
test/TutorialD/Interpreter.hs+10−2
@@ -54,7 +54,8 @@ main = do
5454 testFunctionalDependencies,
5555 testEmptyCommits,
5656 testIntervalAtom,
57− testListConstructedAtom
57+ testListConstructedAtom,
58+ testTypeChecker
5859 ]
5960 simpleRelTests = [("x:=true", Right relationTrue),
6061 ("x:=false", Right relationFalse),
@@ -478,4 +479,11 @@ testListConstructedAtom = TestCase $ do
478479 let err1 = "ConstructedAtomArgumentCountMismatchError 2 1"
479480 expectTutorialDErr sessionId dbconn (T.isPrefixOf err1) "z:=relation{tuple{l Cons 4}}"
480481 let err2 = "TypeConstructorAtomTypeMismatch \"List\" IntegerAtomType"
481− expectTutorialDErr sessionId dbconn (T.isPrefixOf err2) "z:=relation{tuple{l Cons 4 5}}"
482+ expectTutorialDErr sessionId dbconn (T.isPrefixOf err2) "z:=relation{tuple{l Cons 4 5}}"
483+
484+testTypeChecker :: Test
485+testTypeChecker = TestCase $ do
486+ (sessionId, dbconn) <- dateExamplesConnection emptyNotificationCallback
487+ let err1 = "AtomFunctionTypeError \"max\" 1 (RelationAtomType [Attribute \"_\" IntegerAtomType]) IntegerAtomType"
488+ expectTutorialDErr sessionId dbconn (T.isPrefixOf err1) "x:=relation{tuple{a 0}}:{b:=max(@a)}"
489+