File tree Expand file tree Collapse file tree 3 files changed +20
-4
lines changed Expand file tree Collapse file tree 3 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -8794,10 +8794,22 @@ void ClangImporter::Implementation::importAttributes(
87948794 if (method->isDirectMethod () && !AnyUnavailable) {
87958795 assert (isa<AbstractFunctionDecl>(MappedDecl) &&
87968796 " objc_direct declarations are expected to be an AbstractFunctionDecl" );
8797- MappedDecl->getAttrs ().add (new (C) FinalAttr (/* IsImplicit=*/ true ));
8798- if (auto accessorDecl = dyn_cast<AccessorDecl>(MappedDecl)) {
8799- auto attr = new (C) FinalAttr (/* isImplicit=*/ true );
8800- accessorDecl->getStorage ()->getAttrs ().add (attr);
8797+ if (isa<ConstructorDecl>(MappedDecl)) {
8798+ // TODO: Teach Swift how to directly call these functions.
8799+ auto attr = AvailableAttr::createPlatformAgnostic (
8800+ C,
8801+ " Swift cannot call Objective-C initializers marked with "
8802+ " 'objc_direct'" ,
8803+ /* Rename*/ " " ,
8804+ PlatformAgnosticAvailabilityKind::UnavailableInSwift);
8805+ MappedDecl->getAttrs ().add (attr);
8806+ AnyUnavailable = true ;
8807+ } else {
8808+ MappedDecl->getAttrs ().add (new (C) FinalAttr (/* IsImplicit=*/ true ));
8809+ if (auto accessorDecl = dyn_cast<AccessorDecl>(MappedDecl)) {
8810+ auto attr = new (C) FinalAttr (/* isImplicit=*/ true );
8811+ accessorDecl->getStorage ()->getAttrs ().add (attr);
8812+ }
88018813 }
88028814 }
88038815 }
Original file line number Diff line number Diff line change 22
33// REQUIRES: objc_interop
44
5+ let _ = Bar ( value: 4 ) // expected-error {{'init(value:)' is unavailable in Swift}}
6+ let _ = Bar . init ( value: 5 ) // expected-error {{'init(value:)' is unavailable in Swift}}
57var something = Bar ( ) as AnyObject
68
79something. directProperty = 123 // expected-error {{value of type 'AnyObject' has no member 'directProperty'}}
Original file line number Diff line number Diff line change 11#import < Foundation/Foundation.h>
22
33@interface Bar : NSObject
4+ + (instancetype )barWithValue : (int )value __attribute__((objc_direct));
5+ - (instancetype )initWithValue : (int )value __attribute__((objc_direct));
46@property(direct) int directProperty;
57- (int )objectAtIndexedSubscript : (int )i __attribute__((objc_direct));
68- (void )setObject : (int )obj atIndexedSubscript : (int )i __attribute__((objc_direct));
You can’t perform that action at this time.
0 commit comments