From 3288696784271525c04562769a5aa19925164304 Mon Sep 17 00:00:00 2001 From: Lesenechal Remi Date: Thu, 2 Jan 2020 19:30:09 +0100 Subject: [PATCH 1/3] add the name of the variable in the unbound variable error message title --- src/passes/4-typer-new/typer.ml | 5 +++-- src/passes/4-typer-old/typer.ml | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/passes/4-typer-new/typer.ml b/src/passes/4-typer-new/typer.ml index f22dd61f9..ea607c505 100644 --- a/src/passes/4-typer-new/typer.ml +++ b/src/passes/4-typer-new/typer.ml @@ -23,10 +23,11 @@ module Errors = struct error ~data title message () let unbound_variable (e:environment) (n:I.expression_variable) (loc:Location.t) () = - let title = (thunk "unbound variable") in + let name = Format.asprintf "%a" Stage_common.PP.name n in + let title = (thunk ("unbound variable "^name)) in let message () = "" in let data = [ - ("variable" , fun () -> Format.asprintf "%a" Stage_common.PP.name n) ; + ("variable" , fun () -> name) ; ("environment" , fun () -> Format.asprintf "%a" Environment.PP.full_environment e) ; ("location" , fun () -> Format.asprintf "%a" Location.pp loc) ] in diff --git a/src/passes/4-typer-old/typer.ml b/src/passes/4-typer-old/typer.ml index b54b7e579..ff0ef2fe9 100644 --- a/src/passes/4-typer-old/typer.ml +++ b/src/passes/4-typer-old/typer.ml @@ -30,10 +30,11 @@ module Errors = struct error ~data title message () let unbound_variable (e:environment) (n:I.expression_variable) (loc:Location.t) () = - let title = (thunk "unbound variable") in + let name = Format.asprintf "%a" Stage_common.PP.name n in + let title = (thunk ("unbound variable "^name)) in let message () = "" in let data = [ - ("variable" , fun () -> Format.asprintf "%a" Stage_common.PP.name n) ; + ("variable" , fun () -> name) ; ("environment" , fun () -> Format.asprintf "%a" Environment.PP.full_environment e) ; ("location" , fun () -> Format.asprintf "%a" Location.pp loc) ] in From 4d56a71bd1ab74f90c88387180b67a9352370302 Mon Sep 17 00:00:00 2001 From: Lesenechal Remi Date: Thu, 2 Jan 2020 19:30:19 +0100 Subject: [PATCH 2/3] propagate location for cameligo variables --- src/passes/2-simplify/cameligo.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/passes/2-simplify/cameligo.ml b/src/passes/2-simplify/cameligo.ml index b2bef414c..7dbb027d7 100644 --- a/src/passes/2-simplify/cameligo.ml +++ b/src/passes/2-simplify/cameligo.ml @@ -327,9 +327,9 @@ let rec simpl_expression : let%bind type_expr' = simpl_type_expression type_expr in return @@ e_annotation ~loc expr' type_expr' | EVar c -> - let c' = c.value in + let (c',loc) = r_split c in (match constants c' with - | Error _ -> return @@ e_variable (Var.of_name c.value) + | Error _ -> return @@ e_variable ~loc (Var.of_name c.value) | Ok (s,_) -> return @@ e_constant s []) | ECall x -> ( let ((e1 , e2) , loc) = r_split x in From a3a09dc0e568dd26e29f448bd51cc41201af934b Mon Sep 17 00:00:00 2001 From: Lesenechal Remi Date: Thu, 2 Jan 2020 19:39:31 +0100 Subject: [PATCH 3/3] functionize the name in the error --- src/passes/4-typer-new/typer.ml | 6 +++--- src/passes/4-typer-old/typer.ml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/passes/4-typer-new/typer.ml b/src/passes/4-typer-new/typer.ml index ea607c505..e6848c232 100644 --- a/src/passes/4-typer-new/typer.ml +++ b/src/passes/4-typer-new/typer.ml @@ -23,11 +23,11 @@ module Errors = struct error ~data title message () let unbound_variable (e:environment) (n:I.expression_variable) (loc:Location.t) () = - let name = Format.asprintf "%a" Stage_common.PP.name n in - let title = (thunk ("unbound variable "^name)) in + let name () = Format.asprintf "%a" Stage_common.PP.name n in + let title = (thunk ("unbound variable "^(name ()))) in let message () = "" in let data = [ - ("variable" , fun () -> name) ; + ("variable" , name) ; ("environment" , fun () -> Format.asprintf "%a" Environment.PP.full_environment e) ; ("location" , fun () -> Format.asprintf "%a" Location.pp loc) ] in diff --git a/src/passes/4-typer-old/typer.ml b/src/passes/4-typer-old/typer.ml index ff0ef2fe9..20b54514b 100644 --- a/src/passes/4-typer-old/typer.ml +++ b/src/passes/4-typer-old/typer.ml @@ -30,11 +30,11 @@ module Errors = struct error ~data title message () let unbound_variable (e:environment) (n:I.expression_variable) (loc:Location.t) () = - let name = Format.asprintf "%a" Stage_common.PP.name n in - let title = (thunk ("unbound variable "^name)) in + let name () = Format.asprintf "%a" Stage_common.PP.name n in + let title = (thunk ("unbound variable "^(name ()))) in let message () = "" in let data = [ - ("variable" , fun () -> name) ; + ("variable" , name) ; ("environment" , fun () -> Format.asprintf "%a" Environment.PP.full_environment e) ; ("location" , fun () -> Format.asprintf "%a" Location.pp loc) ] in