Document nested modules and calling parent functions
I can't find any documentation for nested modules and calling parent module functions within a child module.
There seems to be no way to call the outermost parent module's baz function from within a child module. It will always prefer the next parent's baz function.
It is impossible to make the following code print baz in foo1. In my use case the function baz is actually called path, so it not only overwrites the second definition of path in foo1 but also makes the global nushell path module unusable within the bim() function in foo3.
Example code:
export module foo1 {
export def baz [] { print "baz foo1" }
export module foo2 {
export def baz [] { print "baz in foo2" }
export module foo3 {
export def bim [] {
print "bim in foo3"
# this will succeed and call "baz in foo2"
baz
# this will fail with `external foo1 not found`
# foo1 foo2 baz
# this will also fail with `external foo1 not found`
# foo1 baz
}
}
}
}
use foo1
foo1 foo2 foo3 bim # this will print "baz in foo2"
This is similar to https://github.com/nushell/nushell/discussions/12598 but in my exact case where two nested modules have a function called path which actually name-collides with the global nushell path module it makes quite an undeterministic behavior:
export module foo1 {
export module foo2 {
export module foo3 {
export def bim [] {
print "bim in foo3"
path
"/" | path type
}
}
export def path [p?: string] {
print "path in foo2"
}
}
export def path [p?: string] {
print "path foo1"
}
}
use foo1
foo1 foo2 foo3 bim
output
bim in foo3
path in foo2
dir
There is no way to see when it will call foo2#path() or global nushell path function.