February 22, 2014
On Saturday, 22 February 2014 at 22:42:24 UTC, simendsjo wrote:
> The problem isn't about optional parenthesis or properties. It's the fact that
> you can redefine a symbol to be something entierly different, and that this
> difference will only be seen if you are looking at the symbol through the
> "correct" type.
You are right. I thought that if we had forced parenthesis, the compiler would at least be able to understand what symbol you were referring to, but this is actually not the case.
February 23, 2014
On 22.2.2014. 23:43, simendsjo wrote:
> On 02/22/2014 11:33 PM, Francesco Cattoglio wrote:
> The problem isn't about optional parenthesis or properties. It's the
> fact that
> you can redefine a symbol to be something entierly different, and that this
> difference will only be seen if you are looking at the symbol through the
> "correct" type.

That is exactly what I wanted to point out! I reduced the example code to make that point more obvious:


import std.stdio;

class A {
  string x = "A";
}

class B : A {
  // should it be legal to hide a symbol and redefine it to a new type?
  int x = 2;
}

//static assert (is(typeof(A.x) == typeof(B.x)));
//Error: static assert (is(string == int)) is false

void main () {
  B o = new B();
  writeln((cast (A)o).x); // A
  writeln((cast (B)o).x); // 2
}


http://dpaste.dzfl.pl/6ae4ac5de1bc

February 23, 2014
On 23.2.2014. 13:51, luka8088 wrote:
> That is exactly what I wanted to point out! I reduced the example code to make that point more obvious:

Just one note. I know how this works currently in D and how it works in C++. What I am asking here is not how it works but is this a good idea as I just see it as a possible source of bugs without any benefit.

1 2
Next ›   Last »