diff --git a/bin/alias.ml b/bin/alias.ml index 02ec8b105be..612b773a7e4 100644 --- a/bin/alias.ml +++ b/bin/alias.ml @@ -18,7 +18,8 @@ let in_dir ~name ~recursive ~contexts dir = let checked = Util.check_path contexts dir in match checked with | External _ -> - User_error.raise [ Pp.textf "@@ on the command line must be followed by a relative path" ] + User_error.raise + [ Pp.textf "@@ on the command line must be followed by a relative path" ] | In_source_dir dir -> { dir ; recursive diff --git a/src/scope.ml b/src/scope.ml index 65d25589544..1a3173d4a44 100644 --- a/src/scope.ml +++ b/src/scope.ml @@ -92,14 +92,13 @@ module DB = struct |> Dune_project.Name.Map.of_list |> function | Ok x -> x - | Error (_name, project1, project2) -> - let to_dyn (project : Dune_project.t) = - Dyn.Encoder.(pair Dune_project.Name.to_dyn Path.Source.to_dyn) - (Dune_project.name project, Dune_project.root project) - in - Code_error.raise "Scope.DB.create got two projects with the same name" - [ "project1", to_dyn project1 - ; "project2", to_dyn project2 + | Error (name, project1, project2) -> + let loc = Loc.in_file (Path.source (Dune_project.file project1)) in + let name = Dune_project.Name.to_string_hum name in + let dup_path = Path.source (Dune_project.file project2) in + User_error.raise ~loc + [ Pp.textf "Project %s is already defined in %s" + name (Path.to_string_maybe_quoted dup_path) ] in let libs_by_project_name = diff --git a/test/blackbox-tests/dune.inc b/test/blackbox-tests/dune.inc index 1184489a0d6..30066b08617 100644 --- a/test/blackbox-tests/dune.inc +++ b/test/blackbox-tests/dune.inc @@ -303,6 +303,14 @@ test-cases/duplicate-c-cxx-obj (progn (run %{exe:cram.exe} -test run.t) (diff? run.t run.t.corrected))))) +(alias + (name duplicate-project-names) + (deps (package dune) (source_tree test-cases/duplicate-project-names)) + (action + (chdir + test-cases/duplicate-project-names + (progn (run %{exe:cram.exe} -test run.t) (diff? run.t run.t.corrected))))) + (alias (name duplicate-target-no-loc) (deps (package dune) (source_tree test-cases/duplicate-target-no-loc)) @@ -1631,6 +1639,7 @@ (alias dup-fields) (alias duplicate-c-cxx) (alias duplicate-c-cxx-obj) + (alias duplicate-project-names) (alias duplicate-target-no-loc) (alias embed-jbuild) (alias enabled_if) @@ -1823,6 +1832,7 @@ (alias dup-fields) (alias duplicate-c-cxx) (alias duplicate-c-cxx-obj) + (alias duplicate-project-names) (alias duplicate-target-no-loc) (alias embed-jbuild) (alias enabled_if) diff --git a/test/blackbox-tests/test-cases/duplicate-project-names/a/dune-project b/test/blackbox-tests/test-cases/duplicate-project-names/a/dune-project new file mode 100644 index 00000000000..1e9cbae5463 --- /dev/null +++ b/test/blackbox-tests/test-cases/duplicate-project-names/a/dune-project @@ -0,0 +1,2 @@ +(lang dune 1.11) +(name foo) diff --git a/test/blackbox-tests/test-cases/duplicate-project-names/b/dune-project b/test/blackbox-tests/test-cases/duplicate-project-names/b/dune-project new file mode 100644 index 00000000000..1e9cbae5463 --- /dev/null +++ b/test/blackbox-tests/test-cases/duplicate-project-names/b/dune-project @@ -0,0 +1,2 @@ +(lang dune 1.11) +(name foo) diff --git a/test/blackbox-tests/test-cases/duplicate-project-names/run.t b/test/blackbox-tests/test-cases/duplicate-project-names/run.t new file mode 100644 index 00000000000..3fa656ecb50 --- /dev/null +++ b/test/blackbox-tests/test-cases/duplicate-project-names/run.t @@ -0,0 +1,5 @@ +Duplicate project names are currently not allowed: + $ dune build @all + File "b/dune-project", line 1, characters 0-0: + Error: Project foo is already defined in a/dune-project + [1]