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 19099 - Struct with field that has postblit or destructor makes struct assignable #8507

Merged
merged 1 commit into from Apr 9, 2019

Conversation

RazvanN7
Copy link
Contributor

@RazvanN7 RazvanN7 commented Jul 19, 2018

I know this requires a deprecation, it's just that it's a bit complicated to do it.

@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @RazvanN7! 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 annotated coverage diff directly on GitHub with CodeCov's browser extension
  • 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
19099 normal Struct with field that has postblit or destructor makes struct assignable

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#8507"

@RazvanN7 RazvanN7 changed the title Fix Issue 19099 - Struct with field that has postblit or destructor makes struct assignable [WIP] Fix Issue 19099 - Struct with field that has postblit or destructor makes struct assignable Jul 19, 2018
@dlang-bot dlang-bot added the WIP Work In Progress - not ready for review or pulling label Jul 19, 2018
@RazvanN7 RazvanN7 changed the title [WIP] Fix Issue 19099 - Struct with field that has postblit or destructor makes struct assignable Fix Issue 19099 - Struct with field that has postblit or destructor makes struct assignable Jul 19, 2018
@RazvanN7 RazvanN7 removed the WIP Work In Progress - not ready for review or pulling label Jul 20, 2018
struct B
{
this(this) {}
~this() {}
Copy link
Member

Choose a reason for hiding this comment

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

Probably a good idea to add a tests for C (only dtor) and D (only postblit)?

@WalterBright
Copy link
Member

@RazvanN7 Please add a link to the PR to the bugzilla entry. Otherwise, someone will waste time fixing a bug that has already been fixed. This has happened.

I already added it for this one.

src/dmd/mtype.d Outdated Show resolved Hide resolved
Copy link
Member

@WalterBright WalterBright left a comment

Choose a reason for hiding this comment

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

see my comments.

@RazvanN7
Copy link
Contributor Author

RazvanN7 commented Apr 5, 2019

After my first noobish attempt, I gave this another look and found the real problem. When the postblit is generated for a struct, opAssign is also generated; opAssign is generated only if all the members are assignable; the TypeStruct isAssignable function tests if each field is assignable, however it has a hack for anonymous unions members so that if a member is assignable, the union is considered assignable; to implement this, it is checked if fields have the same offset, however, the size for the struct is determined on in the second semantic step (right after semantic 1 finished), therefore at this point, all fields have offset 0 => this bug. To fix this, I called the determineSize function in isAssignable so that the offsets are correct. This should be the correct course of action, as at the time of opAssign generation all fields are already semantically analyzed.

ping @WalterBright @andralex

@RazvanN7
Copy link
Contributor Author

RazvanN7 commented Apr 9, 2019

cc @thewilsonator

@dlang-bot dlang-bot merged commit ce21f1d into dlang:master Apr 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants