digitalmars.D.learn - Package method is not virtual and cannot override - a bug or a
- Piotr Mitana (24/24) May 10 2018 Given this code:
- Jonathan M Davis (6/30) May 10 2018 I don't rememeber the reasoning at the moment, but it's most definitely ...
Given this code:
abstract class A
{
package property void x(int x);
package property int x();
}
class B : A
{
package property override void x(int x) {}
package property override int x() { return 0; }
}
void main() {}
I get the following message:
onlineapp.d(9): Error: function `onlineapp.B.x` package method is
not virtual and cannot override
onlineapp.d(10): Error: function `onlineapp.B.x` package method
is not virtual and cannot override
Why is that? If the access specifier is private, I can perfectly
understand it - subclasses can't call the private method of
parent class, so there's no need in making it virtual. For
protected/public the code compiles. However, for the package
protection it may happen that a subclass is in the same package
(and just happened to me).
Should I file a bug or is there a reason for such behavior?
May 10 2018
On Thursday, May 10, 2018 11:52:38 Piotr Mitana via Digitalmars-d-learn
wrote:
Given this code:
abstract class A
{
package property void x(int x);
package property int x();
}
class B : A
{
package property override void x(int x) {}
package property override int x() { return 0; }
}
void main() {}
I get the following message:
onlineapp.d(9): Error: function `onlineapp.B.x` package method is
not virtual and cannot override
onlineapp.d(10): Error: function `onlineapp.B.x` package method
is not virtual and cannot override
Why is that? If the access specifier is private, I can perfectly
understand it - subclasses can't call the private method of
parent class, so there's no need in making it virtual. For
protected/public the code compiles. However, for the package
protection it may happen that a subclass is in the same package
(and just happened to me).
Should I file a bug or is there a reason for such behavior?
I don't rememeber the reasoning at the moment, but it's most definitely not
a bug and is on purpose. There's probably a "won't fix" bug in bugzilla for
it if you go digging.
- Jonathan M Davis
May 10 2018








Jonathan M Davis <newsgroup.d jmdavisprog.com>