Skip to content

[Sema] Fix crash on bad inheritance clause #17662

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
Jul 2, 2018

Conversation

hamishknight
Copy link
Contributor

When checking for the superclass type, ensure we don't use a protocol composition's superclass type if it doesn't have one.

Resolves SR-8160.

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.

Nice catch!

@@ -956,7 +956,8 @@ void AccessControlChecker::check(Decl *D) {
return false;
Type ty = inherited.getType();
if (ty->is<ProtocolCompositionType>())
ty = ty->getExistentialLayout().superclass;
if (auto superclass = ty->getExistentialLayout().superclass)
ty = superclass;
Copy link
Contributor

Choose a reason for hiding this comment

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

There’s another copy of this check in the UsableFromInlineChecker too. I know that’s bad and I need to clean it up, but can you fix it and add a test?

@@ -0,0 +1,9 @@
// RUN: not %target-typecheck-verify-swift
Copy link
Contributor

Choose a reason for hiding this comment

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

I’d prefer it if you incorporated this test case into an existing file in test/decl/class/ somewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@slavapestov Thanks, I wasn't sure which to favour in this case. I've gone ahead and put the test case in test/inherit/inherit.swift, as that's where the existing "superclass '%0' must appear first in the inheritance clause" diagnostic is currently being tested – I trust this is okay?


// SR-8160
@usableFromInline
class D3 : Any, A { } // expected-error{{superclass 'A' must appear first in the inheritance clause}}{{15-18=}}{{12-12=A, }}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you just change test/decl/inherit/inherit.swift to pass -swift-version 5?

@hamishknight hamishknight force-pushed the bad-inheritance-crash branch from 44703c8 to 40fada7 Compare July 2, 2018 18:38
@DougGregor
Copy link
Member

@swift-ci please smoke test

@slavapestov
Copy link
Contributor

Thanks!

@slavapestov slavapestov merged commit 678e564 into swiftlang:master Jul 2, 2018
@hamishknight hamishknight deleted the bad-inheritance-crash branch July 2, 2018 22:17
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.

3 participants