Thread overview
Module import incompatibility
Aug 31, 2021
frame
Aug 31, 2021
bauss
Aug 31, 2021
frame
Aug 31, 2021
Paul Backus
Aug 31, 2021
frame
Aug 31, 2021
Paul Backus
Aug 31, 2021
frame
August 31, 2021

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?

August 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.

August 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:

>

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.

No, it has one, eg:

module cairo.PdfSurface;

but the filename is PdfSurface.d and class name also :\

August 31, 2021

On Tuesday, 31 August 2021 at 12:57:33 UTC, frame wrote:

>

No, it has one, eg:

module cairo.PdfSurface;

but the filename is PdfSurface.d and class name also :\

You can use a selective import:

import cairo.PdfSurface: PdfSurface;
August 31, 2021

On 8/31/21 8:57 AM, frame wrote:

>

On Tuesday, 31 August 2021 at 12:37:51 UTC, bauss wrote:

>

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.

No, it has one, eg:

module cairo.PdfSurface;

but the filename is PdfSurface.d and class name also :\

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.

-Steve

August 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:

// main.d
import example;

void main()
{
    // Error: incompatible types for `(module example) == (42)`: `void` and `int`
    assert(example == 42);
}
// example.d
int example = 42;

https://run.dlang.io/is/SpEZNF

August 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:

>

No, it has one, eg:

module cairo.PdfSurface;

but the filename is PdfSurface.d and class name also :\

You can use a selective import:

import cairo.PdfSurface: PdfSurface;

Damn it's working - I swear I tried that before.
I believe sometimes VsCode doesn't really updating my files.

Thx.

August 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.

-Steve

Ah, 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.

August 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:

>

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:

// main.d
import example;

void main()
{
     // Error: incompatible types for `(module example) == (42)`: `void` and `int`
     assert(example == 42);
}
// example.d
int example = 42;

https://run.dlang.io/is/SpEZNF

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"

// 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).

-Steve