digitalmars.D.learn - conflicting alias in package module
- 60rntogo (21/21) Sep 26 2020 I have a package with the following structure:
- Steven Schveighoffer (5/33) Sep 26 2020 A selective import is equivalent to aliasing (to the public) the symbol
- 60rntogo (5/8) Sep 26 2020 Are you saying that I should write this in bar.d?
- Steven Schveighoffer (11/23) Sep 26 2020 Oh wait, I missed the problem. It's here:
- 60rntogo (6/9) Sep 26 2020 OK, sure. It's just that the motivation behind doing public
- Mike Parker (2/6) Sep 26 2020 package.d is for your external interface.
- 60rntogo (2/3) Sep 26 2020 Fair enough, thanks.
- Steven Schveighoffer (5/9) Sep 27 2020 This isn't an issue with package, it's an issue with a circular dependen...
- Steven Schveighoffer (4/13) Sep 27 2020 Just in case someone comes along and reads this, I was wrong about this....
I have a package with the following structure: pack |- foo.d |- bar.d |- package.d and the modules look like this: --- module pack.foo; struct Foo {} --- module pack.bar; import pack : Foo; --- module pack; public import pack.foo, pack.bar; --- and this is an error: "struct pack.foo.Foo at source/pack/foo.d(3,1) conflicts with alias pack.bar.Foo at source/pack/bar.d(3,8)". I seems like the import in package.d sees Foo both in pack.foo and pack.bar, but I don't understand why this happens since the import in bar.d is private, isn't it?
Sep 26 2020
On 9/26/20 3:33 AM, 60rntogo wrote:I have a package with the following structure: pack |- foo.d |- bar.d |- package.d and the modules look like this: --- module pack.foo; struct Foo {} --- module pack.bar; import pack : Foo; --- module pack; public import pack.foo, pack.bar; --- and this is an error: "struct pack.foo.Foo at source/pack/foo.d(3,1) conflicts with alias pack.bar.Foo at source/pack/bar.d(3,8)". I seems like the import in package.d sees Foo both in pack.foo and pack.bar, but I don't understand why this happens since the import in bar.d is private, isn't it?A selective import is equivalent to aliasing (to the public) the symbol as if it were defined in that scope. You have to label it as private if you want it to be private. -Steve
Sep 26 2020
On Saturday, 26 September 2020 at 13:45:21 UTC, Steven Schveighoffer wrote:A selective import is equivalent to aliasing (to the public) the symbol as if it were defined in that scope. You have to label it as private if you want it to be private.Are you saying that I should write this in bar.d? private import pack : Foo; This still gives the same error.
Sep 26 2020
On 9/26/20 10:59 AM, 60rntogo wrote:On Saturday, 26 September 2020 at 13:45:21 UTC, Steven Schveighoffer wrote:Oh wait, I missed the problem. It's here: pack/bar.d: module pack.bar; import pack : Foo; Here you are importing the PACKAGE, which is importing bar, which is trying to define Foo. It's a recursive loop. Instead: import pack.foo : Foo; Works. -SteveA selective import is equivalent to aliasing (to the public) the symbol as if it were defined in that scope. You have to label it as private if you want it to be private.Are you saying that I should write this in bar.d? private import pack : Foo; This still gives the same error.
Sep 26 2020
On Saturday, 26 September 2020 at 15:12:47 UTC, Steven Schveighoffer wrote:Instead: import pack.foo : Foo; Works.OK, sure. It's just that the motivation behind doing public imports in package.d is that I can write "import pack" instead of "import pack.foo". I guess it simply doesn't work within the package itself.
Sep 26 2020
On Saturday, 26 September 2020 at 22:43:10 UTC, 60rntogo wrote:OK, sure. It's just that the motivation behind doing public imports in package.d is that I can write "import pack" instead of "import pack.foo". I guess it simply doesn't work within the package itself.package.d is for your external interface.
Sep 26 2020
On Sunday, 27 September 2020 at 03:33:20 UTC, Mike Parker wrote:package.d is for your external interface.Fair enough, thanks.
Sep 26 2020
On 9/27/20 1:17 AM, 60rntogo wrote:On Sunday, 27 September 2020 at 03:33:20 UTC, Mike Parker wrote:This isn't an issue with package, it's an issue with a circular dependency. You are importing yourself and trying alias something to itself before that is defined, which has a conflict. -Stevepackage.d is for your external interface.Fair enough, thanks.
Sep 27 2020
On 9/26/20 9:45 AM, Steven Schveighoffer wrote:On 9/26/20 3:33 AM, 60rntogo wrote:Just in case someone comes along and reads this, I was wrong about this. It's not a public import. -Steveand this is an error: "struct pack.foo.Foo at source/pack/foo.d(3,1) conflicts with alias pack.bar.Foo at source/pack/bar.d(3,8)". I seems like the import in package.d sees Foo both in pack.foo and pack.bar, but I don't understand why this happens since the import in bar.d is private, isn't it?A selective import is equivalent to aliasing (to the public) the symbol as if it were defined in that scope.
Sep 27 2020