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

feature(compiler) Make constant shadowing a warning #699

Merged
merged 2 commits into from
Oct 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion mechanization/Common/Result.v
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,10 @@ Section Result.
end.
Definition print_warnings {A:Set} (prefix:string) (x:eresult A) : eresult A :=
elift_warning (fun xy => coq_print_warnings prefix (List.map string_of_warning (snd xy)) (fst xy)) x.

Definition warning_no_else prov : ewarning :=
EWarning prov "No else in enforce".
Definition warning_global_shadowing prov (name:string) :=
EWarning prov ("Constant " ++ name ++ " hides an existing constant with the same name").
End warnings.
End Result.

13 changes: 10 additions & 3 deletions mechanization/Translation/ErgoCInline.v
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,16 @@ Section ErgoCInline.
| DCExpr prov expr =>
elift (fun x => (DCExpr prov x, ctxt)) (ergo_inline_expr ctxt expr)
| DCConstant prov name ta expr =>
elift (fun x =>
(DCConstant prov name ta x, compilation_context_update_global_env ctxt name x))
(ergo_inline_expr ctxt expr)
let global_shadowing_warning :=
match lookup String.string_dec (ctxt.(compilation_context_global_env)) name with
| Some val => warning_global_shadowing prov name :: nil
| None => nil
end
in
eolift (fun x =>

(esuccess (DCConstant prov name ta x, compilation_context_update_global_env ctxt name x) global_shadowing_warning))
(ergo_inline_expr ctxt expr)
| DCFunc prov name fn =>
elift (fun x =>
(DCFunc prov name x, compilation_context_update_function_env ctxt name x))
Expand Down
5 changes: 1 addition & 4 deletions mechanization/Translation/ErgotoErgoC.v
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,10 @@ Section ErgotoErgoC.
(ergo_stmt_to_expr ctxt s2)
(ergo_stmt_to_expr ctxt s3)
| SEnforce prov e1 None s3 =>
let warning_no_else :=
EWarning prov "No else in enforce"
in
elift3 (EIf prov)
(elift (EUnaryBuiltin prov OpNeg) (ergo_expr_to_ergoc_expr ctxt e1))
(esuccess (EFailure prov
(EConst prov (enforce_error_content prov ""))) (warning_no_else::nil))
(EConst prov (enforce_error_content prov ""))) (warning_no_else prov::nil))
(ergo_stmt_to_expr ctxt s3)
| SEnforce prov e1 (Some s2) s3 =>
elift3 (EIf prov)
Expand Down
Loading