Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: decoding dune-package crashes with (include_subdirs qualified) #10269

Merged
merged 5 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/changes/10269.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- fix crash when decoding dune-package for libraries with `(include_subdirs
qualified)` (#10269, fixes #10264, @emillon)
2 changes: 1 addition & 1 deletion src/dune_rules/module.ml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ module Kind = struct
match next with
| None -> return (Alias [])
| Some _ ->
let+ path = Module_name.Path.decode in
let+ path = enter Module_name.Path.decode in
Alias path )
]
;;
Expand Down
2 changes: 2 additions & 0 deletions src/dune_rules/module.mli
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ module Kind : sig
| Root

include Dune_lang.Conv.S with type t := t

val to_dyn : t -> Dyn.t
end

module Source : sig
Expand Down
3 changes: 2 additions & 1 deletion src/dune_rules/modules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,8 @@ module Group = struct
Module_name.Map.to_list_map modules ~f:(fun _ t ->
Dune_lang.List
(match t with
| Group g -> Dune_lang.atom "group" :: encode ~src_dir g
| Group g ->
Dune_lang.atom "group" :: Module_name.encode g.name :: encode ~src_dir g
| Module m -> Dune_lang.atom "module" :: Module.encode ~src_dir m))
;;

Expand Down
31 changes: 31 additions & 0 deletions test/expect-tests/module_tests.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
open Stdune
module Kind = Dune_rules.Module.Kind

(* See #10264 *)
let%expect_test "Module.Kind encoding round trip" =
let module_name s = Dune_rules.Module_name.of_string s in
let test k =
let ast = Kind.encode k in
let sexp = Dune_sexp.Ast.add_loc ~loc:Loc.none ast in
let decoded =
match Dune_lang.Decoder.parse Kind.decode Univ_map.empty sexp with
| r -> Ok r
| exception e -> Error e
in
let dyn =
Dyn.record
[ "ast", Dyn.string (Dune_sexp.to_string ast)
; "decoded", Or_exn.to_dyn Kind.to_dyn decoded
]
in
Dune_tests_common.print_dyn dyn
in
test Impl;
[%expect {| { ast = "impl"; decoded = Ok Impl } |}];
test (Alias []);
[%expect {| { ast = "alias"; decoded = Ok Alias [] } |}];
test (Alias [ module_name "A" ]);
[%expect {| { ast = "(alias (A))"; decoded = Ok Alias [ "A" ] } |}];
test (Alias [ module_name "A"; module_name "B" ]);
[%expect {| { ast = "(alias (A B))"; decoded = Ok Alias [ "A"; "B" ] } |}]
;;
Loading