www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Not sure .. is this a bug?

reply Downs <default_357-line yahoo.de> writes:
import std.stdio;

class foo { int e; abstract const void bar(); }

class bug: foo { void bar() { writefln("I NOW CHANGEZ TEH OBJECTS"); e=5; } }

void main() {
  const(bug) okay=new bug;
  // okay.bar; fails as expected
  const(foo) Bug=cast(foo)okay;
  Bug.bar; // interestingly works.
}

From my POV, the Bug.bar is modifying data it shouldn't be able to modify, but
then again, I'm rather new to the whole constness thing. So, is this a bug?
 -- downs
Jun 28 2007
next sibling parent Frits van Bommel <fvbommel REMwOVExCAPSs.nl> writes:
Downs wrote:
 import std.stdio;
 
 class foo { int e; abstract const void bar(); }
 
 class bug: foo { void bar() { writefln("I NOW CHANGEZ TEH OBJECTS"); e=5; } }
 
 void main() {
   const(bug) okay=new bug;
   // okay.bar; fails as expected
   const(foo) Bug=cast(foo)okay;
   Bug.bar; // interestingly works.
 }
 
 From my POV, the Bug.bar is modifying data it shouldn't be able to modify, but
then again, I'm rather new to the whole constness thing. So, is this a bug?
I'd have expected the compiler to give an error when trying to override "const void bar()" with "void bar()" in 'bug'...
Jun 28 2007
prev sibling parent reply nick <nick.atamas gmail.com> writes:
Downs wrote:
 import std.stdio;
 
 class foo { int e; abstract const void bar(); }
 
 class bug: foo { void bar() { writefln("I NOW CHANGEZ TEH OBJECTS"); e=5; } }
 
 void main() {
   const(bug) okay=new bug;
   // okay.bar; fails as expected
   const(foo) Bug=cast(foo)okay;
   Bug.bar; // interestingly works.
 }
 
 From my POV, the Bug.bar is modifying data it shouldn't be able to modify, but
then again, I'm rather new to the whole constness thing. So, is this a bug?
  -- downs
Your code does not compile.
Jun 28 2007
parent downs <default_357-line yahoo.de> writes:
nick Wrote:

 Downs wrote:
 import std.stdio;
 
 class foo { int e; abstract const void bar(); }
 
 class bug: foo { void bar() { writefln("I NOW CHANGEZ TEH OBJECTS"); e=5; } }
 
 void main() {
   const(bug) okay=new bug;
   // okay.bar; fails as expected
   const(foo) Bug=cast(foo)okay;
   Bug.bar; // interestingly works.
 }
 
 From my POV, the Bug.bar is modifying data it shouldn't be able to modify, but
then again, I'm rather new to the whole constness thing. So, is this a bug?
  -- downs
Your code does not compile.
Hm. Seeing as I wouldn't have posted it here if it didn't compile for me, how about a little more info? For example, what error did you get? What compiler version do you use? This is code for D 2.0, in case it wasn't clear from the use of const, so naturally it won't work on 1.0 compilers.. -- downs
Jun 29 2007