www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Issue with 2.071: Regression or valid error?

reply Andre <andre.pany sap.com> writes:
Hi,

With 2.071 following coding does not compile anymore and somehow 
I feel it should compile.
The issue is with line "cat.create();".
Cat is a sub type of Animal. Animal "owns" method create and I 
want to call the method
create within the class Animal for cat.

Is the error message "no property create for type 'b.cat'" valid 
or not?

Kind regards
André

module a;
import b;

class Animal
{
	private void create() {}
	
	void foo(Cat cat)
	{
		cat.create(); // >> no property create for type 'b.cat'
	}
}

void main() {}

--------------

module b;
import a;

class Cat: Animal {};

compile with
 rdmd a b
Apr 06 2016
next sibling parent reply Craig Dillabaugh <craig.dillabaugh gmail.com> writes:
On Wednesday, 6 April 2016 at 15:10:45 UTC, Andre wrote:
 Hi,

 With 2.071 following coding does not compile anymore and 
 somehow I feel it should compile.
 The issue is with line "cat.create();".
 Cat is a sub type of Animal. Animal "owns" method create and I 
 want to call the method
 create within the class Animal for cat.

 Is the error message "no property create for type 'b.cat'" 
 valid or not?

 Kind regards
 André

 module a;
 import b;

 class Animal
 {
 	private void create() {}
 	
 	void foo(Cat cat)
 	{
 		cat.create(); // >> no property create for type 'b.cat'
 	}
 }

 void main() {}

 --------------

 module b;
 import a;

 class Cat: Animal {};

 compile with
 rdmd a b
Not so up to date on D's OOP stuff, but don't you want create() to be protected, not private. You can typically access a private method through a base class, which is what you are doing with cat.create().
Apr 06 2016
parent Craig Dillabaugh <craig.dillabaugh gmail.com> writes:
On Wednesday, 6 April 2016 at 19:01:58 UTC, Craig Dillabaugh 
wrote:
 On Wednesday, 6 April 2016 at 15:10:45 UTC, Andre wrote:
clip
 Not so up to date on D's OOP stuff, but don't you want create() 
 to be protected, not private.  You can typically access a 
 private method through a base class, which is what you are 
 doing with cat.create().
You CAN'T typically access a private ...
Apr 06 2016
prev sibling next sibling parent reply Daniel Kozak via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
This should not compile. Cat cant access create because it is private. Ok
it can access it but only if you move cat into same module as animal
Dne 6. 4. 2016 17:16 napsal u=C5=BEivatel "Andre via Digitalmars-d-learn" <
digitalmars-d-learn puremagic.com>:

 Hi,

 With 2.071 following coding does not compile anymore and somehow I feel i=
t
 should compile.
 The issue is with line "cat.create();".
 Cat is a sub type of Animal. Animal "owns" method create and I want to
 call the method
 create within the class Animal for cat.

 Is the error message "no property create for type 'b.cat'" valid or not?

 Kind regards
 Andr=C3=A9

 module a;
 import b;

 class Animal
 {
         private void create() {}

         void foo(Cat cat)
         {
                 cat.create(); // >> no property create for type 'b.cat'
         }
 }

 void main() {}

 --------------

 module b;
 import a;

 class Cat: Animal {};

 compile with

 rdmd a b

Apr 06 2016
parent Andre <andre s-e-a-p.de> writes:
On Wednesday, 6 April 2016 at 19:22:44 UTC, Daniel Kozak wrote:
 This should not compile. Cat cant access create because it is 
 private. Ok
 it can access it but only if you move cat into same module as 
 animal
 Dne 6. 4. 2016 17:16 napsal uživatel "Andre via 
 Digitalmars-d-learn" <
 digitalmars-d-learn puremagic.com>:
Thanks for the answers. Kind regards André
Apr 06 2016
prev sibling parent reply Steven Schveighoffer <schveiguy yahoo.com> writes:
On 4/6/16 11:10 AM, Andre wrote:
 Hi,

 With 2.071 following coding does not compile anymore and somehow I feel
 it should compile.
 The issue is with line "cat.create();".
 Cat is a sub type of Animal. Animal "owns" method create and I want to
 call the method
 create within the class Animal for cat.

 Is the error message "no property create for type 'b.cat'" valid or not?

 Kind regards
 André

 module a;
 import b;

 class Animal
 {
      private void create() {}

      void foo(Cat cat)
      {
          cat.create(); // >> no property create for type 'b.cat'
      }
 }

 void main() {}

 --------------

 module b;
 import a;

 class Cat: Animal {};
Just FYI, you don't need a semicolon there.
 compile with
 rdmd a b
