Skip to content
This repository has been archived by the owner on Sep 7, 2023. It is now read-only.

Commit

Permalink
fix(typing) Type soundness bug for match expressions #645
Browse files Browse the repository at this point in the history
Signed-off-by: Jerome Simeon <jeromesimeon@me.com>
  • Loading branch information
jeromesimeon committed Sep 6, 2019
1 parent a808135 commit 9c6c60b
Show file tree
Hide file tree
Showing 10 changed files with 1,477 additions and 1,380 deletions.
3 changes: 3 additions & 0 deletions examples/opttest/contract.json
@@ -0,0 +1,3 @@
{
"$class": "org.accordproject.opttest.TemplateModel"
}
44 changes: 44 additions & 0 deletions examples/opttest/logic.ergo
@@ -0,0 +1,44 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace org.accordproject.opttest

contract OptTest over TemplateModel {
// Simple Clause
clause test(request : Request) : Response {
let foo : Nothing? = // This should fail
match request
with let x : Request then some(1)
else none;

let foo : Nothing? = // This should fail
match some(request)
with let? x : Request then some(1)
else none;

let foo : Nothing? = // This should fail
match request
with let x then some(1)
else none;

let foo : Nothing? = // This should fail
match some(request)
with let? x then some(1)
else none;

return Response{
test1:1
}
}
}
29 changes: 29 additions & 0 deletions examples/opttest/model.cto
@@ -0,0 +1,29 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace org.accordproject.opttest

transaction Request {
}

transaction Response {
o Integer test1
}

/**
* The template model
*/
@AccordTemplateModel("opttest")
concept TemplateModel {
}
3 changes: 3 additions & 0 deletions examples/opttest/request.json
@@ -0,0 +1,3 @@
{
"$class": "org.accordproject.opttest.Request"
}
2 changes: 2 additions & 0 deletions examples/opttest/state.json
@@ -0,0 +1,2 @@
{ "$class": "org.accordproject.cicero.contract.AccordContractState",
"stateId" : "1" }
28 changes: 15 additions & 13 deletions mechanization/ErgoC/Lang/ErgoCTypecheck.v
Expand Up @@ -249,6 +249,19 @@ Section ErgoCTypecheck.
((CaseLet (prov,sofart) name None,eT)::fst sofarT, sofart))
sofarT
(ergoc_typecheck_expr nsctxt (type_context_update_local_env ctxt name t0) res)
| (CaseLet prov name (Some b), res) =>
elift2 (fun sofarT eT =>
let et := exprct_type_annot eT in
let sofart := ergoc_type_join et (snd sofarT) in
((CaseLet (prov,sofart) name (Some b), eT)::fst sofarT, sofart))
sofarT
(ergoc_typecheck_expr
nsctxt
(type_context_update_local_env
ctxt
name
(tbrand (b::nil)))
res)
| (CaseLetOption prov name None, res) =>
match unteither t0 with
| None =>
Expand All @@ -267,7 +280,8 @@ Section ErgoCTypecheck.
case_option_not_on_either_error prov
| Some (st, ft) =>
elift2 (fun sofarT eT =>
let sofart := snd sofarT in
let et := exprct_type_annot eT in
let sofart := ergoc_type_join et (snd sofarT) in
((CaseLetOption (prov,sofart) name (Some b), eT)::fst sofarT, sofart))
sofarT
(ergoc_typecheck_expr
Expand All @@ -283,18 +297,6 @@ Section ErgoCTypecheck.
((CaseWildcard (prov,sofart) (Some b), eT)::fst sofarT, sofart))
sofarT
(ergoc_typecheck_expr nsctxt ctxt res)
| (CaseLet prov name (Some b), res) =>
elift2 (fun sofarT eT =>
let sofart := snd sofarT in
((CaseLet (prov,sofart) name (Some b), eT)::fst sofarT, sofart))
sofarT
(ergoc_typecheck_expr
nsctxt
(type_context_update_local_env
ctxt
name
(tbrand (b::nil)))
res)
end)
(esuccess (nil, dt) nil)
pes))
Expand Down
1,218 changes: 609 additions & 609 deletions packages/ergo-cli/extracted/ergoccore.js

Large diffs are not rendered by default.

516 changes: 258 additions & 258 deletions packages/ergo-cli/extracted/ergotopcore.js

Large diffs are not rendered by default.

1,000 changes: 500 additions & 500 deletions packages/ergo-compiler/extracted/compilercore.js

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions packages/ergo-engine/test/workload.json
Expand Up @@ -51,6 +51,20 @@
}
}
},
{
"name": "opttest",
"dir": "examples/opttest",
"ergo": ["logic.ergo"],
"models": ["model.cto"],
"contract": "contract.json",
"request": "request.json",
"state": "state.json",
"contractName": "org.accordproject.opttest.OptTest",
"currentTime": null,
"expected": {
"error": "Type error (at file examples/opttest/logic.ergo line 20 col 2). The let type annotation `Nothing?' for the name `foo' does not match the actual type `Integer?'.\n let foo : Nothing? = // This should fail\n ^ "
}
},
{
"name": "helloworldstate",
"dir": "examples/helloworldstate",
Expand Down

0 comments on commit 9c6c60b

Please sign in to comment.