digitalmars.D.bugs - imported version specifications fail in some cases
- Lars Ivar Igesund (52/52) Jul 26 2004 I have a module foody:
I have a module foody:
--------
version = foody;
--------
Another module looks like this:
--------
import std.stdio;
import foody;
version (foody) {
int f() { return 77; }
}
version (bardy) {
int f() { return 3; }
}
void main() {
writefln(f());
}
--------
This won't compile, saying that f is and undefined identifier.
Doing it the way below works as expected:
--------
import std.stdio;
import foody;
void main() {
version (foody) {
int f() { return 77; }
}
version (bardy) {
int f() { return 3; }
}
writefln(f());
}
--------
Maybe you should specify the rules for version specification lookup? I
would expect one of two;
1. version specifications are applied after they have been found
(lexically? not to sure about the wording to use). That is;
-----------
version (foody) { int foo() {return 77;} }
version = foody; // or import with version = foody;
-----------
The version block is kept out of the compilation. Switching the lines
works. (This is the way it works with the version specification
statement. Due to the behaviour outlined above, I can't test it with
imports.)
2. all version specifications are looked up before checking if a block
should be compiled in or not. I suspect that this solution can lead to a
recursive nightmare, as version blocks can hold further specifications
and imports.
Personally, I think 1 is the correct answer (and that 1 *should* be the
correct answer) but that the implementation is somewhat lacking.
Lars Ivar Igesund
Jul 26 2004








Lars Ivar Igesund <larsivar igesund.net>