Skip to content

Sema: Fix assertion failure when overriding a dynamic method with a final method [4.0] #12001

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

Conversation

slavapestov
Copy link
Contributor

@slavapestov slavapestov commented Sep 19, 2017

  • Description: Fixes an assertion failure when overriding an imported method (or property) with a final method (or property).

  • Scope of the issue: Affects builds with assertions on, like downloadable snapshots.

  • Origination: The underlying bug has been there forever I think, but became easier to hit when overrides of imported methods started to be marked 'dynamic' as part of the Swift 3/4 mix-and-match support.

  • Risk: Low. The change has been in the master branch for a while now with no apparent fallout.

  • Tested: New tests added.

  • Reviewed by: @jrose-apple

@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@slavapestov
Copy link
Contributor Author

@jrose-apple I thought I cherry-picked this into 4.0 already but it looks like I didn't. Mind reviewing?

Copy link
Contributor

@jrose-apple jrose-apple left a comment

Choose a reason for hiding this comment

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

On second thought, I don't think this is correct. If a base method is dynamic, that could mean the author expects it to be replaced at run-time. That means the overriding method has to be dynamic as well.

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - f2f9e2e

@slavapestov
Copy link
Contributor Author

@jrose-apple However, the override in question is explicitly 'final'. I think we should probably disallow final overrides of explicitly-defined 'dynamic' methods altogether, but in this case, the method was implicitly 'dynamic' because it was imported. Since a customer is hitting this issue with a snapshot toolchain, I'd like to check this in as-is. If you feel that perfecting the semantics is more important than the other items on your plate right now, you're welcome to take over.

@slavapestov
Copy link
Contributor Author

@swift-ci Please test Linux

@jrose-apple
Copy link
Contributor

Given that there's a workaround—remove final—I'm inclined to say that it'd be better to only allow this if the dynamic comes from an imported declaration, and to actually produce the warning in other cases. Otherwise, we would have run-time behavior that doesn't match the documented behavior of dynamic. @ematejska or @tkremenek may have a different opinion on the relative priorities here, though.

@slavapestov
Copy link
Contributor Author

Having a workaround is not a good enough reason not to fix a crash. Users don't always know what the workaround is.

@DougGregor
Copy link
Member

Personally, I think avoiding the crash here is the right thing to do for 4.0. LGTM for 4.0

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.

4 participants