digitalmars.D.learn - Module import incompatibility
- frame (7/7) Aug 31 2021 I'm sure it was asked before but can't find the thread:
- bauss (8/15) Aug 31 2021 The problem is that the file doesn't have a module statement so
- frame (6/20) Aug 31 2021 No, it has one, eg:
- Paul Backus (5/10) Aug 31 2021 You can use a selective import:
- frame (4/17) Aug 31 2021 Damn it's working - I swear I tried that before.
- Steven Schveighoffer (7/33) Aug 31 2021 Are you sure this is the problem? `PdfSurface` is not a valid identifier...
- Paul Backus (18/21) Aug 31 2021 Must've changed since you last checked:
- Steven Schveighoffer (19/45) Aug 31 2021 That is a top-level module that has an equivalent name inside. I did say...
- frame (8/14) Aug 31 2021 Ah, now I see the problem. It was imported with an additional
I'm sure it was asked before but can't find the thread: How to deal best with an older library that uses the same class name as module name? I get a lot of `Error: module ABC from file ...ABC.d must be imported with 'import ABC'` Do I need to rename all modules?
Aug 31 2021
On Tuesday, 31 August 2021 at 12:26:28 UTC, frame wrote:I'm sure it was asked before but can't find the thread: How to deal best with an older library that uses the same class name as module name? I get a lot of `Error: module ABC from file ...ABC.d must be imported with 'import ABC'` Do I need to rename all modules?The problem is that the file doesn't have a module statement so the compiler tries to resolve the module name from the import but is unable to resolve that properly. The fix here is the module must have a module statement but since it's a library then you probably need to go into said library and fix it manually. There's really no other fix I believe.
Aug 31 2021
On Tuesday, 31 August 2021 at 12:37:51 UTC, bauss wrote:On Tuesday, 31 August 2021 at 12:26:28 UTC, frame wrote:No, it has one, eg: ```d module cairo.PdfSurface; ``` but the filename is PdfSurface.d and class name also :\I'm sure it was asked before but can't find the thread: How to deal best with an older library that uses the same class name as module name? I get a lot of `Error: module ABC from file ...ABC.d must be imported with 'import ABC'` Do I need to rename all modules?The problem is that the file doesn't have a module statement so the compiler tries to resolve the module name from the import but is unable to resolve that properly.
Aug 31 2021
On Tuesday, 31 August 2021 at 12:57:33 UTC, frame wrote:No, it has one, eg: ```d module cairo.PdfSurface; ``` but the filename is PdfSurface.d and class name also :\You can use a selective import: ```d import cairo.PdfSurface: PdfSurface; ```
Aug 31 2021
On Tuesday, 31 August 2021 at 13:03:54 UTC, Paul Backus wrote:On Tuesday, 31 August 2021 at 12:57:33 UTC, frame wrote:Damn it's working - I swear I tried that before. I believe sometimes VsCode doesn't really updating my files. Thx.No, it has one, eg: ```d module cairo.PdfSurface; ``` but the filename is PdfSurface.d and class name also :\You can use a selective import: ```d import cairo.PdfSurface: PdfSurface; ```
Aug 31 2021
On 8/31/21 8:57 AM, frame wrote:On Tuesday, 31 August 2021 at 12:37:51 UTC, bauss wrote:Are you sure this is the problem? `PdfSurface` is not a valid identifier here except for the class. In order to access the package, you need to use `cairo.PdfSurface`. Tango was full of stuff like this, and it worked fine *as long as* it wasn't a top-level module. -SteveOn Tuesday, 31 August 2021 at 12:26:28 UTC, frame wrote:No, it has one, eg: ```d module cairo.PdfSurface; ``` but the filename is PdfSurface.d and class name also :\I'm sure it was asked before but can't find the thread: How to deal best with an older library that uses the same class name as module name? I get a lot of `Error: module ABC from file ...ABC.d must be imported with 'import ABC'` Do I need to rename all modules?The problem is that the file doesn't have a module statement so the compiler tries to resolve the module name from the import but is unable to resolve that properly.
Aug 31 2021
On Tuesday, 31 August 2021 at 14:09:01 UTC, Steven Schveighoffer wrote:Are you sure this is the problem? `PdfSurface` is not a valid identifier here except for the class. In order to access the package, you need to use `cairo.PdfSurface`.Must've changed since you last checked: ```d // main.d import example; void main() { // Error: incompatible types for `(module example) == (42)`: `void` and `int` assert(example == 42); } ``` ```d // example.d int example = 42; ``` https://run.dlang.io/is/SpEZNF
Aug 31 2021
On 8/31/21 11:17 AM, Paul Backus wrote:On Tuesday, 31 August 2021 at 14:09:01 UTC, Steven Schveighoffer wrote:That is a top-level module that has an equivalent name inside. I did say "*as long as* it wasn't a top-level module" ```d // main.d import pkg.mod; void main() { assert mod = 42; } // example.d module pkg.mod; int mod = 42; ``` works fine https://run.dlang.io/is/sQ4Bsa This is why I always try to use a top-level package instead of a module (especially with a common name). -SteveAre you sure this is the problem? `PdfSurface` is not a valid identifier here except for the class. In order to access the package, you need to use `cairo.PdfSurface`.Must've changed since you last checked: ```d // main.d import example; void main() { // Error: incompatible types for `(module example) == (42)`: `void` and `int` assert(example == 42); } ``` ```d // example.d int example = 42; ``` https://run.dlang.io/is/SpEZNF
Aug 31 2021
On Tuesday, 31 August 2021 at 14:09:01 UTC, Steven Schveighoffer wrote:Are you sure this is the problem? `PdfSurface` is not a valid identifier here except for the class. In order to access the package, you need to use `cairo.PdfSurface`. Tango was full of stuff like this, and it worked fine *as long as* it wasn't a top-level module. -SteveAh, now I see the problem. It was imported with an additional top-level package path and that caused my confusion because the compiler shows the right path in the error and also the IDE sees the package with this top-level path, so it seems right but the module declaration doesn't match, of course. Thanks.
Aug 31 2021