Skip to content

Commit 7640b32

Browse files
committed
Fix printing of notations
Prefer operators from the current environment when resolving names for printing, and avoid rewriting explicitly named operators through special syntax.
1 parent ea0bde6 commit 7640b32

1 file changed

Lines changed: 28 additions & 16 deletions

File tree

src/ecPrinting.ml

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -244,14 +244,23 @@ module PPEnv = struct
244244

245245
fun sm ->
246246
check_for_local sm;
247-
let ue = EcUnify.UniEnv.create None in
248-
match EcUnify.select_op ~hidden:true ~filter tvi ppe.ppe_env sm ue dom with
247+
248+
let by_current ((p, _), _, _, _) =
249+
let env = ppe.ppe_env in
250+
EcPath.isprefix ~prefix:(oget (EcPath.prefix p)) ~path:(EcEnv.root env) in
251+
252+
let ue = EcUnify.UniEnv.create None in
253+
let ops = EcUnify.select_op ~hidden:true ~filter tvi ppe.ppe_env sm ue dom in
254+
let ops = match List.mbfilter by_current ops with [] -> ops | ops -> ops in
255+
256+
match ops with
249257
| [(p1, _), _, _, _] -> p1
250258
| _ -> raise (EcEnv.LookupFailure (`QSymbol sm)) in
251259

252260
let exists sm =
253-
try EcPath.p_equal (lookup sm) p
261+
try EcPath.p_equal (lookup sm) p
254262
with EcEnv.LookupFailure _ -> false
263+
255264
in
256265
(* FIXME: for special operators, do check `info` *)
257266
if List.exists (fun (_, sp) -> EcPath.p_equal sp p) specs
@@ -1378,14 +1387,18 @@ let pp_opapp
13781387
| _ -> None
13791388

13801389
in
1381-
(odfl
1382-
pp_as_std_op
1383-
(List.fpick [try_pp_special ;
1384-
try_pp_as_uniop;
1385-
try_pp_as_binop;
1386-
try_pp_as_post ;
1387-
try_pp_record ;
1388-
try_pp_proj ;])) fmt ()
1390+
if List.is_empty nm then
1391+
(odfl
1392+
pp_as_std_op
1393+
(List.fpick [
1394+
try_pp_special ;
1395+
try_pp_as_uniop;
1396+
try_pp_as_binop;
1397+
try_pp_as_post ;
1398+
try_pp_record ;
1399+
try_pp_proj ;])) fmt ()
1400+
else
1401+
pp_as_std_op fmt ()
13891402

13901403
(* -------------------------------------------------------------------- *)
13911404
let pp_chained_orderings (type v)
@@ -1802,7 +1815,6 @@ and match_pp_notations
18021815

18031816
List.find_map_opt try_notation nts
18041817

1805-
18061818
and try_pp_notations
18071819
(ppe : PPEnv.t)
18081820
(outer : opprec * iassoc)
@@ -1818,10 +1830,10 @@ and try_pp_notations
18181830
let rty = ti nt.ont_resty in
18191831
let tv = List.map (ti -| tvar) tv in
18201832
let args = List.map (curry f_local -| snd_map ti) nt.ont_args in
1821-
let f = f_op p tv (toarrow tv rty) in
1822-
let f = f_app f args rty in
1823-
let f = Fsubst.f_subst (EcMatching.MEV.assubst ue ev ppe.ppe_env) f in
1824-
let f = f_app f eargs f.f_ty in
1833+
let args =
1834+
let subst = EcMatching.MEV.assubst ue ev ppe.ppe_env in
1835+
List.map (Fsubst.f_subst subst) args in
1836+
let f = f_app (f_op p tv rty) (args @ eargs) f.f_ty in
18251837
pp_form_core_r ppe outer fmt f; true
18261838

18271839
and pp_poe ppe fmt (l,d) =

0 commit comments

Comments
 (0)