Skip to content

Commit

Permalink
some errors are now emitted in a centralised fashion
Browse files Browse the repository at this point in the history
  • Loading branch information
ggreif committed Dec 10, 2024
1 parent ec31258 commit ca66302
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
2 changes: 0 additions & 2 deletions src/lang_utils/error_codes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,7 @@ let error_codes : (string * string option) list =
"M0198", Some([%blob "lang_utils/error_codes/M0198.md"]); (* Unused field pattern warning *)
"M0199", Some([%blob "lang_utils/error_codes/M0199.md"]); (* Deprecate experimental stable memory *)
"M0200", Some([%blob "lang_utils/error_codes/M0200.md"]); (* Cannot determine subtyping or equality *)
"M0201", None; (* `cycle` attribute in parenthetical note must be of type `Nat` *)
"M0202", None; (* parenthetical note must be applied to a message send *)
"M0203", None; (* parenthetical note has no attributes *)
"M0204", Some([%blob "lang_utils/error_codes/M0204.md"]); (* Unrecognised attribute in parenthetical note *)
"M0205", None; (* `timeout` attribute in parenthetical note must be of type `Nat32` *)
]
7 changes: 2 additions & 5 deletions src/mo_frontend/typing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2578,20 +2578,17 @@ and validate_parenthetical env typ_opt = function
end
| _ -> ()
end;
(*let [@warning "-8"] ObjE (bases, fields) = par.it in*)
let [@warning "-8"] par_infer env { it = ObjE (bases, fields); _ } =
let checked = T.[ { lab = "cycles"; typ = nat; src = empty_src}
; { lab = "timeout"; typ = nat32; src = empty_src}
] in
infer_check_bases_fields env checked par.at bases fields in
let attrs = infer_exp_wrapper par_infer T.as_immut env par in
(*let attrs = infer_check_bases_fields env checked par.at bases fields in*)
(*let attrs = infer_exp env par in*)
let [@warning "-8"] T.Object, attrs_flds = T.as_obj attrs in
if attrs_flds = [] then warn env par.at "M0203" "redundant empty parenthetical note";
let unrecognised = List.(filter (fun {T.lab; _} -> lab <> "cycles" && lab <> "timeout") attrs_flds |> map (fun {T.lab; _} -> lab)) in
if unrecognised <> [] then warn env par.at "M0204" "unrecognised attribute %s in parenthetical note" (List.hd unrecognised);
let cyc = List.(filter (fun {T.lab; _} -> lab = "cycles") attrs_flds) in
(*let cyc = List.(filter (fun {T.lab; _} -> lab = "cycles") attrs_flds) in
if cyc <> [] && not T.(sub (List.hd cyc).typ nat) then
local_error env par.at "M0201"
"expected Nat type for attribute cycles, but it has type%a"
Expand All @@ -2600,7 +2597,7 @@ and validate_parenthetical env typ_opt = function
if timeout <> [] && not T.(sub (List.hd timeout).typ nat32) then
local_error env par.at "M0205"
"expected Nat32 type for attribute timeout, but it has type%a"
display_typ_expand (List.hd timeout).T.typ
display_typ_expand (List.hd timeout).T.typ*)

and check_system_fields env sort scope tfs dec_fields =
List.iter (fun df ->
Expand Down
14 changes: 9 additions & 5 deletions test/fail/ok/cycle-type.tc.ok
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
cycle-type.mo:4.44-4.51: warning [M0204], unrecognised attribute moot in parenthetical note
cycle-type.mo:4.44-4.51: type error [M0201], expected Nat type for attribute cycles, but it has type
cycle-type.mo:4.39-4.42: type error [M0050], literal of type
Char
cycle-type.mo:5.48-5.56: warning [M0204], unrecognised attribute moot in parenthetical note
cycle-type.mo:5.48-5.56: type error [M0201], expected Nat type for attribute cycles, but it has type
does not have expected type
Nat
cycle-type.mo:5.39-5.46: type error [M0050], literal of type
Text
does not have expected type
Nat
cycle-type.mo:7.23-7.32: warning [M0202], unexpected parenthetical note on a non-send call
cycle-type.mo:7.23-7.32: warning [M0203], redundant empty parenthetical note
cycle-type.mo:9.19-9.29: warning [M0203], redundant empty parenthetical note
cycle-type.mo:10.36-10.43: type error [M0205], expected Nat32 type for attribute timeout, but it has type
cycle-type.mo:10.31-10.34: type error [M0050], literal of type
Char
does not have expected type
Nat32

0 comments on commit ca66302

Please sign in to comment.