Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give D2-style operator overload priority over D1-style, reinstate the latter's deprecation #10725

Merged
merged 2 commits into from
Jan 15, 2020

Conversation

Geod24
Copy link
Member

@Geod24 Geod24 commented Jan 15, 2020

It was merged accidentally, see #10716 (comment)

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @Geod24!

Bugzilla references

Auto-close Bugzilla Severity Description
18665 enhancement Deprecate Undocumented Operator Overloads

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub fetch digger
dub run digger -- build "master + dmd#10725"

See the changelog entry for the full rationale.
TL;DR: It's more user friendly and sensical
(although they were good reasons not to do it in the first place as well).
@Geod24 Geod24 changed the title WIP: Reinstate deprecation for D1 operator overloads Reinstate deprecation for D1 operator overloads Jan 15, 2020
@Geod24 Geod24 changed the title Reinstate deprecation for D1 operator overloads Give D2-style operator overload priority over D1-style, reinstate the later's deprecatoin Jan 15, 2020
@Geod24
Copy link
Member Author

Geod24 commented Jan 15, 2020

@don-clugston-sociomantic : Can you review ? Hope this will suit you. The only downside I can see is that the following is not supported:

class DontDoThat {
   int opAdd(int) {}
   int opBinary(string op)(int) if (op == "-") { return 0; }
}

void main ()
{
     scope o = new DontDoThat();
    // This will now error out because the compiler does not consider `opAdd`,
    // as it sees an `opBinary`... I don't think that's a big deal but you tell us.
     o + 42;
}

@Geod24 Geod24 changed the title Give D2-style operator overload priority over D1-style, reinstate the later's deprecatoin Give D2-style operator overload priority over D1-style, reinstate the later's deprecation Jan 15, 2020
@don-clugston-sociomantic
Copy link
Contributor

That looks great! From there, we can mark the D1 names as deprecated in our own code, so that we can flush out existing uses. Nice solution.

@don-clugston-sociomantic
Copy link
Contributor

The only downside I can see is that the following is not supported:

class DontDoThat {
   int opAdd(int) {}
   int opBinary(string op)(int) if (op == "-") { return 0; }
}

void main ()
{
     scope o = new DontDoThat();
    // This will now error out because the compiler does not consider `opAdd`,
    // as it sees an `opBinary`... I don't think that's a big deal but you tell us.
     o + 42;
}

I think that's good behaviour actually. Any code affected by that deserves to be broken.

@atilaneves atilaneves changed the title Give D2-style operator overload priority over D1-style, reinstate the later's deprecation Give D2-style operator overload priority over D1-style, reinstate the latter's deprecation Jan 15, 2020
Copy link
Contributor

@don-clugston-sociomantic don-clugston-sociomantic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. This is a good solution.

@dlang-bot dlang-bot merged commit 97c2c62 into dlang:master Jan 15, 2020
@Geod24 Geod24 deleted the revert-10716-revert-10130-depD1ops branch January 15, 2020 14:53
@schveiguy
Copy link
Member

Nice! Note that I found even an alias works, and should be exactly equivalent to the original (no inlining necessary):

class C
{
    int *opIn_r(int x) { return null; }
    alias opBinaryRight(string s : "in") = opIn_r;
}

This should not error now, I would think (it did not error if the virtual call was not named opIn_r).

@don-clugston-sociomantic
Copy link
Contributor

Can we get this merged into stable, please?

@Geod24
Copy link
Member Author

Geod24 commented Feb 3, 2020

#10760

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants