Spin-off issue from bug 9159.
Between DeclDefs and function body scopes, semantic analysis works differently for variable declaration.
----
version = A; // or B
struct P {
int v;
this(int i) { v = i; }
}
P p(int i) {
assert(0);
return typeof(return)(i);
}
class C {
version(A)
P p = p(10); // Error: struct P does not overload ()
}
void main() {
version(B)
P p = p(10); // asserts in runtime
}
----
In the semantic analysis for the expression p(10),
- `p` matches the declared variable itself in DeclDefs scope (version=A).
- `p` matches the module level function in function scope (version=B).
Comment #1 by k.hara.pg — 2012-12-23T08:21:37Z
Related: issue 3131
Comment #2 by robert.schadek — 2024-12-13T18:03:26Z