Skip to content

Conversation

LucianoPAlmeida
Copy link
Contributor

We were skipping diagnostics for cases where the key path type was a function which result was equal the contextual key path value or function result type (key path as function). So in cases where this is the only constraint failing, that would lead type check an incorrect value type, leading to hit an assertion is CSApply.
Example:

extension String {
  var boolean : (Self) throws -> Bool {
    { $0.contains("a") }
  }
  var integer : (Self) throws -> Int {
    { $0.count }
  }
}
let a : [String] = [ "asd", "bcd", "def" ]

_ = a.filter(\.integer) // correctly diagnosed 
_ = a.filter(\.boolean) // diagnostic skipped since (String)-> Bool result Bool is equal contextual type expected 
}

So in this PR we remove this check (in fact we change the check) to make sure this is diagnosed correctly.
Also, a tailored diagnostic on argument mismatch for key path as function.

Resolves SR-14096.

@LucianoPAlmeida LucianoPAlmeida requested a review from xedin March 21, 2021 21:50
@LucianoPAlmeida
Copy link
Contributor Author

@swift-ci Please smoke test

@LucianoPAlmeida
Copy link
Contributor Author

@swift-ci Please smoke test MacOS platform

@LucianoPAlmeida
Copy link
Contributor Author

@swift-ci Please test Windows platform

@LucianoPAlmeida
Copy link
Contributor Author

@swift-ci Please smoke test Linux platform

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.

Great! 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.

2 participants