module b;
template member(alias s, string m) {
static assert(__traits(hasMember, s, m)); // passes for both x and b
alias member = mixin("s.", m); // fails for b
}
----
module a;
import b;
int x;
alias x1 = member!(a, "x"); // ok
alias b1 = a.b; // ok
alias b2 = member!(a, "b"); // fail
void main() {
}
----
source/b.d-mixin-5(5,1): Error: undefined identifier b in module a
source/a.d(9,12): Error: template instance b.member!(a, "b") error instantiating
Comment #1 by pro.mathias.lang — 2020-12-11T14:24:44Z
> source/b.d-mixin-5(5,1): Error: undefined identifier b in module a
This is correct. `b` is not a member of `a`, it's an import. I'm tempted to mark this as `INVALID`.
Comment #2 by maxsamukha — 2020-12-11T15:10:51Z
If imports are not members, then:
__traits(allMembers, importing_module) must not return imports;
__traits(hasMember, importing_module, "imported_module") must return false;
it must be impossible to refer to the imported module as 'importing_module.imported_module' everywhere including the importing module.
Also, being an import and being a member are not conceptually exclusive. "`b` is not a member of `a`, it's an import" sounds too dogmatic to me.
Comment #3 by robert.schadek — 2024-12-13T19:13:26Z