digitalmars.D.learn - nested module problem
- Jean-Louis Leroy (17/17) Sep 02 2017 So I have:
- Moritz Maxeiner (18/39) Sep 02 2017 This means bar.d's module name will be inferred by the compiler
- Jean-Louis Leroy (21/26) Sep 02 2017 I thought of doing that, it merely changed the error. OK now I
- Moritz Maxeiner (19/45) Sep 02 2017 Yes, these now both fail because you cannot have a module `foo`
- Jean-Louis Leroy (5/28) Sep 02 2017 Hmmm I see...I was thinking of spinning the runtime part of my
- Moritz Maxeiner (4/8) Sep 02 2017 Why does it look like a bad idea (I don't see an immediate issue
- Moritz Maxeiner (3/12) Sep 02 2017 * in the module structure
- =?UTF-8?B?THXDrXM=?= Marques (5/10) Dec 24 2017 I think that shouldn't be allowed. You have a package foo, but
-
=?UTF-8?B?THXDrXM=?= Marques
(2/5)
Dec 24 2017
- Jean-Louis Leroy (2/12) Dec 25 2017 Monkey testing haha!
- mw (7/7) Oct 28 2020 I run into a similar issue today:
- Adam D. Ruppe (6/8) Oct 28 2020 Don't write any module with a single name unless you are
- mw (8/16) Oct 28 2020 Thanks for the tip, Adam.
- H. S. Teoh (8/20) Oct 28 2020 IMO, 3rd party libraries should always be in their own package
- mw (2/7) Oct 28 2020 logged:
So I have: jll ORAC:~/dev/d/tests/modules$ tree . ├── foo │ └── bar.d └── foo.d foo.d contains: import foo.bar; bar.d is empty. Now I try compiling: jll ORAC:~/dev/d/tests/modules$ dmd -c foo.d jll ORAC:~/dev/d/tests/modules$ dmd -c foo/bar.d So far so good. Now I try it the way dub does it: jll ORAC:~/dev/d/tests/modules$ dmd -c foo.d foo/bar.d foo.d(1): Error: module bar from file foo/bar.d must be imported with 'import bar;' What's up?
Sep 02 2017
On Saturday, 2 September 2017 at 20:03:48 UTC, Jean-Louis Leroy wrote:So I have: jll ORAC:~/dev/d/tests/modules$ tree . ├── foo │ └── bar.d └── foo.d foo.d contains: import foo.bar; bar.d is empty.This means bar.d's module name will be inferred by the compiler [1], which will ignore the path you put it under, yielding the module name "bar", not "foo.bar" (one of the issues of doing otherwise would be how the compiler should know at which path depth the inference should start - and any solution to that other than simply ignoring the path would be full of special cases):Modules have a one-to-one correspondence with source files. The module name is, by default, the file name with the path and extension stripped off, and can be set explicitly with the module declaration.Now I try compiling: jll ORAC:~/dev/d/tests/modules$ dmd -c foo.dThis looks like a compiler bug to me (accepts invalid), though I'm not certain.jll ORAC:~/dev/d/tests/modules$ dmd -c foo/bar.d(No issue here, just an empty module being compiled separately)So far so good. Now I try it the way dub does it: jll ORAC:~/dev/d/tests/modules$ dmd -c foo.d foo/bar.d foo.d(1): Error: module bar from file foo/bar.d must be imported with 'import bar;' What's up?This doesn't work, because of the inferred module name for foo/bar.d being "bar". So the compiler wants you to import it by the name it has inferred for you (The fix being either specifying the module name in foo/bar.d as `module foo.bar`, or importing it as via `import bar;` in foo.d). [1] https://dlang.org/spec/module.html
Sep 02 2017
On Saturday, 2 September 2017 at 20:48:22 UTC, Moritz Maxeiner wrote:So the compiler wants you to import it by the name it has inferred for you (The fix being either specifying the module name in foo/bar.d as `module foo.bar`, or importing it as via `import bar;` in foo.d). [1] https://dlang.org/spec/module.htmlI thought of doing that, it merely changed the error. OK now I have: in foo.d: module foo; import foo.bar; in foo/bar.d: module foo.bar; $ dmd -c foo.d foo/bar.d foo/bar.d(1): Error: package name 'foo' conflicts with usage as a module name in file foo.d If I compile separately: jll ORAC:~/dev/d/tests/modules$ dmd -I. -c foo.d foo/bar.d(1): Error: package name 'foo' conflicts with usage as a module name in file foo.d jll ORAC:~/dev/d/tests/modules$ dmd -I. -c foo/bar.d It believes that 'foo' is a package...because there is a 'foo' directory? I see that a workaround is to move foo.d to foo/package.d but I would like to avoid that.
Sep 02 2017
On Saturday, 2 September 2017 at 21:24:19 UTC, Jean-Louis Leroy wrote:On Saturday, 2 September 2017 at 20:48:22 UTC, Moritz Maxeiner wrote:Yes, these now both fail because you cannot have a module `foo` and a package `foo` at the same time (they share a namespace), I forgot about that.So the compiler wants you to import it by the name it has inferred for you (The fix being either specifying the module name in foo/bar.d as `module foo.bar`, or importing it as via `import bar;` in foo.d). [1] https://dlang.org/spec/module.htmlI thought of doing that, it merely changed the error. OK now I have: in foo.d: module foo; import foo.bar; in foo/bar.d: module foo.bar; $ dmd -c foo.d foo/bar.d foo/bar.d(1): Error: package name 'foo' conflicts with usage as a module name in file foo.d If I compile separately: jll ORAC:~/dev/d/tests/modules$ dmd -I. -c foo.d foo/bar.d(1): Error: package name 'foo' conflicts with usage as a module name in file foo.djll ORAC:~/dev/d/tests/modules$ dmd -I. -c foo/bar.d(same as before, no issue here)It believes that 'foo' is a package...because there is a 'foo' directory?You created the 'foo' package by specifying `module foo.bar` in foo/bar.d.I see that a workaround is to move foo.d to foo/package.d but I would like to avoid that.AFAIK you can't; consider: -- baz.d --- import foo; ------------ in the same directory as foo.d. If foo/package.d exists (with `module foo` inside), what should baz.d import? foo.d or foo/package.d? The point being that we could have either used foo/package.d or foo.d for a package file, but not both (as that would allow ambiguity) and package.d was chosen. [1] https://dlang.org/spec/module.html#package-module
Sep 02 2017
On Saturday, 2 September 2017 at 21:42:59 UTC, Moritz Maxeiner wrote:On Saturday, 2 September 2017 at 21:24:19 UTC, Jean-Louis Leroy wrote:Hmmm I see...I was thinking of spinning the runtime part of my openmethods library into its own module (like here https://github.com/jll63/openmethods.d/tree/split-runtime/source/openmethods) but it looks like a bad idea...[...]Yes, these now both fail because you cannot have a module `foo` and a package `foo` at the same time (they share a namespace), I forgot about that.[...](same as before, no issue here)[...]You created the 'foo' package by specifying `module foo.bar` in foo/bar.d.[...]AFAIK you can't; consider: -- baz.d --- import foo; ------------ in the same directory as foo.d. If foo/package.d exists (with `module foo` inside), what should baz.d import? foo.d or foo/package.d? The point being that we could have either used foo/package.d or foo.d for a package file, but not both (as that would allow ambiguity) and package.d was chosen. [1] https://dlang.org/spec/module.html#package-module
Sep 02 2017
On Saturday, 2 September 2017 at 21:56:15 UTC, Jean-Louis Leroy wrote:[...] Hmmm I see...I was thinking of spinning the runtime part of my openmethods library into its own module (like here https://github.com/jll63/openmethods.d/tree/split-runtime/source/openmethods) but it looks like a bad idea...Why does it look like a bad idea (I don't see an immediate issue the module structure either way)?
Sep 02 2017
On Saturday, 2 September 2017 at 23:02:18 UTC, Moritz Maxeiner wrote:On Saturday, 2 September 2017 at 21:56:15 UTC, Jean-Louis Leroy wrote:* in the module structure[...] Hmmm I see...I was thinking of spinning the runtime part of my openmethods library into its own module (like here https://github.com/jll63/openmethods.d/tree/split-runtime/source/openmethods) but it looks like a bad idea...Why does it look like a bad idea (I don't see an immediate issue the module structure either way)?
Sep 02 2017
On Saturday, 2 September 2017 at 20:03:48 UTC, Jean-Louis Leroy wrote:jll ORAC:~/dev/d/tests/modules$ tree . ├── foo │ └── bar.d └── foo.dI think that shouldn't be allowed. You have a package foo, but use a normal module instead of foo/package.d. I'm going to file a bug on that.
Dec 24 2017
On Sunday, 24 December 2017 at 22:17:23 UTC, Luís Marques wrote:I think that shouldn't be allowed. You have a package foo, but use a normal module instead of foo/package.d. I'm going to file a bug on that.<https://issues.dlang.org/show_bug.cgi?id=18123>
Dec 24 2017
On Sunday, 24 December 2017 at 22:17:23 UTC, Luís Marques wrote:On Saturday, 2 September 2017 at 20:03:48 UTC, Jean-Louis Leroy wrote:Monkey testing haha!jll ORAC:~/dev/d/tests/modules$ tree . ├── foo │ └── bar.d └── foo.dI think that shouldn't be allowed. You have a package foo, but use a normal module instead of foo/package.d. I'm going to file a bug on that.
Dec 25 2017
I run into a similar issue today: -- I try to use a library `pyd`, and -- my local project has a file called "source/util.d" the dub build error out: /.dub/packages/pyd-0.13.1/pyd/infrastructure/util/typelist.d(1,1): Error: package name 'util' conflicts with usage as a module name in file source/util.d I wonder what's the best way to resolve this conflict, i.e my local file name with 3rd party library dir name.
Oct 28 2020
On Wednesday, 28 October 2020 at 22:43:12 UTC, mw wrote:I wonder what's the best way to resolve this conflict, i.e my local file name with 3rd party library dir name.Don't write any module with a single name unless you are guaranteed to never import it. pyd should have called it like `module pyd.util;` Then you call yours like `module mw.util;` This makes such conflicts a lot less likely.
Oct 28 2020
On Wednesday, 28 October 2020 at 22:52:33 UTC, Adam D. Ruppe wrote:On Wednesday, 28 October 2020 at 22:43:12 UTC, mw wrote:Thanks for the tip, Adam. And I fixed the imports in multiple files with: ``` $ sed -i 's/import util;/import mw.util;/g' *.d ``` Hope this will help if someone else also run into this issue.I wonder what's the best way to resolve this conflict, i.e my local file name with 3rd party library dir name.Don't write any module with a single name unless you are guaranteed to never import it. pyd should have called it like `module pyd.util;` Then you call yours like `module mw.util;` This makes such conflicts a lot less likely.
Oct 28 2020
On Wed, Oct 28, 2020 at 10:52:33PM +0000, Adam D. Ruppe via Digitalmars-d-learn wrote:On Wednesday, 28 October 2020 at 22:43:12 UTC, mw wrote:IMO, 3rd party libraries should always be in their own package namespace. Leave the top-level for user code! Why should a local module 'util' conflict with any dependency? It should be the library author's job to make sure his code doesn't conflict with the user's! T -- Recently, our IT department hired a bug-fix engineer. He used to work for Volkswagen.I wonder what's the best way to resolve this conflict, i.e my local file name with 3rd party library dir name.Don't write any module with a single name unless you are guaranteed to never import it. pyd should have called it like `module pyd.util;` Then you call yours like `module mw.util;` This makes such conflicts a lot less likely.
Oct 28 2020
IMO, 3rd party libraries should always be in their own package namespace. Leave the top-level for user code! Why should a local module 'util' conflict with any dependency? It should be the library author's job to make sure his code doesn't conflict with the user's!logged: https://github.com/ariovistus/pyd/issues/140
Oct 28 2020