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 19022 - CTorFlow: Show the line of the duplicated initialization for const/immutable fields #8399

Merged
merged 1 commit into from Jun 27, 2018

Conversation

wilzbach
Copy link
Member

I wasn't sure on the best way to save this information.
Is it okay to use an additional array here?

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @wilzbach!

Bugzilla references

Auto-close Bugzilla Severity Description
19022 enhancement CTorFlow: Show the line of the duplicated initialization for const/immutable fields

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

@wilzbach wilzbach added the WIP Work In Progress - not ready for review or pulling label Jun 24, 2018
@wilzbach wilzbach changed the title Fix Issue 19022 - CTorFlow: Show the line of the duplicated initialization for const/immutable fields [WIP] Fix Issue 19022 - CTorFlow: Show the line of the duplicated initialization for const/immutable fields Jun 24, 2018

Returns: A copy of the input array.
*/
extern (D) static auto arraydup(T)(T[] s) nothrow
Copy link
Contributor

@JinShil JinShil Jun 24, 2018

Choose a reason for hiding this comment

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

const scope T[] maybe?

Copy link
Contributor

Choose a reason for hiding this comment

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

  • static is not necessary
  • please don’t use auto for the return type
  • please use standard D naming conventions
  • can this be made pure?

Copy link
Member Author

Choose a reason for hiding this comment

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

FYI: I copied the declaration of the previous xarraydup, hence the name.

can this be made pure?

Yes, if the pureMalloc declarations are added. However, I don't see a big to do this in this PR as xarraydup isn't pure either, DMD can't take much advantage of purity anyhow and this PR still has other, real issues.


Returns: A copy of the input array.
*/
extern (D) static auto arraydup(T)(T[] s) nothrow
Copy link
Contributor

Choose a reason for hiding this comment

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

  • static is not necessary
  • please don’t use auto for the return type
  • please use standard D naming conventions
  • can this be made pure?

*/
extern (D) static auto arraydup(T)(T[] s) nothrow
{
if (s !is null)
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest an early return.

@wilzbach wilzbach force-pushed the fix-19022 branch 3 times, most recently from 25e7d34 to 448f3b6 Compare June 27, 2018 03:13
@wilzbach wilzbach removed the WIP Work In Progress - not ready for review or pulling label Jun 27, 2018
@wilzbach
Copy link
Member Author

Instead of using to separate arrays, I now merged them (CSX + Location info) into one.

@wilzbach wilzbach changed the title [WIP] Fix Issue 19022 - CTorFlow: Show the line of the duplicated initialization for const/immutable fields Fix Issue 19022 - CTorFlow: Show the line of the duplicated initialization for const/immutable fields Jun 27, 2018
fail_compilation/fail9665a.d(45): Error: immutable field `v` initialized multiple times
fail_compilation/fail9665a.d(44): Previous initialization is here.
fail_compilation/fail9665a.d(55): Error: immutable field `v` initialized multiple times
Previous initialization is here.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is missing file and line information as far as I can see.

@wilzbach wilzbach force-pushed the fix-19022 branch 2 times, most recently from 9b5045f to 24e4a0c Compare June 27, 2018 09:58
@wilzbach wilzbach added the WIP Work In Progress - not ready for review or pulling label Jun 27, 2018
@wilzbach wilzbach force-pushed the fix-19022 branch 3 times, most recently from dbbd592 to e7cbc9d Compare June 27, 2018 11:12
@@ -127,9 +129,14 @@ bool modifyFieldVar(Loc loc, Scope* sc, VarDeclaration var, Expression e1)
// dmd.ctorflow.CSX enum.
// @@@DEPRECATED_2019-01@@@.
if (fi & CSX.deprecate_18719)
.deprecation(loc, "%s field `%s` initialized multiple times", modStr, var.toChars());
{
.deprecation(loc, "%s field `%s` was initialized in a previous constructor call", modStr, var.toChars());
Copy link
Member Author

Choose a reason for hiding this comment

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

The fix for 18719 is too aggressive and only checks whether a this call is present.
Hence, there's no way to get the line number of the field with the previous initialization (there might be none after all).
See also: https://issues.dlang.org/show_bug.cgi?id=19030

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok. Perhaps an intermediate solution can be implemented. For example, printing the line number of the constructor call if there is no line number for the field.

Copy link
Member Author

Choose a reason for hiding this comment

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

The problem is the as of now we don't have this information. It currently triggers this deprecation whenever a this(...) call has been observed and a immutable field is modified. This means if there are three constructors it could be any of the two other.

@wilzbach wilzbach removed the WIP Work In Progress - not ready for review or pulling label Jun 27, 2018
@dlang-bot dlang-bot merged commit 033d324 into dlang:master Jun 27, 2018
@wilzbach wilzbach deleted the fix-19022 branch July 1, 2018 23:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants