-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[Sema] @objc functions shall not have typed throw #81054
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
Changes from 5 commits
b664a40
cf15d46
813aae6
3afddfa
841b583
ea05881
05644c1
5af6e5e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2569,12 +2569,12 @@ InterfaceTypeRequest::evaluate(Evaluator &eval, ValueDecl *D) const { | |
| ProtocolDecl *errorProto = Context.getErrorDecl(); | ||
| if (thrownTy && !thrownTy->hasError() && errorProto) { | ||
| Type thrownTyInContext = AFD->mapTypeIntoContext(thrownTy); | ||
| if (!checkConformance(thrownTyInContext, errorProto)) { | ||
| SourceLoc loc; | ||
| if (auto thrownTypeRepr = AFD->getThrownTypeRepr()) | ||
| loc = thrownTypeRepr->getLoc(); | ||
| else | ||
| loc = AFD->getLoc(); | ||
| auto thrownTypeRepr = AFD->getThrownTypeRepr(); | ||
| SourceLoc loc = | ||
| (thrownTypeRepr) ? thrownTypeRepr->getLoc() : AFD->getLoc(); | ||
| if (AFD->getAttrs().hasAttribute<ObjCAttr>()) { | ||
| Context.Diags.diagnose(loc, diag::typed_thrown_in_objc_forbidden); | ||
|
||
| } else if (!checkConformance(thrownTyInContext, errorProto)) { | ||
| Context.Diags.diagnose(loc, diag::thrown_type_not_error, thrownTy); | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -216,3 +216,13 @@ struct NotAnError<T> {} | |
|
|
||
| func badThrowingFunctionType<T>(_: () throws(NotAnError<T>) -> ()) {} | ||
| // expected-error@-1 {{thrown type 'NotAnError<T>' does not conform to the 'Error' protocol}} | ||
|
|
||
| enum ObjCError: Int, Error { | ||
| case Others | ||
| } | ||
|
|
||
| import Foundation | ||
| @objc class ObjCClass: NSObject { | ||
| @objc func objcTypedThrow() throws(ObjCError) -> () {} | ||
|
||
| // expected-error@-1 {{@objc functions cannot have typed throw}} | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would probably word this more similarly to the other diagnostics emitted by
isRepresentableInLanguage(), such asnot_objc_function_async:Note that this will insert a string like "instance method" where
%kindonly0is written—you'll need to pass the decl into thediagnose()call, though.(There are other ways you might word this—if you'd like, take a look around at a few other diagnostics in this method and see if there's something you like better.)