Skip to content

[ConstraintSystem] Introduce a fix to allow conversion between inout types #26912

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 2 commits into from
Aug 29, 2019

Conversation

xedin
Copy link
Contributor

@xedin xedin commented Aug 28, 2019

If there is an argument-to-parameter conversion which is associated with
inout parameter, subtyping is now permitted, types have to be identical.

protocol P {}
struct S : P  {}

func foo(_: inout P) {}

var s = S()
foo(&s) // `s` has to be defined as `P` e.g. `var s: P = S()`
        // to be used as an argument to `inout P` parameter.

xedin added 2 commits August 28, 2019 00:56
…` types

If there is an argument-to-parameter conversion which is associated with
`inout` parameter, subtyping is now permitted, types have to be identical.

```swift
protocol P {}
struct S : P  {}

func foo(_: inout P) {}

var s = S()
foo(&s) // `s` has to be defined as `P` e.g. `var s: P = S()`
        // to be used as an argument to `inout P` parameter.
```
…ment/parameter

Since there is no subtyping allowed in `inout` positions, let's
produce a tailored error message and a note about that.
@xedin xedin requested review from DougGregor and hborla August 28, 2019 19:21
@xedin
Copy link
Contributor Author

xedin commented Aug 28, 2019

@swift-ci please smoke test

@xedin
Copy link
Contributor Author

xedin commented Aug 28, 2019

@swift-ci please smoke test Linux platform

@jrose-apple
Copy link
Contributor

This is SR-4078, yeah?

@xedin
Copy link
Contributor Author

xedin commented Aug 28, 2019

@jrose-apple Yeah, that's almost it :) Let me see what else do we need to make that work, the problem is related to bind param constraint for the closure parameter.

@xedin
Copy link
Contributor Author

xedin commented Aug 28, 2019

For posterity, example in SR-4078 is not handled by this fix because types C and D are unrelated and there is no conversion between them. We need a general allow argument-to-parameter conversion mismatch to handle that case.

@xedin
Copy link
Contributor Author

xedin commented Aug 28, 2019

This also removes last special case from diagnoseContextualConversionError.

@xedin xedin merged commit facd27f into swiftlang:master Aug 29, 2019
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