Wow, totally agree with you. Compiler shouldn't make you jump through this hoop: void foo(Cat cat) { Animal a = cat; a.create(); } Please file a bug report, not sure why this happened. -Steve
Apr 07 2016
next sibling parent reply 9il <ilyayaroshenko gmail.com> writes:
On Thursday, 7 April 2016 at 15:55:16 UTC, Steven Schveighoffer 
wrote:
 On 4/6/16 11:10 AM, Andre wrote:
 [...]
Just FYI, you don't need a semicolon there.
 [...]
Wow, totally agree with you. Compiler shouldn't make you jump through this hoop: void foo(Cat cat) { Animal a = cat; a.create(); } Please file a bug report, not sure why this happened. -Steve
Why this is a bug? private methods are not virtual, are they? --Ilya
Apr 07 2016
next sibling parent reply Daniel Kozak <kozzi11 gmail.com> writes:
On Friday, 8 April 2016 at 06:08:38 UTC, 9il wrote:
 On Thursday, 7 April 2016 at 15:55:16 UTC, Steven Schveighoffer 
 wrote:
 On 4/6/16 11:10 AM, Andre wrote:
 [...]
Just FYI, you don't need a semicolon there.
 [...]
Wow, totally agree with you. Compiler shouldn't make you jump through this hoop: void foo(Cat cat) { Animal a = cat; a.create(); } Please file a bug report, not sure why this happened. -Steve
Why this is a bug? private methods are not virtual, are they? --Ilya
No they are not virtual, so this is not a bug.
Apr 08 2016
parent Rene Zwanenburg <renezwanenburg gmail.com> writes:
On Friday, 8 April 2016 at 08:26:11 UTC, Daniel Kozak wrote:
 On Friday, 8 April 2016 at 06:08:38 UTC, 9il wrote:
 On Thursday, 7 April 2016 at 15:55:16 UTC, Steven 
 Schveighoffer wrote:
 Wow, totally agree with you. Compiler shouldn't make you jump 
 through this hoop:

 void foo(Cat cat)
 {
    Animal a = cat;
    a.create();
 }

 Please file a bug report, not sure why this happened.

 -Steve
Why this is a bug? private methods are not virtual, are they? --Ilya
No they are not virtual, so this is not a bug.
I disagree, virtuality has nothing to do with this. After all, moving Cat to the same module as Animal, or making create() public final will make the code compile. Private symbols can (only) be accessed from the module where they are defined, so anything in the animal module should be able to call create() on a Cat just fine.
Apr 08 2016
prev sibling parent reply Steven Schveighoffer <schveiguy yahoo.com> writes:
On 4/8/16 2:08 AM, 9il wrote:
 On Thursday, 7 April 2016 at 15:55:16 UTC, Steven Schveighoffer wrote:
 On 4/6/16 11:10 AM, Andre wrote:
 [...]
Just FYI, you don't need a semicolon there.
 [...]
Wow, totally agree with you. Compiler shouldn't make you jump through this hoop: void foo(Cat cat) { Animal a = cat; a.create(); } Please file a bug report, not sure why this happened.
Why this is a bug? private methods are not virtual, are they? --Ilya
A Cat is an Animal. The compiler knows this. The 'a' module has access to Animal private methods. This isn't a virtual call, but a call to a base class member. Those are allowed. How can you think this is not a bug? Would you think it was a bug if create was a final function instead of private? This is exactly the same thing. -Steve
Apr 08 2016
parent Daniel Kozak via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
Dne 8.4.2016 v 14:56 Steven Schveighoffer via Digitalmars-d-learn napsal(a):
 On 4/8/16 2:08 AM, 9il wrote:
 On Thursday, 7 April 2016 at 15:55:16 UTC, Steven Schveighoffer wrote:
 On 4/6/16 11:10 AM, Andre wrote:
 [...]
Just FYI, you don't need a semicolon there.
 [...]
Wow, totally agree with you. Compiler shouldn't make you jump through this hoop: void foo(Cat cat) { Animal a = cat; a.create(); } Please file a bug report, not sure why this happened.
Why this is a bug? private methods are not virtual, are they? --Ilya
A Cat is an Animal. The compiler knows this. The 'a' module has access to Animal private methods. This isn't a virtual call, but a call to a base class member. Those are allowed. How can you think this is not a bug? Would you think it was a bug if create was a final function instead of private? This is exactly the same thing. -Steve
Yes ou are right, I see it now :), thanks.
Apr 08 2016
prev sibling parent Steven Schveighoffer <schveiguy yahoo.com> writes:
On 4/7/16 11:55 AM, Steven Schveighoffer wrote:
 Please file a bug report, not sure why this happened.
I filed it for you: https://issues.dlang.org/show_bug.cgi?id=15897 -Steve
Apr 08 2016