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 20800 - Error: cannot implicitly convert expression with bad diagnostic #11106

Merged
merged 1 commit into from May 15, 2020

Conversation

RazvanN7
Copy link
Contributor

@RazvanN7 RazvanN7 commented May 8, 2020

CommaExps are used internally in the compiler in a lot of places, but they shouldn't be exposed to the user. Since expression printing is done in the hdrgen file, I added a new checkpoint where all comma expressions are captured and transformed into user readable form. The patch may be incomplete since I tackled only the cases where temporaries are inserted into CommaExp, but we can add to the function more cases as soon as they pop up.

I forgot if error fixing PRs should go to stable or not.

@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 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
20800 normal Error: cannot implicitly convert expression with bad diagnostic.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#11106"

@RazvanN7
Copy link
Contributor Author

RazvanN7 commented May 8, 2020

The C++ interop failures seems unrelated: a wget failure to download.

src/dmd/hdrgen.d Outdated
commaExtract = ce.e2;
else if (auto se = exp.isStructLiteralExp)
commaExtract = se;
expToBuffer(commaExtract, precedence[exp.op], buf, hgs);
Copy link
Contributor

Choose a reason for hiding this comment

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

this seems to segault, with null commaExtract I'm guessing.

Copy link
Contributor Author

@RazvanN7 RazvanN7 May 8, 2020

Choose a reason for hiding this comment

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

Yep, apparently there are some situations in phobos where the compilation of code leads to .toChars on a comma expression, maybe when running with -deps. This might be problematic, we'll see what the tester says.

src/dmd/hdrgen.d Outdated
// CommaExp that contain temporaries inserted via
// `copyToTemp` are usually of the form
// ((T __temp = exp), __tmp)
if (ve && ve.var.storage_class & STC.temp)
Copy link
Contributor

Choose a reason for hiding this comment

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

 // for all other cases, go on the old path
if (!ve || !ve.var.storage_class & STC.temp)
             visit(cast(BinExp)e);
...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated.

src/dmd/hdrgen.d Outdated Show resolved Hide resolved
src/dmd/hdrgen.d Outdated Show resolved Hide resolved
@RazvanN7
Copy link
Contributor Author

ping.

@dlang-bot dlang-bot merged commit b4744b2 into dlang:master May 15, 2020
@UplinkCoder
Copy link
Member

@RazvanN7 This seems to have introduced a regression.

I am still reducing the testcase.

// Asserts are here to easily spot
// missing cases where CommaExp
// are used for other constructs
auto vd = ve.var.isVarDeclaration();
Copy link
Member

Choose a reason for hiding this comment

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

this is not always true!

Copy link
Member

Choose a reason for hiding this comment

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

The comment says you are unsure about this.
In this case don't make it an assert.

Assertion is defined as: a statement that you strongly believe is true.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I am aware that the assert is not always true, but on the other hand I have no clue what other possible forms the CommaExp might have in this particular scenario, therefore, instead of letting a potential segfault with no additional information happen, I opted for an assert that gives you the exact line that is causing problems.

@UplinkCoder
Copy link
Member

UplinkCoder commented Aug 3, 2020 via email

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