Skip to content

Commit

Permalink
Fix type checker
Browse files Browse the repository at this point in the history
  • Loading branch information
zoep committed Sep 23, 2024
1 parent 9e60317 commit e6439c4
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/Act/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,10 @@ checkContractType env SInteger (ITE p _ a b) =
(Just c1, Just c2) -> Just c1 <$ assert (p, "Type of if-then-else branches does not match") (c1 == c2)
(_, _ )-> pure Nothing
checkContractType _ SInteger (Create _ c _) = pure $ Just c
checkContractType env SInteger var@(Var _ _ _ _) = error "TODO" -- varContractType env var
checkContractType Env{pointers} SInteger (Var _ _ _ x) =
case Map.lookup x pointers of
Just c -> pure $ Just c
Nothing -> pure Nothing

checkContractType _ _ (TEntry _ _ (Item _ (ContractType c) _)) = pure $ Just c
checkContractType _ SInteger _ = pure Nothing
Expand Down
4 changes: 4 additions & 0 deletions tests/frontend/pass/case/case.act.typed.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
},
"kind": "Behaviour",
"name": "bar",
"pointers": [],
"postConditions": [],
"preConditions": [
{
Expand Down Expand Up @@ -241,6 +242,7 @@
},
"kind": "Behaviour",
"name": "bar",
"pointers": [],
"postConditions": [],
"preConditions": [
{
Expand Down Expand Up @@ -452,6 +454,7 @@
},
"kind": "Behaviour",
"name": "bar",
"pointers": [],
"postConditions": [],
"preConditions": [
{
Expand Down Expand Up @@ -651,6 +654,7 @@
},
"invariants": [],
"kind": "Constructor",
"pointers": [],
"postConditions": [],
"preConditions": []
},
Expand Down
1 change: 1 addition & 0 deletions tests/frontend/pass/creation/create.act.typed.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
},
"invariants": [],
"kind": "Constructor",
"pointers": [],
"postConditions": [],
"preConditions": [
{
Expand Down
6 changes: 5 additions & 1 deletion tests/frontend/pass/multi/multi.act.typed.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
},
"invariants": [],
"kind": "Constructor",
"pointers": [],
"postConditions": [],
"preConditions": []
},
Expand Down Expand Up @@ -58,6 +59,7 @@
},
"kind": "Behaviour",
"name": "remote",
"pointers": [],
"postConditions": [],
"preConditions": [
{
Expand Down Expand Up @@ -260,6 +262,7 @@
},
"kind": "Behaviour",
"name": "multi",
"pointers": [],
"postConditions": [],
"preConditions": [
{
Expand Down Expand Up @@ -525,7 +528,7 @@
"kind": "SVar",
"svar": "a"
},
"type": "contract"
"type": "int"
},
"value": {
"args": [
Expand All @@ -546,6 +549,7 @@
},
"invariants": [],
"kind": "Constructor",
"pointers": [],
"postConditions": [],
"preConditions": []
},
Expand Down
2 changes: 2 additions & 0 deletions tests/frontend/pass/safemath/safemathraw.act.typed.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
},
"kind": "Behaviour",
"name": "add",
"pointers": [],
"postConditions": [],
"preConditions": [
{
Expand Down Expand Up @@ -276,6 +277,7 @@
},
"invariants": [],
"kind": "Constructor",
"pointers": [],
"postConditions": [],
"preConditions": []
},
Expand Down
2 changes: 2 additions & 0 deletions tests/frontend/pass/smoke/smoke.act.typed.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
},
"kind": "Behaviour",
"name": "f",
"pointers": [],
"postConditions": [],
"preConditions": [
{
Expand Down Expand Up @@ -92,6 +93,7 @@
},
"invariants": [],
"kind": "Constructor",
"pointers": [],
"postConditions": [],
"preConditions": []
},
Expand Down
7 changes: 7 additions & 0 deletions tests/frontend/pass/token/transfer.act.typed.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
},
"kind": "Behaviour",
"name": "transfer",
"pointers": [],
"postConditions": [],
"preConditions": [
{
Expand Down Expand Up @@ -826,6 +827,7 @@
},
"kind": "Behaviour",
"name": "transfer",
"pointers": [],
"postConditions": [],
"preConditions": [
{
Expand Down Expand Up @@ -1356,6 +1358,7 @@
},
"kind": "Behaviour",
"name": "transferFrom",
"pointers": [],
"postConditions": [],
"preConditions": [
{
Expand Down Expand Up @@ -2473,6 +2476,7 @@
},
"kind": "Behaviour",
"name": "transferFrom",
"pointers": [],
"postConditions": [],
"preConditions": [
{
Expand Down Expand Up @@ -3686,6 +3690,7 @@
},
"kind": "Behaviour",
"name": "transferFrom",
"pointers": [],
"postConditions": [],
"preConditions": [
{
Expand Down Expand Up @@ -4984,6 +4989,7 @@
},
"kind": "Behaviour",
"name": "transferFrom",
"pointers": [],
"postConditions": [],
"preConditions": [
{
Expand Down Expand Up @@ -6132,6 +6138,7 @@
}
],
"kind": "Constructor",
"pointers": [],
"postConditions": [],
"preConditions": [
{
Expand Down

0 comments on commit e6439c4

Please sign in to comment.