Skip to content

Commit

Permalink
fix(init): check that module names are valid (#8644)
Browse files Browse the repository at this point in the history
Fixes #8252

When creating a library (directly or indirectly, through a project), the
component name should be a valid module name.

This restriction does not apply to executable names.

Signed-off-by: Etienne Millon <me@emillon.org>
  • Loading branch information
emillon authored Sep 15, 2023
1 parent 4593b51 commit 77cd8fc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
9 changes: 9 additions & 0 deletions bin/dune_init.ml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,14 @@ module Init_context = struct
;;
end

let check_module_name name =
let s = Dune_lang.Atom.to_string name in
let (_ : Dune_rules.Module_name.t) =
Dune_rules.Module_name.of_string_user_error (Loc.none, s) |> User_error.ok_exn
in
()
;;

module Public_name = struct
include Lib_name
module Pkg = Dune_lang.Package_name.Opam_compatible
Expand Down Expand Up @@ -346,6 +354,7 @@ module Component = struct
;;

let library (common : Options.Common.t) { Options.Library.inline_tests; public } =
check_module_name common.name;
let common =
if inline_tests
then (
Expand Down
1 change: 1 addition & 0 deletions doc/changes/init-module-names.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- init: check that module names are valid (#8644, fixes #8252, @emillon)
6 changes: 5 additions & 1 deletion test/blackbox-tests/test-cases/dune-init/github8252.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@

$ dune init project 01_module
Entering directory '01_module'
Success: initialized project component named 01_module
Error: "01_module" is an invalid module name.
Module names must be non-empty, start with a letter, and composed only of the
following characters: 'A'..'Z', 'a'..'z', '_', ''' or '0'..'9'.
Hint: M01_module would be a correct module name
Leaving directory '01_module'
[1]

0 comments on commit 77cd8fc

Please sign in to comment.