Skip to content

Conversation

DougGregor
Copy link
Member

This PR provides default implementations for the three requirements of CustomNSError. The default implementations were actually part of SE-0112, but I forgot to implement them. Further confusing the issue, we thought they had been omitted from the proposal, and therefore required an amendment... which is not the case.

Resolves rdar://problem/23511842.

…uld not find declarations there.

The presence of a generic signature in a XREF means that we should only find the result in a (further-constrained) extension with that generic signature. The absence of a generic signature in a XREF means that we should not find the result in a constrained extension. We implemented the former but not the latter, which would lead to deserialization failures if one had both constrained and unconstrained extensions with the same property in them. Methods/initializers weren’t a problem because the generic signature is (redundantly) encoded in their interface type.
(cherry picked from commit 5775732)
…o the runtime.

Rather than having Sema provide a default implementation of
Error._code when needed, introduce a runtime function to extract the
default code, so that we can provide a default implementation via a
protocol extension in the standard library.

(cherry picked from commit e1545a7)
…nts.

Provide default implementations for all of the CustomNSError requirements:
  * errorDomain: default to the name of the enum type
  * errorCode: default to the same thing "_code" gets, e.g., the enum tag or
    raw value
  * errorUserInfo: default to empty

This makes it significantly easier to customize just one aspect of the
NSError view of an error type, e.g., just the user-info dictionary,
without having to write boilerplate for the others. This was actually
part of SE-0112, but I missed it in the original implementation and we
thought it was an amendment.

Fixes rdar://problem/23511842.

(cherry picked from commit 73e2143)
@DougGregor DougGregor added this to the Swift 3.0 milestone Sep 6, 2016
@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

@jckarter, please review. Most of the work here is in shifting the default implementation of NSError._code from the code synthesis into protocol extensions with a new runtime hook to determine the code for an enum from metadata.

@jckarter
Copy link
Contributor

jckarter commented Sep 6, 2016

Looks good.

@DougGregor
Copy link
Member Author

@tkremenek approved off-line; merging.

@DougGregor DougGregor merged commit 5833f8b into swiftlang:swift-3.0-branch Sep 6, 2016
@DougGregor DougGregor deleted the se-0112-customnserror-defaults-3-0 branch September 6, 2016 20:45
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