Skip to content

Commit a9c363d

Browse files
joelburgetbts
authored andcommitted
Fix some nits.
1 parent 96a1064 commit a9c363d

File tree

2 files changed

+38
-36
lines changed

2 files changed

+38
-36
lines changed

‎src/Pact/Analyze/Check.hs‎

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ import qualified Pact.Types.Runtime as Pact
6464
import Pact.Types.Typecheck (AST,
6565
Fun (FDefun, _fArgs, _fBody, _fInfo),
6666
Named, Node, TcId (_tiInfo),
67-
TopLevel (TopFun, TopTable),
68-
UserType (_utFields, _utName),
69-
runTC, tcFailures)
67+
TopLevel (TopFun, TopTable,
68+
_tlInfo), UserType (_utFields,
69+
_utName), runTC, tcFailures)
7070
import qualified Pact.Types.Typecheck as TC
7171

7272
import Pact.Analyze.Analyze hiding (invariants)
@@ -649,9 +649,9 @@ verifyFunctionInvariants tables ref = do
649649
else
650650
let parsed = infoToParsed _fInfo
651651
in pure (Left (CheckFailure parsed (TypecheckFailure failures)))
652-
653-
-- TODO: should this be an error?
654-
_ -> pure $ Right $ TableMap Map.empty
652+
other ->
653+
let parsed = infoToParsed (_tlInfo other)
654+
in pure $ Left (CheckFailure parsed (NotAFunction (tShow ref)))
655655

656656
-- | Verifies properties on all functions, and that each function maintains all
657657
-- invariants.
@@ -679,31 +679,35 @@ verifyModule modules moduleData = do
679679
HM.empty
680680
funRefs
681681

682-
case tables of
683-
Left errs -> pure (ModuleParseFailures errs)
684-
Right tables' -> do
685-
686-
let funChecks :: HM.HashMap Text (Ref, Either [ParseFailure] [(Parsed, Check)])
687-
funChecks = moduleFunChecks tables' funTypes
688-
689-
funChecks' :: Either [ParseFailure] (HM.HashMap Text (Ref, [(Parsed, Check)]))
690-
funChecks' = sequence (fmap sequence funChecks)
691-
692-
verifyFunProps :: (Ref, [(Parsed, Check)]) -> IO [CheckResult]
693-
verifyFunProps = uncurry (verifyFunctionProps tables')
694-
695-
case funChecks' of
696-
Left errs -> pure (ModuleParseFailures errs)
697-
Right funChecks'' -> do
698-
funChecks''' <- traverse verifyFunProps funChecks''
699-
invariantChecks <- runExceptT $ for funRefs $ \ref -> do
700-
tabledResults <- lift $ verifyFunctionInvariants tables' ref
701-
case tabledResults of
702-
Left err -> throwError err
703-
Right results -> pure results
704-
pure $ case invariantChecks of
705-
Left err -> ModuleCheckFailure err
706-
Right invariantChecks' -> ModuleChecks funChecks''' invariantChecks'
682+
runExceptT' $ do
683+
tables' <- case tables of
684+
Left errs -> throwError (ModuleParseFailures errs)
685+
Right tables' -> pure tables'
686+
687+
let funChecks :: HM.HashMap Text (Ref, Either [ParseFailure] [(Parsed, Check)])
688+
funChecks = moduleFunChecks tables' funTypes
689+
690+
funChecks' :: Either [ParseFailure] (HM.HashMap Text (Ref, [(Parsed, Check)]))
691+
funChecks' = sequence (fmap sequence funChecks)
692+
693+
verifyFunProps :: (Ref, [(Parsed, Check)]) -> IO [CheckResult]
694+
verifyFunProps = uncurry (verifyFunctionProps tables')
695+
696+
funChecks'' <- case funChecks' of
697+
Left errs -> throwError (ModuleParseFailures errs)
698+
Right funChecks'' -> pure funChecks''
699+
700+
funChecks''' <- lift $ traverse verifyFunProps funChecks''
701+
invariantChecks <- for funRefs $ \ref -> do
702+
tabledResults <- lift $ verifyFunctionInvariants tables' ref
703+
case tabledResults of
704+
Left err -> throwError $ ModuleCheckFailure err
705+
Right results -> pure results
706+
707+
pure $ ModuleChecks funChecks''' invariantChecks
708+
709+
runExceptT' :: Functor m => ExceptT a m a -> m a
710+
runExceptT' = fmap (either id id) . runExceptT
707711

708712
-- | Verifies a one-off 'Check' for a function.
709713
verifyCheck

‎tests/AnalyzeSpec.hs‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,10 @@ runVerification code = do
100100
ModuleChecks propResults invariantResults -> pure $
101101
case findOf (traverse . traverse) isLeft propResults of
102102
Just (Left failure) -> Just $ TestCheckFailure failure
103-
_ -> case findOf (traverse . traverse . traverse) isLeft invariantResults of
103+
_ -> case findOf (traverse . traverse . traverse) isLeft invariantResults of
104+
104105
Just (Left failure) -> Just $ TestCheckFailure failure
106+
Just (Right _) -> error "impossible: result of isLeft"
105107
Nothing -> Nothing
106108

107109
runCheck :: Text -> Check -> IO (Maybe TestFailure)
@@ -142,7 +144,6 @@ decConserves tn cn = PDecimalComparison Eq 0 $
142144

143145
spec :: Spec
144146
spec = describe "analyze" $ do
145-
-- {-
146147
describe "result" $ do
147148
let code =
148149
[text|
@@ -650,7 +651,6 @@ spec = describe "analyze" $ do
650651

651652
expectVerified code
652653
expectPass code $ Valid $ Success ==> decConserves "accounts2" "balance"
653-
-- -}
654654

655655
describe "conserves-mass.decimal.failing-invariant" $ do
656656
let code =
@@ -710,7 +710,6 @@ spec = describe "analyze" $ do
710710
it "should have no keyset provenance" $ do
711711
ksProvs `shouldBe` Map.empty
712712

713-
-- {-
714713
describe "cell-delta.integer" $ do
715714
let code =
716715
[text|
@@ -1470,4 +1469,3 @@ spec = describe "analyze" $ do
14701469
-- TODO(bts): test that execution traces include auth metadata (arg vs row vs
14711470
-- named)
14721471
--
1473-
-- -}

0 commit comments

Comments
 (0)