Skip to content

[Diagnostics] Extend the AllowInOutConversion fix to cover inout attribute mismatches in function types. #27043

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
Sep 5, 2019

Conversation

hborla
Copy link
Member

@hborla hborla commented Sep 5, 2019

This improves the diagnostic in cases where we have argument-to-parameter conversion failures or contextual type mismatches due to inout attribute mismatches.

Example:

func foo<T>(_ f : (inout T) -> Void) {}
foo({ (x : Int) -> Void in return })

Previously, we would diagnose cannot convert value of type '(inout Int) -> Void' to expected argument type '(inout _) -> Void'. Now, we diagnose cannot convert value of type '(Int) -> Void' to expected argument type '(inout Int) -> Void'.

@hborla hborla requested a review from xedin September 5, 2019 20:31
@hborla
Copy link
Member Author

hborla commented Sep 5, 2019

@swift-ci please smoke test

@@ -1289,7 +1289,7 @@ class IgnoreContextualType : public ContextualMismatch {
};

/// If this is an argument-to-parameter conversion which is associated with
/// `inout` parameter, subtyping is now permitted, types have to
/// `inout` parameter, subtyping is not permitted, types have to
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you! :)

Copy link
Contributor

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

Looks great!

…tribute

mismatches in function types.

This improves the diagnostic in cases where we have argument-to-parameter
conversion failures or contextual type mismatches due to inout attribute
mismatches.
@hborla hborla force-pushed the inout-attr-mismatch-diag branch from f0213b0 to 7277f4f Compare September 5, 2019 21:17
@hborla
Copy link
Member Author

hborla commented Sep 5, 2019

@swift-ci please smoke test

return {
x in ()
}
}
var _: (inout X) -> () = makef() // expected-error{{generic parameter 'T' could not be inferred}}
var _: (inout X) -> () = makef() // expected-error{{cannot convert value of type '(X) -> ()' to specified type '(inout X) -> ()'}}
Copy link
Contributor

Choose a reason for hiding this comment

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

Much better!

@hborla hborla merged commit d1f139c into swiftlang:master Sep 5, 2019
@hborla hborla deleted the inout-attr-mismatch-diag branch September 5, 2019 22:14
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