Please be more careful when changing the language behavior
mw
mingwu at gmail.com
Thu Jun 4 07:13:40 UTC 2020
On Wednesday, 3 June 2020 at 19:40:10 UTC, jmh530 wrote:
> On Tuesday, 2 June 2020 at 06:17:50 UTC, mw wrote:
>> [snip]
>
> Thanks for that some interesting materials there about Eiffel.
>
> As it says on the wikipedia page, the select & rename together
> drives their solution. Combining select and rename in one class
> is like an alias in D. However, D does not have the ability to
> prevent calling a member function of an inherited class. Using
> opDispatch doesn't work because it comes after calling member
> functions.
>
> I think the most D-like way to incorporate this behavior is to
> allow @disable in a derived class for a base member function.
> Right now (see code below), you get a message about a
> depreciation (I think this one [1]) and not being able to
> @disable an overridden (you have to throw in an override) base
> class member function.
>
> Probably would require a DIP, there is likely code out there
> that depends on always being able to call the base class member
> functions. Ideally, it would also handle base members, but this
> would likely require an even bigger change.
>
> [1]
> https://dlang.org/deprecate.html#Overriding%20without%20override
>
>
> import std.stdio: writeln;
>
> class A
> {
> int x;
> void foo(int x){
> writeln("A");
> }
> }
>
> class B : A
> {
> alias val = A.foo;
>
> //@disable this.x;
> @disable override void foo(int){}
> }
>
> void main() {
> A a = new A;
> B b = new B;
> b.val(1);
> }
This is a bit off-topic in this thread, I started a new one:
https://forum.dlang.org/thread/obqthozmxwzhvrafothw@forum.dlang.org
will discuss the topic there.
More information about the Digitalmars-d
mailing list