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 17307 - [REG2.072.0][ICE] TypeBasic::implicitConvTo #7199

Merged
merged 1 commit into from
Oct 11, 2017
Merged

Fix Issue 17307 - [REG2.072.0][ICE] TypeBasic::implicitConvTo #7199

merged 1 commit into from
Oct 11, 2017

Conversation

JinShil
Copy link
Contributor

@JinShil JinShil commented Oct 8, 2017

This fixes the ICE, but there may still be an underlying problem with the semantics.

Output for...

struct { enum bitsPerWord = size_t; }

void main()
{ }

... is now...

main.d(1): Error: anonymous struct can only be a part of an aggregate, not module main
main.d(1): Error: cannot interpret ulong at compile time

I'd be happy to add a test case, but I first need confirmation that that is the expected output.

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @JinShil! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.

Some tips to help speed things up:

  • smaller, focused PRs are easier to review than big ones

  • try not to mix up refactoring or style changes with bug fixes or feature enhancements

  • provide helpful commit messages explaining the rationale behind each change

Bear in mind that large or tricky changes may require multiple rounds of review and revision.

Please see CONTRIBUTING.md for more information.

Bugzilla references

Auto-close Bugzilla Description
17307 [REG2.072.0][ICE] TypeBasic::implicitConvTo: After error "anonymous struct can only be a part of an aggregate"

@PetarKirov
Copy link
Member

PetarKirov commented Oct 8, 2017

The error message sounds correct to me, as D's grammar doesn't support neither inline typedefs, nor inline struct variables (declaring a structure and variables of that type in a single declaration). So really there's another way to use anonymous structs or unions in D, except as members of other aggregates.

@rainers
Copy link
Member

rainers commented Oct 8, 2017

I think this is fighting the symptoms, but a type pointer null will cause a lot of trouble elsewhere, too. I think a better fix might be to not stop semantic analysis if "anonymous struct can only be a part of an aggregate" has been detected, i.e. remove the return here: https://github.com/dlang/dmd/blob/stable/src/ddmd/attrib.d#L805

@rainers
Copy link
Member

rainers commented Oct 8, 2017

You should also add the test somwhere to the fail_compilation test suite.

@JinShil
Copy link
Contributor Author

JinShil commented Oct 9, 2017

I think a better fix might be to not stop semantic analysis if "anonymous struct can only be a part of an aggregate" has been detected, i.e. remove the return here: https://github.com/dlang/dmd/blob/stable/src/ddmd/attrib.d#L805

Done

You should also add the test somwhere to the fail_compilation test suite.

Done

Copy link
Member

@rainers rainers left a comment

Choose a reason for hiding this comment

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

Thanks.

It's a bit annoying that code coverage marks this PR as bad as it just removes a line. The percentage drops indeed, but the number of uncovered lines stays the same.

@WalterBright
Copy link
Member

The theory of dealing with compilation errors is not to attempt to recover from them, but to 'poison' anything that depends on an AST node that has an error in it. This is the rationale of TypeError and similar in the compiler. Recovery attempts (i.e. guess what the user intended and attempt to repair the error) rarely work out well, and result in cascaded misleading error messages.

This PR is trying to recover from the error by putting the erroneous AnonDeclaration back into a known state, which later passes depend on.

A fix more in keeping with the error design in the compiler is to 'poison' the AnonDeclaration node by setting AnonDeclaration.errors. Then, when the node is used, errors is checked and the error is propagated instead. Making this work in the most effective manner is to put the errors check inside the various include() member functions, having them return null if errors is set.

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.

Set errors instead, per my other comment.

@WalterBright
Copy link
Member

@JinShil when submitting a bug fix PR, please note in bugzilla the PR url. This helps prevent someone else from wasting their time preparing a fix for an issue if there already is an outstanding PR. Thanks!

(I already took care of it for this one.)

@JinShil
Copy link
Contributor Author

JinShil commented Oct 10, 2017

A fix more in keeping with the error design in the compiler is to 'poison' the AnonDeclaration node by setting AnonDeclaration.errors. Then, when the node is used, errors is checked and the error is propagated instead. Making this work in the most effective manner is to put the errors check inside the various include() member functions, having them return null if errors is set.

Done. I hope my changes are what you intended.

@@ -55,6 +55,9 @@ extern (C++) abstract class AttribDeclaration : Dsymbol

Dsymbols* include(Scope* sc, ScopeDsymbol sds)
Copy link
Member

Choose a reason for hiding this comment

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

Also need to do the overrides of include().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@WalterBright
Copy link
Member

Good! Well done.

@WalterBright WalterBright merged commit bf5a755 into dlang:stable Oct 11, 2017
tramker pushed a commit to tramker/dmd that referenced this pull request Feb 8, 2018
Fix Issue 17307 - [REG2.072.0][ICE] TypeBasic::implicitConvTo

cherry-picked-by: Martin Krejcirik <mk@krej.cz>
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.

5 participants