Thread overview | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
April 06, 2016 Issue with 2.071: Regression or valid error? | ||||
---|---|---|---|---|
| ||||
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
|
April 06, 2016 Re: Issue with 2.071: Regression or valid error? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andre | 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().
|
April 06, 2016 Re: Issue with 2.071: Regression or valid error? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Craig Dillabaugh | 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 ... |
April 06, 2016 Re: Issue with 2.071: Regression or valid error? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andre Attachments:
| 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>: > 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 >>> >> |
April 06, 2016 Re: Issue with 2.071: Regression or valid error? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Daniel Kozak | 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é
|
April 07, 2016 Re: Issue with 2.071: Regression or valid error? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andre | 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 |
April 08, 2016 Re: Issue with 2.071: Regression or valid error? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | 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
|
April 08, 2016 Re: Issue with 2.071: Regression or valid error? | ||||
---|---|---|---|---|
| ||||
Posted in reply to 9il | 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.
|
April 08, 2016 Re: Issue with 2.071: Regression or valid error? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Daniel Kozak | 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.
|
April 08, 2016 Re: Issue with 2.071: Regression or valid error? | ||||
---|---|---|---|---|
| ||||
Posted in reply to 9il | 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
|
Copyright © 1999-2021 by the D Language Foundation