Skip to content

Commit de20159

Browse files
dra27rjbou
authored andcommitted
Fix OpamFilter map/fold functions
Incorrect handling of FDefined and FUndef - harden fold_down_left against future changes.
1 parent 21305bb commit de20159

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
@@ -160,6 +160,8 @@ users)
160160

161161
## opam-format
162162
* `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]
163+
* `OpamFilter.map_up`: correct handling of FDefined [#5983 @dra27]
164+
* `OpamFilter.fold_down_left`: correct handling of FDefined and FUndef [#5983 @dra27]
163165

164166
## opam-core
165167
* `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)