digitalmars.D.learn - Cannot Call Super-Class Overloaded Function If Class has Function
- Vijay Nayar (33/33) Mar 01 2022 I've randomly encountered a strange error, and I cannot find any
- vit (31/64) Mar 01 2022 ```d
- vit (3/6) Mar 01 2022 Here is more info (3.):
- Vijay Nayar (5/12) Mar 01 2022 Very well spotted, thank you for that!
- Mike Parker (2/6) Mar 01 2022 https://dlang.org/articles/hijack.html
I've randomly encountered a strange error, and I cannot find any explanation for it in the official documentation of syntax. Essentially, a class cannot call function overload in a super-class if the class itself contains an override. Is this a bug? Is this on purpose? Take a look at `B.otherThing()` below. ``` d void main() { abstract class A { // An abstract method for sub-classes abstract void doThing(string a, size_t b); // A convenience helper. void doThing(string a) { doThing(a, a.length); } } class B : A { // If this overload exists, something strange happens... override void doThing(string a, size_t b) { } void otherThing() { // Error: `B.doThing(string a, ulong b)` // is not callable using argument // types `(string)` doThing("hello"); super.doThing("hello"); // OK } } } ```
Mar 01 2022
On Tuesday, 1 March 2022 at 08:40:12 UTC, Vijay Nayar wrote:I've randomly encountered a strange error, and I cannot find any explanation for it in the official documentation of syntax. Essentially, a class cannot call function overload in a super-class if the class itself contains an override. Is this a bug? Is this on purpose? Take a look at `B.otherThing()` below. ``` d void main() { abstract class A { // An abstract method for sub-classes abstract void doThing(string a, size_t b); // A convenience helper. void doThing(string a) { doThing(a, a.length); } } class B : A { // If this overload exists, something strange happens... override void doThing(string a, size_t b) { } void otherThing() { // Error: `B.doThing(string a, ulong b)` // is not callable using argument // types `(string)` doThing("hello"); super.doThing("hello"); // OK } } } ``````d void main() { abstract class A { // An abstract method for sub-classes abstract void doThing(string a, size_t b); // A convenience helper. void doThing(string a) { doThing(a, a.length); } } class B : A { // If this overload exists, something strange happens... override void doThing(string a, size_t b) { } alias doThing = typeof(super).doThing; //add super.doThing to overload set. void otherThing() { // Error: `B.doThing(string a, ulong b)` // is not callable using argument // types `(string)` doThing("hello"); super.doThing("hello"); // OK } } } ```
Mar 01 2022
On Tuesday, 1 March 2022 at 08:40:12 UTC, Vijay Nayar wrote:I've randomly encountered a strange error, and I cannot find any explanation for it in the official documentation of syntax. [...]Here is more info (3.): https://docarchives.dlang.io/v2.078.0/spec/function.html#function-inheritance
Mar 01 2022
On Tuesday, 1 March 2022 at 09:06:59 UTC, vit wrote:On Tuesday, 1 March 2022 at 08:40:12 UTC, Vijay Nayar wrote:Very well spotted, thank you for that! I'm a bit surprised at this behavior though. Do you happen to know why it is considered bad to take into account the overloads of a super-class when resolving a call in a derived-class?I've randomly encountered a strange error, and I cannot find any explanation for it in the official documentation of syntax. [...]Here is more info (3.): https://docarchives.dlang.io/v2.078.0/spec/function.html#function-inheritance
Mar 01 2022
On Tuesday, 1 March 2022 at 09:10:46 UTC, Vijay Nayar wrote:I'm a bit surprised at this behavior though. Do you happen to know why it is considered bad to take into account the overloads of a super-class when resolving a call in a derived-class?https://dlang.org/articles/hijack.html
Mar 01 2022