Packages / imports & references between modules

Robert M. Münch robert.muench at saphirion.com
Sat Apr 27 16:24:40 UTC 2019


On 2019-04-27 15:06:01 +0000, Adam D. Ruppe said:

> On Saturday, 27 April 2019 at 14:58:01 UTC, Robert M. Münch wrote:
>> 	import A.a;
> 
> `import` by itself is a private import, meaning it cannot be seen from 
> outside the module.
> 
> Make it `public import` and it can be seen from the outside; the other 
> modules importing it can access them too.

I thought that public only applies to the upward chain, not to the same level.

However, using public doens't help as there are still some undefined 
identifiers between modules on the same level. I think I need to 
elaborate on my case a bit more:

I use DStep to convert some C library headers. And these use forward 
references to structs.

A/a.d
	module A.a;
	struct myStruct;

A/b.d
	module A.b;
	struct myStruct {...}

A/c.d
	module A.c;
	struct myOtherStruct {
		myStruct ms;
	}

A/package.d
	import A.a;
	import A.b;
	import A.c;

I get an "undefined identifier" error in A/c.d for myStruct. Changing A/c.d to:

A/c.d
	module A.c;
	import A.b;
	struct myOtherStruct {
		myStruct ms;
	}

works. But this would end up in adding a lot of imports to avoid the 
"undefined identifier" problem to many files manually and somehow break 
the DStep workflow.

So, is there a way to avoid this? With public import it doesn't seem to work.

-- 
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



More information about the Digitalmars-d-learn mailing list