diff --git a/src/dune_project.ml b/src/dune_project.ml index e185ee63580b..4b65aecae7f2 100644 --- a/src/dune_project.ml +++ b/src/dune_project.ml @@ -614,15 +614,24 @@ let parse ~dir ~lang ~packages ~file = let allow_approx_merlin = Option.value ~default:false allow_approx_merlin in let packages = + begin match dune_defined_packages, name with + | [loc, p], Named name -> + if Package.Name.to_string p.name <> name then + of_sexp_errorf loc + "when a single package is defined, it must have the same \ + name as the project name: %s" name; + | _, _ -> () + end; match - dune_defined_packages - |> Package.Name.Map.of_list_map - ~f:(fun (_loc, (p : Package.t)) -> p.name, p) + dune_defined_packages + |> Package.Name.Map.of_list_map + ~f:(fun (_loc, (p : Package.t)) -> p.name, p) with | Error (p, (_, _), (loc, _)) -> of_sexp_errorf loc "package %s is already defined" (Package.Name.to_string p) - | Ok d -> Package.Name.Map.superpose packages d + | Ok d -> + Package.Name.Map.superpose packages d in { name ; root = dir