www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3182] New: compile time access of imported symbol

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3182

           Summary: compile time access of imported symbol
           Product: D
           Version: unspecified
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: ellery-newcomer utulsa.edu


The following code does not print 'z=1!' when compiled, as if a premature
attempted access to z causes the compiler to believe z doesn't exist even after
the import statement. Take out the first static if, and issue goes away. Change
the import to 'import test2: z;' and issue goes away.

Question: Would I be incorrect in assuming the expected output of this compile
should be

no z!
z!
z=1!


test.d
-------
import tango.io.Stdout;
static if(is(typeof(z))){
    pragma(msg,"z!");
}else{
    pragma(msg,"no z!");
}
import test2;
static if(is(typeof(z))){
    pragma(msg,"z!");
}else{
    pragma(msg,"no z!");
}
static if(z == 1) pragma(msg,"z=1!");

void main(){
}
-------
test2.d
-------
module test2;
const int z = 1;

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 15 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3182


Jarrett Billingsley <jarrett.billingsley gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jarrett.billingsley gmail.c
                   |                            |om




--- Comment #1 from Jarrett Billingsley <jarrett.billingsley gmail.com> 
2009-07-16 08:12:41 PDT ---
I don't think your ideas on the ordering are right.  You can place imports
anywhere in a module and their symbols will be accessible before or after.  For
instance:

[mod.d]
module mod;
void foo() {}

[test.d]
void bar() { foo(); } // fine
import mod;

So, if anything, I'd expect the output to be

z!
z!
z=1!

But the compiler doesn't seem to be doing that.  That the static if before the
import causes later references to 'z' to be invalid is even stranger.  Also, if
you replace 'z' with something else (like "void z(){}"), you get other
behavior, making me think that the semantic analysis is being done differently
for different types.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 16 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3182





--- Comment #2 from Ellery Newcomer <ellery-newcomer utulsa.edu>  2009-07-16
19:00:38 PDT ---
Well, the distinction is whether the symbol is used in compile time expressions
or run time expressions. Currently, DMD performs some or all compile time
evaluation in the same pass as it builds the symbol table, which is why you get
the behavior for the first static if.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 16 2009