Variables should probably not shadow parent methods

qznc via Digitalmars-d digitalmars-d at puremagic.com
Tue Jul 12 04:53:26 PDT 2016


Just seen on Reddit [0] and there are a few more examples.

   class Test
   {
     string function() toString = function() { return "one"; };
   }

   void main()
   {
     auto test = new Test;
     writeln(test);
     test.toString = function() { return "two"; };
     writeln(cast(Object)test);
   }

Test has a delegate field `toString` which shadows the method 
`toString` inherited from Object. Could we make this an error?


[0] 
https://www.reddit.com/r/d_language/comments/4sfcv8/overriding_parents_member_function_with_anonymous/


More information about the Digitalmars-d mailing list