diff --git a/src/dune_project.ml b/src/dune_project.ml index 4be06c51c4ed..e185ee63580b 100644 --- a/src/dune_project.ml +++ b/src/dune_project.ml @@ -576,7 +576,7 @@ let parse ~dir ~lang ~packages ~file = and+ source = field_o "source" (Syntax.since Stanza.syntax (1, 7) >>> Source_kind.decode) and+ dune_defined_packages = - multi_field "package" (package_decode ~dir) + multi_field "package" (located (package_decode ~dir)) and+ authors = field ~default:[] "authors" (Syntax.since Stanza.syntax (1, 9) >>> repeat string) and+ license = field_o "license" @@ -614,8 +614,15 @@ let parse ~dir ~lang ~packages ~file = let allow_approx_merlin = Option.value ~default:false allow_approx_merlin in let packages = - List.fold_left ~init:packages ~f:(fun acc (p : Package.t) -> - Package.Name.Map.add acc p.name p) dune_defined_packages + match + 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 in { name ; root = dir