www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Version bug?

reply Adam Ruppe <destructionator gmail.com> writes:
I just hit something that might be a compiler bug, or might be a
documentation bug. (Of course, it can't be me! :P )

I have two modules:

config.d
===
version (clientA) {}

version ( clientB ) {
    version = withFeatureX;
}

version (clientC) {
   version = withFeatureX;
}
===

application.d
===
import config;
void main() {
   version(withFeatureX)
       static assert(0);
}
====


dmd application.d config.d -version=clientB

This compiles, but I expect it to hit the static assert.

Should it? Note that it does work correctly if I put the version= line
in the actual file, but that means I can't have the nice centralized
config module anymore.

So is this a bug, or should the documentation be a bit more explicit
about version = lines only working inside the one module? (or should I
just learn how to read? :-P)

I kinda miss #include here.....
Aug 20 2010
next sibling parent Stewart Gordon <smjg_1998 yahoo.com> writes:
Adam Ruppe wrote:
 I just hit something that might be a compiler bug, or might be a
 documentation bug. (Of course, it can't be me! :P )
<snip> As has been said, it's by design. However, it does destroy much of the usefulness of VersionSpecification. As such, there ought to be an explicit means of importing the versions set by a module. Some time ago, there was a brief discussion of this http://www.digitalmars.com/d/archives/digitalmars/D/11981.html but it was inconclusive. Stewart.
Aug 21 2010
prev sibling parent Walter Bright <newshound2 digitalmars.com> writes:
Adam Ruppe wrote:
 Should it? Note that it does work correctly if I put the version= line
 in the actual file, but that means I can't have the nice centralized
 config module anymore.
The compiler is exhibiting correct behavior. The idea is, versions exist only in the module's scope. You cannot scope them, nest them, etc. they are global to the module. This means that if an imported module declared versions, then it could have unhygienic interactions with versions declared in the importers. But manifest constant declarations, like: enum Foo = 7; can be tested by the importer with static if. These declarations can be nested, scoped, etc., and there are protections in the language for inadvertent ambiguities from imports, and ways to control it - it's all very hygienic. Versions are intended really for global, project-wide things like demo/paid version, etc., and should not be set by configuration files.
Aug 22 2010