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 18719 - Doubly-called constructor against member when using forwarding constructors #8167

Merged
merged 1 commit into from
Apr 16, 2018

Conversation

RazvanN7
Copy link
Contributor

Whenever a call expression to a constructor is encountered, update the scope ctorflow so that it is known that all member fields have been initialized

@dlang-bot
Copy link
Contributor

dlang-bot commented Apr 12, 2018

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
18719 normal Doubly-called constructor against member when using forwarding constructors

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

@RazvanN7
Copy link
Contributor Author

Blocked by : dlang/phobos#6448

@CyberShadow
Copy link
Member

I don't know how many times this needs to be said: If your compiler change breaks Phobos, it likely breaks user code. There needs to be at least some proof of effort that this couldn't be done as a deprecation, and there must be a changelog entry with rationale, examples, and steps for fixing user code.

// If `exp` is a call expression to another constructor
// then it means that all struct/class fields will be
// initialized after this call.
for (size_t i = 0; i < sc.ctorflow.fieldinit.length; i++)
Copy link
Member

Choose a reason for hiding this comment

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

foreach ?

@@ -3271,11 +3271,22 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
}
else
{
// `this` call expression must be inside a
// constructor
if (!ad || !sc.func.isCtorDeclaration())
{
exp.error("constructor call must be in a constructor");
Copy link
Member

Choose a reason for hiding this comment

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

does this ever happen ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it might if one is noobish enough

@RazvanN7
Copy link
Contributor Author

@CyberShadow I transformed the error into a deprecation and added a changelog entry.

}
---

However, issue 18719 ( https://issues.dlang.org/show_bug.cgi?id=18719 ) shows
Copy link
Member

Choose a reason for hiding this comment

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

$(LINK2 https://issues.dlang.org/show_bug.cgi?id=18719, issue 18719)

Copy link
Member

Choose a reason for hiding this comment

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

Better yet: $(BUGZILLA 18719)

@@ -29,6 +29,7 @@ enum CSX : ubyte
return_ = 0x20, /// seen a return statement
any_ctor = 0x40, /// either this() or super() was called
halt = 0x80, /// assert(0)
deprecate_18719 = 0x100, // issue deprecation for Issue 18719 - delete when deprecation period is over
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we call it deprecate so it can be used for other deprecations?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is highly unlikely that this is going to be used for something else. even so, the modification can be done when it is necessary

Copy link
Contributor

Choose a reason for hiding this comment

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

@RazvanN7 RazvanN7 force-pushed the Issue_18719 branch 2 times, most recently from 387f0fc to 9543f5d Compare April 16, 2018 13:32
@dlang-bot dlang-bot merged commit ebecaf9 into dlang:master Apr 16, 2018
@wilzbach
Copy link
Member

This introduced a regression as it only checks whether a this() call is present, but not what the this call actually does. For example, it is totally valid to have a this constructor that does nothing..

https://issues.dlang.org/show_bug.cgi?id=19030

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.

7 participants