This code should IMO give at least a warning, but it doesn't:

abstract class A {
    int kind;
}

class B : A {
    int kind;

    this(int k) {
        kind = k;
    }
}

In my actual code, the declaration of field "kind" in B was left in accidentally. Surprisingly, however, no warning was emitted when I compiled this, leading to B having two fields called kind which are distinct from one another. The complete program

import std.stdio;

abstract class A {
    int kind;
}

class B : A {
    int kind;

    this(int k) {
        kind = k;
    }
}

void main()
{
    auto b = new B(4);
    A a = b;

    writeln(b.kind);
    writeln(a.kind);
}

prints

4
0

Given that this is the kind of thing that is easily done, surely the default behaviour should be for the compiler to emit at least a warning that field "kind" is ambiguous in B? This behaviour occurs even when the field is declared as "public" or "protected" in both classes. What am I missing?

Reply via email to