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

Fix Issue 20539 - std.conv.to: internal overload conflict for enums with base types that have a catch-all opEquals overload #7378

Closed
wants to merge 1 commit into from

Conversation

ghost
Copy link

@ghost ghost commented Jan 28, 2020

It wasn't easy to decide, which of the two overloads should be choosen: The first one uses the names of the enums, while the second one uses opEquals. I decided on the second one, although the first one would have needed only one template constraint. The reason for this decission is that else the behaviour would differ, depending on the struct being inside the unittest or outside (due to a frame pointer issue).

@ghost ghost requested a review from JackStouffer as a code owner January 28, 2020 09:05
@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @berni44! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Auto-close Bugzilla Severity Description
20539 minor std.conv.to: internal overload conflict for enums with base types that have a catch-all opEquals overload (?)

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 + phobos#7378"

std/conv.d Outdated
// needs to be outside of the unittest, because else a frame pointer issue
// makes it work unintentionally; see next unittest for the version with
// the struct being inside
struct Test20539
Copy link
Contributor

Choose a reason for hiding this comment

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

This struct won‘t have a frame pointer if you declare it as static

Copy link
Author

Choose a reason for hiding this comment

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

I'm not familiar enough with frame pointers yet. Anyway, this is the original test and it doesn't help to modify it, if that's what you want to do. I just realised that the test passed, when I put the struct inside the unittest. Having had a look, why this is, I found a "could not access frame pointer" problem in the overload using parse. So what I did was to add both versions as separate unittests and make sure they both work and do the same.

Copy link
Contributor

Choose a reason for hiding this comment

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

There is no difference between the external or static declaration IIRC (except the visibility of course). This isn't required but this allows to condense bug tests inside one unittest and avoids version(StdUnittest).

Anyway, do as you see fit

Copy link
Author

Choose a reason for hiding this comment

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

Ah, sorry, now I got it. I checked that indeed the bug is there, when I replace the global struct with the static one (for extra security, not because I do not believe you). This also helps to remove this stupid toHash. Thank you!

Copy link
Contributor

Choose a reason for hiding this comment

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

[..] (for extra security, not because I do not believe you).[...]

Better safe than sorry

Thank you!

You're welcome

with base types that have a catch-all opEquals overload (?)
}

// issue 20539
@safe pure unittest
Copy link
Contributor

@MoonlightSentinel MoonlightSentinel Jan 28, 2020

Choose a reason for hiding this comment

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

Is there a good reason to split this into 2 unittest instead of e.g. 2 scopes? That would avoid the duplicate import and unittest declaration

Copy link
Author

Choose a reason for hiding this comment

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

Don't know. It feels a little bit like two different things. The first one guards against the bug, while the second one guards against not introducing a new bug with the bug fix. On the other hand, they are quite similar. Do you mind me leaving it, like it is?

Copy link
Contributor

@MoonlightSentinel MoonlightSentinel Jan 28, 2020

Choose a reason for hiding this comment

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

No, it's mostly a matter of preference (except maybe a negligible difference in compile/run time)

@RazvanN7
Copy link
Collaborator

Closing in favor of: #7749

@RazvanN7 RazvanN7 closed this Jan 19, 2021
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.

3 participants