Skip to content

Sema: NSValue-to-value-type casts are failable and should be checked. #6774

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
Jan 13, 2017

Conversation

jckarter
Copy link
Contributor

In Swift 4 mode, no longer consider e.g. 'nsNumber as Int' or 'nsValue as NSRange' to be valid coercions. This would break compatibility with Swift 3, so in Swift 3 mode, accept the coercion, but also accept a checked cast without a warning, and raise a migration warning about the unchecked coercion.

@jckarter
Copy link
Contributor Author

@swift-ci Please test

@jckarter
Copy link
Contributor Author

@DougGregor and @rudkx, do you mind reviewing this?

Copy link
Contributor

@rudkx rudkx left a comment

Choose a reason for hiding this comment

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

Everything else LGTM.

@@ -5394,6 +5411,8 @@ Expr *ExprRewriter::buildObjCBridgeExpr(Expr *expr, Type toType,
ConstraintLocatorBuilder locator) {
Type fromType = cs.getType(expr);

// Warn in Swift 3 mode if a coercion goes from
Copy link
Contributor

Choose a reason for hiding this comment

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

stray comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, thanks Mark!

In Swift 4 mode, no longer consider e.g. 'nsNumber as Int' or 'nsValue as NSRange' to be valid coercions. This would break compatibility with Swift 3, so in Swift 3 mode, accept the coercion, but *also* accept a checked cast without a warning, and raise a migration warning about the unchecked coercion.
@jckarter jckarter force-pushed the nsnumber-conditional-casting branch from c258bb1 to c03371a Compare January 13, 2017 21:53
@jckarter
Copy link
Contributor Author

@swift-ci Please smoke test and merge

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