Skip to content

Fix implicit UnresolvedMemberExpr crash #16785

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

Merged
merged 1 commit into from
May 24, 2018
Merged

Fix implicit UnresolvedMemberExpr crash #16785

merged 1 commit into from
May 24, 2018

Conversation

beccadax
Copy link
Contributor

The isImplicit() flag on an UnresolvedMemberExpr was not carried over to the CallExpr node generated after type checking, which could cause later stages of compilation to use invalid SourceLocs. This change correctly propagates the flag from the UnresolvedMemberExpr to the CallExpr.

(I'm not aware of any way the compiler might currently malfunction due to this bug, but it was happening in new code I was writing.)

The isImplicit flag on an UnresolvedMemberExpr was not carried over to the CallExpr node generated after type checking, which caused later stages of compilation to try to use invalid SourceLocs. This change correctly propagates the flag.
Copy link
Contributor

@xedin xedin left a comment

Choose a reason for hiding this comment

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

Thanks! Could you please add a test to validation-test/compiler_crashers_2_fixed to make sure that it doesn't regress in the future?

@beccadax
Copy link
Contributor Author

beccadax commented May 23, 2018

@xedin I took a look at this, and I don't think there's actually a way to exercise this bug currently. The four places where the compiler creates an UnresolvedMemberExpr all set Implicit to false. The bug caused a crash in modifications I'm making to the compiler, but if my new code gets merged at all, it'll need to wait for an evolution proposal.

So unless there's some hidden way to mark a node as Implicit, or to write a test case that generates an arbitrary AST, I don't know how to write a regression test for this issue.

@xedin
Copy link
Contributor

xedin commented May 24, 2018

It does make sense for me in theory - if the argument to unresolved member is implicit we want to make the call implicit as well, but I'm just having a hard time trying to imagine how this is going to be expressed syntactically, as I see it right now, there is no real reason to have implicit flag for the unresolved member at all...

It seems like this doesn't do any harm if we merge, I just want to understand what is really going on here...

@xedin
Copy link
Contributor

xedin commented May 24, 2018

@swift-ci please test

@xedin
Copy link
Contributor

xedin commented May 24, 2018

@swift-ci please test source compatibility

@beccadax
Copy link
Contributor Author

In my case, I'm synthesizing an initializer call very early, before I know what type it will be used on, and the easiest way to have the compiler infer the type and insert it into the call for me is to create an implicit UnresolvedMemberExpr. I might change my implementation later so that it doesn't create the call until after the type is inferred, but even if I do, we'll have the same issue if we eventually add some synthesis that needs to do this.

If we don't want to support implicit UnresolvedMemberExprs turning into CallExprs, we should add an assertion that trips when you try to do it—preferably as soon as you try to create the node. But if we're not going to forbid it, I think it's pretty clear what the code ought to do, because what we're doing right now reliably builds ASTs that break our invariants.

@xedin
Copy link
Contributor

xedin commented May 24, 2018

Ok, sounds reasonable to me!

@xedin xedin merged commit d501b58 into swiftlang:master May 24, 2018
@beccadax beccadax deleted the explicitly-implicit branch May 24, 2018 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants