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 20549 - Initialization with a tuple of a module symbol refe… #10750

Merged
merged 2 commits into from Jan 31, 2020

Conversation

BorisCarvajal
Copy link
Member

…rencing itself could crash dmd

@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @BorisCarvajal! 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
20549 normal Initialization with a tuple of a module symbol referencing itself could crash dmd

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 "stable + dmd#10750"

Copy link
Contributor

@thewilsonator thewilsonator left a comment

Choose a reason for hiding this comment

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

I agree it shuldn't crash, but is there any reason to disallow it?

src/dmd/dsymbolsem.d Outdated Show resolved Hide resolved
@BorisCarvajal
Copy link
Member Author

BorisCarvajal commented Jan 31, 2020

I'm just disallowing it from that block, that piece of code seems to be there just to get some extra info about postblit/copy constructor in structs, the initialization works fine and the error is the expected output.
Well, I'm not totally sure.
Maybe the correct fix is just to run the if only for structs.

@thewilsonator
Copy link
Contributor

Fair enough, I suppose if someone wants to use it in that way they will open a bug report about it.

@MoonlightSentinel
Copy link
Contributor

This seems to be a hackish workaround. I would prefer to have a look before this is merged...

Copy link
Contributor

@MoonlightSentinel MoonlightSentinel left a comment

Choose a reason for hiding this comment

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

This could use further review

@dlang-bot dlang-bot merged commit 7fefd61 into dlang:stable Jan 31, 2020
if (ei)
// Bug 20549. Don't try this on modules or packages, syntaxCopy
// could crash (inf. recursion) on a mod/pkg referencing itself
if (ei && (ei.exp.op != TOK.scope_ ? true : !(cast(ScopeExp)ei.exp).sds.isPackage()))
Copy link
Member

Choose a reason for hiding this comment

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

|| is a thing too

ei.exp.op != TOK.scope_ || !(cast(ScopeExp)ei.exp).sds.isPackage())

Copy link
Member Author

Choose a reason for hiding this comment

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

My initial version was a parenthesesless with the ternary, for some reason I put the parens before committing, but yeah with them that alternative is absolutely more clean.

@wilzbach
Copy link
Member

This seems to be a hackish workaround. I would prefer to have a look before this is merged...

Agreed. Yet another too eager merge :/

@@ -0,0 +1,5 @@
module test;
Copy link
Contributor

Choose a reason for hiding this comment

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

This should have a TEST_OUTPUT section checking for the correct error message.

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 error message is not the thing to be tested.

Copy link
Contributor

Choose a reason for hiding this comment

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

All test that yield error messages should provide that section because its assumed to be silent otherwise. IIRC this is currently not enforced but will become the default once the remaining tests are updated.

Copy link
Member

Choose a reason for hiding this comment

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

IIRC there were only a handful of tests left as they had a massive list of output, maybe they can be ignored manually?

Copy link
Member

Choose a reason for hiding this comment

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

The point is not only to test the error message, but to make sure the assumptions made by the test hold.

Someone sometime later could change some code in DMD, and lead to the test case pass for the wrong reason
(here "passing" == "not compiling"). That could potentially mean the regression could sneak back because something unrelated in the test now fails.
And while it's unlikely with a 3 lines test, it's still a good habit to have. (On a side note, there also was some effort to have TEST_OUTPUT set as required IIRC).

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry for not knowing all the test rules, there should be a test category for "not crash only".
Now thinking I should have written the code in a trait-compiles on the compilable category, much clever.

Copy link
Contributor

Choose a reason for hiding this comment

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

fail_compilation is fine as it assigns a module to an enum.
Anyway, I assume the explanation concerning is in the tests README.md (or should be added there if it is missing)

@BorisCarvajal
Copy link
Member Author

Yeah its hacky and as I said before, "Maybe the correct fix is just to run the if only for structs.", that code looks like it was meant to be used only on a struct but I didn't know and I didn't want to keep investigating. Always someone can apply the proper fix in the future.

@MoonlightSentinel
Copy link
Contributor

That's fine, nobody forces you to continue your work on a certain task. Someone else can pick up this PR and maybe find at a better solution.
The point is that questionable fixes should not be merged easily because they tend to accumulate over time ...

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