Fix incorrect claim that a module file cannot match its directory name - #2219
Merged
fdncred merged 1 commit intoAug 6, 2026
Merged
Conversation
The 'Creating Modules' chapter stated that a `.nu` file cannot have the same name as its module directory (e.g. `spam/spam.nu`). Nushell accepts that layout: the file imports normally, both directly (`use spam/spam.nu`) and as a submodule exported from `spam/mod.nu`. The restriction that does exist is on the exported *name*: a module cannot export a command, alias, or known external defined inside it, or a submodule declared by name, with the same name as the module itself. Replace the false statement with the real restriction, and keep a note warning that a same-named submodule is still worth avoiding because its `main` is shadowed by the parent module's `main`.
Contributor
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
book/modules/creating_modules.mdsays:Nushell accepts that layout. There is no error and no ambiguity condition. What Nushell actually rejects is an export whose name equals the module name — a command, alias, known external, or a submodule declared by name.
This PR replaces the false statement with the real restriction, and keeps a note explaining why
spam/spam.nuis still worth avoiding (the submodule'smainis shadowed by the parent module'smain).Verified against Nushell 0.114.1 (Homebrew)
A
.nufile with the same name as its directory imports fine on its own:It also works as a submodule exported from
spam/mod.nu:Behaviour is identical to a differently-named submodule (
foo/bar.nu), so nothing is "defined twice" and nothing errors.The one real gotcha, which the new note documents: if both the parent module and the same-named submodule export a
main, both resolve to the same command name and the parent silently wins — still no error:The restriction that does exist, and that the corrected text describes:
Same for
export def spam,export alias spam, andexport extern spaminsidemodule spam. This matchescrates/nu-parser/src/parse_module.rs,parse_def.rsandparse_alias.rs(ParseError::NamedAsModule) and thenot_allowed_submodule/module_invalid_def_name/module_invalid_alias_name/module_invalid_known_external_nametests intests/modules/mod.rsin nushell/nushell.export const spam = 1insidemodule spamis accepted, so the corrected text deliberately does not list constants.Checks run
npx prettier@3 --check book/modules/creating_modules.md— passes.nu 0.114.1; the error text in the new code block is copied from real output.Translations
zh-CN/book/modules/creating_modules.md:432andko/book/modules/creating_modules.md:430carry the same incorrect sentence. Following the repository's translation workflow, this PR only changes the English page and leaves those to the usualnu tools/i18n.nu outdated <locale>sync.Disclosure
This change was drafted with AI assistance (Claude). Every behavioural claim in it was verified by running the commands shown above against Nushell 0.114.1 and by reading the parser source and test suite in nushell/nushell.