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

[Typechecker] Relax existential to concrete type cast check for non-final classes #26971

Merged
merged 4 commits into from Sep 3, 2019
Merged

[Typechecker] Relax existential to concrete type cast check for non-final classes #26971

merged 4 commits into from Sep 3, 2019

Conversation

theblixguy
Copy link
Collaborator

Relax existential to concrete type cast check for classes, otherwise we have emit a warning for the code below:

protocol MyProtocol {}
class Superclass {} // Superclass does not conform to MyProtocol
class Subclass: Superclass, MyProtocol {} // Subclass conforms to MyProtocol

func f(_ x: MyProtocol) { // Expects existential of type MyProtocol
  if let y = x as? Superclass { // Superclass is 'unrelated', but cast still succeeds
    print(y)
  }
}

f(Subclass())

Resolves SR-11402.

Copy link
Collaborator

@harlanhaskins harlanhaskins left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the quick fix @theblixguy!

@theblixguy
Copy link
Collaborator Author

@swift-ci please smoke test

@theblixguy
Copy link
Collaborator Author

@swift-ci please smoke test

@theblixguy theblixguy changed the title [Typechecker] Relax existential to concrete type cast check for classes [Typechecker] Relax existential to concrete type cast check for non-final classes Aug 30, 2019
@theblixguy
Copy link
Collaborator Author

@swift-ci please smoke test

@theblixguy
Copy link
Collaborator Author

@swift-ci please smoke test

Copy link
Collaborator

@harlanhaskins harlanhaskins left a comment

Choose a reason for hiding this comment

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

This LGTM! Thanks again @theblixguy!

Copy link
Member

@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.

Perfect, thank you!

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.

None yet

4 participants