Skip to content

Conversation

@slavapestov
Copy link
Contributor

  • Description: Fixes a crash when applying a solution containing a conditional or forced cast from a Swift collection to the corresponding CF collection type.

  • Origination: The bug has always been there.

  • Risk: Low, the code path in question would have asserted otherwise.

  • Tested: New tests added.

  • Reviewed by: @DougGregor

  • Radar: rdar://problem/32227571

Conditional and forced downcasts enter a constraint that almost
always succeeds; only when applying the solution do we evaluate
the feasability of the cast and determine if it always succeeds,
always fails, or conditionally succeeds. This changes how the
resulting AST is represented and can also emit diagnostics.

If the conditional cast is at this stage determined to always
succeed, we treat it as an unconditional cast, going through
ExprRewriter::coerceToType() to build the AST for the coercion.

However conditional cast constraints don't enter the same
restrictions into the solution as unconditional casts do, so
coerceToType() would fall over if casting a Swift type to a CF
type by first bridging the Swift type to Objective-C.

Get around this by checking for this case explicitly when
lowering a CoerceExpr.

It feels like there's a more fundamental issue here with how
casts are modeled in the constraint solver, but I'm not going
to try understanding that now.

Fixes <rdar://problem/32227571>.
@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@tkremenek tkremenek merged commit b4166a1 into swiftlang:swift-4.0-branch Jun 2, 2017
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