@@ -489,7 +489,7 @@ andExps (c:cs) = foldl (\cs' c' -> And nowhere c' cs') c cs
489489
490490-- | Check the type of an expression and construct a typed expression
491491checkExpr :: forall a t . Typeable t => Env -> SType a -> U. Expr -> Err (Exp a t )
492- checkExpr env@ Env {constructors} typ e = case (typ, e) of
492+ checkExpr env@ Env {constructors, calldata } typ e = case (typ, e) of
493493 -- Boolean expressions
494494 (SBoolean , U. ENot p v1) -> Neg p <$> checkExpr env SBoolean v1
495495 (SBoolean , U. EAnd p v1 v2) -> And p <$> checkExpr env SBoolean v1 <*> checkExpr env SBoolean v2
@@ -516,8 +516,8 @@ checkExpr env@Env{constructors} typ e = case (typ, e) of
516516 (SInteger , U. ECreate p c args) -> case Map. lookup c constructors of
517517 Just ctrs ->
518518 let (typs, ptrs) = unzip ctrs in
519- checkIxs env p args (fmap PrimitiveType typs) `bindValidation` (\ args ->
520- pure (Create p c args) <* traverse_ (\ (e, t) -> checkContractType env e t) (zip args ptrs))
519+ checkIxs env p args (fmap PrimitiveType typs) `bindValidation` (\ args' ->
520+ pure (Create p c args' ) <* traverse_ (\ (e' , t) -> checkContractType env e' t) (zip args' ptrs))
521521 Nothing -> throw (p, " Unknown constructor " <> show c)
522522
523523 -- Control
@@ -537,16 +537,16 @@ checkExpr env@Env{constructors} typ e = case (typ, e) of
537537 _ -> throw (p, " Unknown environment variable " <> show v1)
538538
539539 -- Variable references
540- (_, U. EUTEntry entry) | isCalldataEntry env entry -> -- TODO more principled way of treating timings
540+ (_, U. EUTEntry entry) | isCalldataEntry entry -> -- TODO more principled way of treating timings
541541 case (eqT @ t @ Timed , eqT @ t @ Untimed ) of
542542 (Just Refl , _) -> validateVar env entry `bindValidation` \ (vt@ (FromVType typ'), ref) ->
543543 Var (getPosEntry entry) Pre typ vt ref <$ checkEq (getPosEntry entry) typ typ'
544544 (_, Just Refl ) -> validateVar env entry `bindValidation` \ (vt@ (FromVType typ'), ref) ->
545545 Var (getPosEntry entry) Neither typ vt ref <$ checkEq (getPosEntry entry) typ typ'
546546 (_,_) -> error " Internal error: Timing should be either Timed or Untimed"
547547 -- Var (getPosEntry entry) Neither typ vt ref <$ checkEq (getPosEntry entry) typ typ'
548- (_, U. EPreEntry entry) | isCalldataEntry env entry -> error " Not supported"
549- (_, U. EPostEntry entry) | isCalldataEntry env entry -> error " Not supported"
548+ (_, U. EPreEntry entry) | isCalldataEntry entry -> error " Not supported"
549+ (_, U. EPostEntry entry) | isCalldataEntry entry -> error " Not supported"
550550 -- Storage references
551551 (_, U. EUTEntry entry) -> validateEntry env entry `bindValidation` \ (vt@ (FromVType typ'), ref) ->
552552 checkTime (getPosEntry entry) <*> (TEntry (getPosEntry entry) Neither (Item typ vt ref) <$ checkEq (getPosEntry entry) typ typ')
@@ -576,11 +576,11 @@ checkExpr env@Env{constructors} typ e = case (typ, e) of
576576 Nothing -> throw (pn, (tail . show $ typeRep @ t ) <> " variable needed here." )
577577
578578 -- TODO FIX
579- isCalldataEntry Env {calldata} (U. EVar _ name) = case Map. lookup name calldata of
579+ isCalldataEntry (U. EVar _ name) = case Map. lookup name calldata of
580580 Just _ -> True
581581 _ -> False
582- isCalldataEntry env (U. EMapping _ entry _) = isCalldataEntry env entry
583- isCalldataEntry env (U. EField _ entry _) = isCalldataEntry env entry
582+ isCalldataEntry (U. EMapping _ entry _) = isCalldataEntry entry
583+ isCalldataEntry (U. EField _ entry _) = isCalldataEntry entry
584584
585585
586586-- | Find the contract id of an expression with contract type
@@ -601,9 +601,9 @@ checkContractType :: Env -> TypedExp t -> Maybe Id -> Err ()
601601checkContractType _ _ Nothing = pure ()
602602checkContractType env (TExp _ e) (Just c) =
603603 findContractType env e `bindValidation` \ oc ->
604- case oc of -- TODO fix position
605- Just c' -> assert (nowhere , " Expression was expected to have contract type " <> c <> " but has contract type " <> c') (c == c')
606- Nothing -> throw (nowhere , " Expression was expected to have contract type " <> c)
604+ case oc of
605+ Just c' -> assert (posnFromExp e , " Expression was expected to have contract type " <> c <> " but has contract type " <> c') (c == c')
606+ Nothing -> throw (posnFromExp e , " Expression was expected to have contract type " <> c)
607607
608608checkEq :: forall a b . Pn -> SType a -> SType b -> Err ()
609609checkEq p t1 t2 = maybe err (\ Refl -> pure () ) $ testEquality t1 t2
0 commit comments