Skip to content

Commit

Permalink
fix(typechecker): location of errors (#1132)
Browse files Browse the repository at this point in the history
* fix(typechecker): location of errors for wrong constructors in pattern-matching (#1131)

* Add test for `0:0` location

* fix(scilla-base): `0:0` locations of errors/warnings (#1133)

* fix(scilla-base): Fix location of warnings for transitions w/o `accept`

* fix(scilla-base): Fix location for type errors

Co-authored-by: Georgiy Komarov <georgiy@zilliqa.com>
  • Loading branch information
Anton Trunov and jubnzv committed Aug 3, 2022
1 parent 3ff5909 commit 1b6ae41
Show file tree
Hide file tree
Showing 94 changed files with 620 additions and 357 deletions.
3 changes: 2 additions & 1 deletion src/base/Accept.ml
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,11 @@ struct
in

if List.for_all all_accept_groups ~f:List.is_empty then
warn0
warn1
(sprintf "No transition in contract %s contains an accept statement\n"
(ACIdentifier.as_error_string contr.cname))
warning_level_missing_accept
(SR.get_loc (ACIdentifier.get_rep contr.cname))

(* ************************************** *)
(* ******** Interface to Accept ********* *)
Expand Down
2 changes: 1 addition & 1 deletion src/base/PatternChecker.ml
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ struct
let { cname = ctr_cname; cparams; cconstraint; cfields; ccomps } = contr in
let kind = "Type error(s) in contract"
and inst = PCIdentifier.as_error_string ctr_cname ^ "\n" in
wrap_with_info ~kind ~inst dummy_loc
wrap_with_info ~kind ~inst (SR.get_loc (PCIdentifier.get_rep ctr_cname))
@@ let%bind checked_rlibs = pm_check_libentries rlibs in
let%bind checked_elibs = mapM elibs ~f:pm_check_libtree in

Expand Down
2 changes: 1 addition & 1 deletion src/base/TypeUtil.ml
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ module TypeUtilities = struct
%s is given"
(as_string name)
(TUName.as_string adt.tname))
(get_rep name)
lc
| _ -> fail1 ~kind:"Not an algebraic data type" ~inst:(pp_typ_error atyp) lc
let constr_pattern_arg_types ?(lc = dummy_loc) atyp cn =
Expand Down
1 change: 1 addition & 0 deletions tests/checker/bad/Bad.ml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ module Tests = Scilla_test.Util.DiffBasedTests (struct
"bad_cast_1.scilla";
"bad_cast_2.scilla";
"bad_cast_3.scilla";
"pm-error.scilla";
]

let exit_code : UnixLabels.process_status = WEXITED 1
Expand Down
12 changes: 7 additions & 5 deletions tests/checker/bad/gold/bad_lib_pm_import.scilla.gold
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
"errors": [
{
"error_message": "Type error(s) in contract: BadLibPM\n",
"start_location": { "file": "", "line": 0, "column": 0 },
"start_location": {
"file": "checker/bad/bad_lib_pm_import.scilla",
"line": 7,
"column": 10
},
"end_location": { "file": "", "line": 0, "column": 0 }
},
{
"error_message":
"Error during pattern-match checking of library: badpm",
"error_message": "Error during pattern-match checking of library: badpm",
"start_location": {
"file": "checker/bad/lib/BadPMLib.scillib",
"line": 5,
Expand All @@ -17,8 +20,7 @@
"end_location": { "file": "", "line": 0, "column": 0 }
},
{
"error_message":
"Type error in pattern matching on `b` of type Bool (or one of its branches):\nNon-exhaustive pattern match.",
"error_message": "Type error in pattern matching on `b` of type Bool (or one of its branches):\nNon-exhaustive pattern match.",
"start_location": {
"file": "checker/bad/lib/BadPMLib.scillib",
"line": 7,
Expand Down
9 changes: 6 additions & 3 deletions tests/checker/bad/gold/bad_message2.scilla.gold
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@
],
"warnings": [
{
"warning_message":
"No transition in contract Empty contains an accept statement\n",
"start_location": { "file": "", "line": 0, "column": 0 },
"warning_message": "No transition in contract Empty contains an accept statement\n",
"start_location": {
"file": "checker/bad/bad_message2.scilla",
"line": 11,
"column": 10
},
"end_location": { "file": "", "line": 0, "column": 0 },
"warning_id": 1
}
Expand Down
12 changes: 7 additions & 5 deletions tests/checker/bad/gold/bad_version.scilla.gold
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
{
"errors": [
{
"error_message":
"Scilla version mismatch. Expected 0 vs Contract 99999\n",
"error_message": "Scilla version mismatch. Expected 0 vs Contract 99999\n",
"start_location": { "file": "", "line": 0, "column": 0 },
"end_location": { "file": "", "line": 0, "column": 0 }
}
],
"warnings": [
{
"warning_message":
"No transition in contract Empty contains an accept statement\n",
"start_location": { "file": "", "line": 0, "column": 0 },
"warning_message": "No transition in contract Empty contains an accept statement\n",
"start_location": {
"file": "checker/bad/bad_version.scilla",
"line": 3,
"column": 10
},
"end_location": { "file": "", "line": 0, "column": 0 },
"warning_id": 1
}
Expand Down
9 changes: 6 additions & 3 deletions tests/checker/bad/gold/mappair2.scilla.gold
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,12 @@
"warning_id": 1
},
{
"warning_message":
"No transition in contract Test contains an accept statement\n",
"start_location": { "file": "", "line": 0, "column": 0 },
"warning_message": "No transition in contract Test contains an accept statement\n",
"start_location": {
"file": "checker/bad/mappair2.scilla",
"line": 30,
"column": 10
},
"end_location": { "file": "", "line": 0, "column": 0 },
"warning_id": 1
}
Expand Down
12 changes: 7 additions & 5 deletions tests/checker/bad/gold/match-in-transition.scilla.gold
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
"errors": [
{
"error_message": "Type error(s) in contract: Matcher\n",
"start_location": { "file": "", "line": 0, "column": 0 },
"start_location": {
"file": "checker/bad/match-in-transition.scilla",
"line": 3,
"column": 10
},
"end_location": { "file": "", "line": 0, "column": 0 }
},
{
"error_message":
"Error during pattern-match checking of component: transition foo:\n",
"error_message": "Error during pattern-match checking of component: transition foo:\n",
"start_location": {
"file": "checker/bad/match-in-transition.scilla",
"line": 7,
Expand All @@ -17,8 +20,7 @@
"end_location": { "file": "", "line": 0, "column": 0 }
},
{
"error_message":
"Type error in pattern matching on `x` (or one of its branches):\nNon-exhaustive pattern match.",
"error_message": "Type error in pattern matching on `x` (or one of its branches):\nNon-exhaustive pattern match.",
"start_location": {
"file": "checker/bad/match-in-transition.scilla",
"line": 10,
Expand Down
9 changes: 6 additions & 3 deletions tests/checker/bad/gold/name_clashes.scilla.gold
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@
],
"warnings": [
{
"warning_message":
"No transition in contract TransitionAndProcedureNameClashes contains an accept statement\n",
"start_location": { "file": "", "line": 0, "column": 0 },
"warning_message": "No transition in contract TransitionAndProcedureNameClashes contains an accept statement\n",
"start_location": {
"file": "checker/bad/name_clashes.scilla",
"line": 5,
"column": 10
},
"end_location": { "file": "", "line": 0, "column": 0 },
"warning_id": 1
}
Expand Down
15 changes: 15 additions & 0 deletions tests/checker/bad/gold/pm-error.scilla.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"gas_remaining": "8000",
"errors": [
{
"error_message": "Wrong constructor in pattern matching: Expected a constructor of type Bool, but a constructor of type Option is given",
"start_location": {
"file": "checker/bad/pm-error.scilla",
"line": 13,
"column": 5
},
"end_location": { "file": "", "line": 0, "column": 0 }
}
],
"warnings": []
}
12 changes: 7 additions & 5 deletions tests/checker/bad/gold/zil_mod.scilla.gold
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
"errors": [
{
"error_message": "Type error(s) in contract: ZilGame\n",
"start_location": { "file": "", "line": 0, "column": 0 },
"start_location": {
"file": "checker/bad/zil_mod.scilla",
"line": 141,
"column": 10
},
"end_location": { "file": "", "line": 0, "column": 0 }
},
{
"error_message":
"Error during pattern-match checking of library: check_validity",
"error_message": "Error during pattern-match checking of library: check_validity",
"start_location": {
"file": "checker/bad/zil_mod.scilla",
"line": 69,
Expand All @@ -17,8 +20,7 @@
"end_location": { "file": "", "line": 0, "column": 0 }
},
{
"error_message":
"Type error in pattern matching on `xa` of type Pair (Bool) (Option (ByStr32)) (or one of its branches):\nPattern is unreachable: 3",
"error_message": "Type error in pattern matching on `xa` of type Pair (Bool) (Option (ByStr32)) (or one of its branches):\nPattern is unreachable: 3",
"start_location": {
"file": "checker/bad/zil_mod.scilla",
"line": 80,
Expand Down
16 changes: 16 additions & 0 deletions tests/checker/bad/pm-error.scilla
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
scilla_version 0

library Dead6

let x = Int32 19
let y = Int32 23

contract Dead6()

transition dummy ()
equals = builtin eq x y;
match equals with
| Some equals =>
| None =>
end
end
9 changes: 6 additions & 3 deletions tests/checker/good/gold/UintParam.scilla.gold
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,12 @@
"warning_id": 3
},
{
"warning_message":
"No transition in contract UintParam contains an accept statement\n",
"start_location": { "file": "", "line": 0, "column": 0 },
"warning_message": "No transition in contract UintParam contains an accept statement\n",
"start_location": {
"file": "contracts/UintParam.scilla",
"line": 5,
"column": 10
},
"end_location": { "file": "", "line": 0, "column": 0 },
"warning_id": 1
}
Expand Down

0 comments on commit 1b6ae41

Please sign in to comment.