Skip to content

Commit 936cf1e

Browse files
authored
Merge pull request #5985 from rjbou/fix-formula-mapfold
Fix OpamFilter map/fold functions
2 parents 6cf6ff3 + de20159 commit 936cf1e

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

master_changes.md

+2
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ users)
166166

167167
## opam-format
168168
* `OpamPath`: remove `OpamPath.Switch.last_env` function in favor to `OpamPath.last_env` as the files are no more stored in switch directory [#5962 @moyodiallo - fix #5823]
169+
* `OpamFilter.map_up`: correct handling of FDefined [#5983 @dra27]
170+
* `OpamFilter.fold_down_left`: correct handling of FDefined and FUndef [#5983 @dra27]
169171

170172
## opam-core
171173
* `OpamStd.String`: add `split_quoted` that preserves quoted separator [#5935 @dra27]

src/format/opamFilter.ml

+10-3
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,23 @@ let to_string ?custom t =
7474
let rec fold_down_left f acc filter = match filter with
7575
| FOp(l,_,r) | FAnd(l,r) | FOr(l,r) ->
7676
fold_down_left f (fold_down_left f (f acc filter) l) r
77-
| FNot(x) -> fold_down_left f (f acc filter) x
78-
| x -> f acc x
77+
| FNot x
78+
| FUndef x
79+
| FDefined x ->
80+
fold_down_left f (f acc filter) x
81+
| FBool _
82+
| FString _
83+
| FIdent _ ->
84+
f acc filter
7985

8086
let rec map_up f = function
8187
| FOp (l, op, r) -> f (FOp (map_up f l, op, map_up f r))
8288
| FAnd (l, r) -> f (FAnd (map_up f l, map_up f r))
8389
| FOr (l, r) -> f (FOr (map_up f l, map_up f r))
8490
| FNot x -> f (FNot (map_up f x))
8591
| FUndef x -> f (FUndef (map_up f x))
86-
| (FBool _ | FString _ | FIdent _ | FDefined _) as flt -> f flt
92+
| FDefined x -> f (FDefined (map_up f x))
93+
| (FBool _ | FString _ | FIdent _) as flt -> f flt
8794

8895
(* ["%%"], ["%{xxx}%"], or ["%{xxx"] if unclosed *)
8996
let string_interp_regex =

0 commit comments

Comments
 (0)