Module import incompatibility

Steven Schveighoffer schveiguy at gmail.com
Tue Aug 31 16:37:15 UTC 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:
> 
> ```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
> 

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

-Steve


More information about the Digitalmars-d-learn mailing list