www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Cannot resolve constant from package when used as initial parameter

reply "tcak" <tcak pcak.com> writes:
I recently started using that new feature "package.d". While 
writing codes today, I started seeing some errors. For 
illustration, I wrote a piece of code. I will list 3 different 
files here. File-Folder structure is below:


File: app.d
import pipes;

void main(){}

File: ./pipes/package.d
module pipes;

public import pipes.namedpipe;

public enum PIPE_BUF = 4096;

File: ./pipes/namedpipe.d
module pipes.namedpipe;

public int getPipeBufferSize(){ return pipes.PIPE_BUF; }

public void foo( size_t a = pipes.PIPE_BUF ){}

Situation is that if I do not define that "foo" function in 
namedpipe.d file, everything is fine. No error at all, and 
"getPipeBufferSize" function returns the value that comes from 
"pipes.PIPE_BUF". When the function "foo" is defined that takes 
pipes.PIPE_BUF as its initial value of parameter, following error 
is seen:

pipes/namedpipe.d(7): Error: cannot resolve type for PIPE_BUF


While writing this post, I discovered that in "pipes/package.d" 
file, if I define "PIPE_BUF" BEFORE the import command as below:

module pipes;

public enum PIPE_BUF = 4096;

public import pipes.namedpipe;

then there is no error at all. Is this intentional? As far as I 
remember, D compiler was finding definitions no matter later or 
before defined.
Feb 13 2014
parent Marco Leise <Marco.Leise gmx.de> writes:
Where possible, the order of declaration in D should not
matter. Consider filing a bug report about that if it doesn't
exist yet.

Feb 17 2014