Skip to content

Commit

Permalink
Check user-written input of implentations to make sure it actually im…
Browse files Browse the repository at this point in the history
…plements the given vlib

Signed-off-by: Lucas Pluvinage <[email protected]>
  • Loading branch information
TheLortex committed Jun 27, 2019
1 parent 6de9237 commit 86b8c5c
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/lib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ module Error = struct
[ Pp.text "No solution found for this select form."
]


let not_an_implementation_of ~vlib ~impl =
make
[ Pp.textf "%S is not an implementation of %S."
(Lib_name.to_string (Lib_info.name impl))
(Lib_name.to_string (Lib_info.name vlib))
]

let dependency_cycle cycle =
make
[ Pp.text "Dependency cycle detected between the following libraries:"
Expand Down Expand Up @@ -891,16 +899,23 @@ let rec instantiate db name info ~stack ~hidden =
Variant.pp variant
Lib_name.pp name)
in
let actually_implements_vlib (lib : lib Or_exn.t) =
let* lib = lib in
let* vlib = Option.value ~default:(Error.not_an_implementation_of ~vlib:info ~impl:lib.info) lib.implements in
if Lib_name.equal vlib.name name
then Ok lib
else Error.not_an_implementation_of ~vlib:info ~impl:lib.info
in
let default_implementation =
Lib_info.default_implementation info
|> Option.map ~f:(fun l -> lazy (resolve l)) in
|> Option.map ~f:(fun l -> lazy (resolve l |> actually_implements_vlib)) in
let resolved_implementations =
Lib_info.virtual_ info
|> Option.map ~f:(fun _ -> lazy (
(* TODO this can be made even lazier as we don't need to resolve all
variants at once *)
Lib_info.known_implementations info
|> Variant.Map.map ~f:resolve))
|> Variant.Map.map ~f:(fun l -> resolve l |> actually_implements_vlib)))
in
let requires, pps, resolved_selects =
let pps = Lib_info.pps info in
Expand Down

0 comments on commit 86b8c5c

Please sign in to comment.