Simplify a bit expand_step2

Signed-off-by: Jeremie Dimino <jeremie@dimino.org>
This commit is contained in:
Jeremie Dimino 2018-07-09 17:36:04 +01:00 committed by Rudi Grinberg
parent c10a2c254e
commit 61a80a6bb3
3 changed files with 8 additions and 15 deletions

View File

@ -251,14 +251,6 @@ module Bindings = struct
| Unnamed _ -> None
| Named (k', x) -> Option.some_if (k = k') x)
let first t =
let rec loop acc = function
| [] -> acc
| Unnamed x :: xs -> loop (Result.Ok x) xs
| Named (_, _) :: _ -> Result.Error `Named_exists
in
loop (Result.Error `Empty) t
let empty = []
let singleton x = [Unnamed x]

View File

@ -98,8 +98,6 @@ module Bindings : sig
val singleton : 'a -> 'a t
val first : 'a t -> ('a, [`Empty | `Named_exists]) Result.t
val sexp_of_t : ('a -> Usexp.t) -> 'a t -> Usexp.t
end

View File

@ -792,14 +792,17 @@ module Action = struct
|> Value.L.paths
|> Option.some
| First_dep ->
begin match Jbuild.Bindings.first deps_written_by_user with
| Error `Named_exists ->
Loc.fail loc "%%{first-dep} is not allowed with named dependencies"
| Error `Empty ->
begin match deps_written_by_user with
| Named _ :: _ ->
(* This case is not possible: ${<} only exist in jbuild
files and named dependencies are not available in
jbuild files *)
assert false
| Unnamed v :: _ -> Some [Path v]
| [] ->
Loc.warn loc "Variable '%s' used with no explicit \
dependencies@." key;
Some [Value.String ""]
| Ok v -> Some [Path v]
end
| _ ->
Exn.code_error "Unexpected variable in step2"