Skip to content

Commit

Permalink
fix: show the relevant loc for public library name collisions (#10389)
Browse files Browse the repository at this point in the history
Signed-off-by: Antonio Nuno Monteiro <anmonteiro@gmail.com>
  • Loading branch information
anmonteiro authored Apr 29, 2024
1 parent 35713dc commit bc57ae4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
20 changes: 11 additions & 9 deletions src/dune_rules/scope.ml
Original file line number Diff line number Diff line change
Expand Up @@ -206,19 +206,18 @@ module DB = struct
| Project of
{ project : Dune_project.t
; lib_id : Lib_id.Local.t
; loc : Loc.t
}
| Name of (Loc.t * Lib_name.t)

let loc_of_redirect_to = function
| Project { lib_id; _ } -> Lib_id.Local.loc lib_id
| Name (loc, _) -> loc
;;

(* Create a database from the public libraries defined in the stanzas *)
let public_libs =
let public_loc_of_redirect_to = function
| Project { loc; _ } | Name (loc, _) -> loc
in
let resolve_redirect_to t rt =
match rt with
| Project { project; lib_id } ->
| Project { project; lib_id; _ } ->
let scope = find_by_project (Fdecl.get t) project in
Lib.DB.Resolve_result.redirect_by_id scope.db (Local lib_id)
| Name name -> Lib.DB.Resolve_result.redirect_in_the_same_db name
Expand Down Expand Up @@ -247,7 +246,10 @@ module DB = struct
in
Library.to_lib_id ~src_dir conf
in
Some (Public_lib.name p, Project { project; lib_id }, Some lib_id)
Some
( Public_lib.name p
, Project { project; lib_id; loc = Public_lib.loc p }
, Some lib_id )
| Library _ | Library_redirect _ -> None
| Deprecated_library_name s ->
Some
Expand All @@ -260,8 +262,8 @@ module DB = struct
Lib_name.Map.update by_name public_name ~f:(function
| None -> Some r2
| Some r1 ->
let loc1 = loc_of_redirect_to r1
and loc2 = loc_of_redirect_to r2 in
let loc1 = public_loc_of_redirect_to r1
and loc2 = public_loc_of_redirect_to r2 in
let main_message =
Pp.textf
"Public library %s is defined twice:"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ different folders.
Without any consumers of the libraries

$ dune build
File "b/dune", line 2, characters 7-10:
2 | (name bar)
^^^
File "b/dune", line 3, characters 14-21:
3 | (public_name bar.foo))
^^^^^^^
Error: Public library bar.foo is defined twice:
- a/dune:2
- b/dune:2
- a/dune:3
- b/dune:3
[1]

With some consumer
Expand All @@ -44,10 +44,10 @@ With some consumer
> EOF

$ dune build
File "b/dune", line 2, characters 7-10:
2 | (name bar)
^^^
File "b/dune", line 3, characters 14-21:
3 | (public_name bar.foo))
^^^^^^^
Error: Public library bar.foo is defined twice:
- a/dune:2
- b/dune:2
- a/dune:3
- b/dune:3
[1]

0 comments on commit bc57ae4

Please sign in to comment.