Added "did you mean" feature for unbound type names

This commit is contained in:
Suzanne Dupéron 2019-12-17 22:46:36 +00:00
parent 2a11c6d180
commit a835bc9286
2 changed files with 11 additions and 1 deletions

View File

@ -12,13 +12,19 @@ type environment = Environment.t
module Errors = struct
let unbound_type_variable (e:environment) (tv:I.type_variable) () =
let name = Var.to_name tv in
let suggestion = match name with
| "integer" -> "int"
| "str" -> "string"
| _ -> "no suggestion" in
let title = (thunk "unbound type variable") in
let message () = "" in
let data = [
("variable" , fun () -> Format.asprintf "%a" Stage_common.PP.type_variable tv) ;
(* TODO: types don't have srclocs for now. *)
(* ("location" , fun () -> Format.asprintf "%a" Location.pp (n.location)) ; *)
("in" , fun () -> Format.asprintf "%a" Environment.PP.full_environment e)
("in" , fun () -> Format.asprintf "%a" Environment.PP.full_environment e) ;
("did_you_mean" , fun () -> suggestion)
] in
error ~data title message ()

View File

@ -0,0 +1,4 @@
let foo : integer = 3
let main (p:int) (storage : int) =
(([] : operation list) , p + foo)