Skip to content

[Sema] ReturnStmt must be ImplicitConversionExpr aware #21319

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

Conversation

davezarzycki
Copy link
Contributor

Found while doing an unrelated experiment.

Found while doing an unrelated experiment.
@davezarzycki
Copy link
Contributor Author

@swift-ci please smoke test

Copy link
Contributor

@slavapestov slavapestov left a comment

Choose a reason for hiding this comment

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

Test case?

@davezarzycki
Copy link
Contributor Author

Hi @slavapestov – I can't think of a way to generate an implicit conversion outside of my private research branch (which created an implicit conversion expression as a side effect of other changes). Can you think of a way of testing this? Otherwise this just seems like good defensive coding.

@slavapestov
Copy link
Contributor

I'm not sure I agree that this is defensive coding. I tend to delete code whose behavior cannot be observed via the test suite.

@davezarzycki
Copy link
Contributor Author

davezarzycki commented Dec 15, 2018

In theory, I agree with you – but in practice I don't think that is a realistic position. For example, if a user (by accident or on purpose) creates an implicit conversion expression as a part of the return statement, then they can bypass the escape check. That's sucks.

For whatever it may be worth, I've run into this bug before, albeit elsewhere in the code. The problem is that Sema is often unprepared for implicit conversion expressions due to raw isa or dyn_cast usage. I try to fix specific diagnostics as I trip over them, but honestly, a more holistic solution is needed. (Perhaps something like the Type type hierarchy? Where one must use getAs instead of dyn_cast?)

@slavapestov
Copy link
Contributor

Ok, I guess it can’t hurt. Without tears though, we can’t promise not to break the behavior used by your private branch later.

@slavapestov
Copy link
Contributor

Without tests* but tears works too :)

@slavapestov slavapestov merged commit 77dc2e8 into swiftlang:master Dec 17, 2018
@davezarzycki
Copy link
Contributor Author

I'm not afraid of breakage. That's the cost of non-merged code (private or public). I was trying to think of a way to generate a FunctionConversionExpr, but I ran out of time. Thanks for merging this.

@davezarzycki davezarzycki deleted the ice_aware_returnstmt_checking branch December 17, 2018 19:50
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