From c7b9c2cd3e69ed0d30cd54d790a026508a5d8960 Mon Sep 17 00:00:00 2001 From: Jeremie Dimino Date: Thu, 29 Mar 2018 15:04:14 -0400 Subject: [PATCH] Fix #661: better error when a public library is defined twice --- CHANGES.md | 5 ++++- src/scope.ml | 19 ++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 8fae978d..4aaaf113 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -34,7 +34,10 @@ next - Fix a regression introduced by beta19 where the generated merlin files didn't include the right `-ppx` flags in some cases (#658 - fixess #657 @diml) + fixes #657 @diml) + +- Fix error messaage when a public library is defined twice. Before + jbuilder would raise an uncaught exception (Fixes #661, @diml) 1.0+beta19.1 (21/03/2018) ------------------------- diff --git a/src/scope.ml b/src/scope.ml index e376c1f7..844e1769 100644 --- a/src/scope.ml +++ b/src/scope.ml @@ -77,7 +77,24 @@ module DB = struct match lib.public with | None -> None | Some p -> Some (p.name, lib.scope_name)) - |> String_map.of_list_exn + |> String_map.of_list + |> function + | Ok x -> x + | Error (name, _, _) -> + match + List.filter_map internal_libs ~f:(fun (_dir, lib) -> + match lib.public with + | None -> None + | Some p -> Option.some_if (name = p.name) lib.buildable.loc) + with + | [] | [_] -> assert false + | loc1 :: loc2 :: _ -> + die "Public library %S is defined twice:\n\ + - %s\n\ + - %s" + name + (Loc.to_file_colon_line loc1) + (Loc.to_file_colon_line loc2) in Lib.DB.create () ~parent:installed_libs