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 @@ -8788,10 +8788,22 @@ void ClangImporter::Implementation::importAttributes(
8788
8788
if (method->isDirectMethod () && !AnyUnavailable) {
8789
8789
assert (isa<AbstractFunctionDecl>(MappedDecl) &&
8790
8790
" objc_direct declarations are expected to be an AbstractFunctionDecl" );
8791
- MappedDecl->getAttrs ().add (new (C) FinalAttr (/* IsImplicit=*/ true ));
8792
- if (auto accessorDecl = dyn_cast<AccessorDecl>(MappedDecl)) {
8793
- auto attr = new (C) FinalAttr (/* isImplicit=*/ true );
8794
- accessorDecl->getStorage ()->getAttrs ().add (attr);
8791
+ if (isa<ConstructorDecl>(MappedDecl)) {
8792
+ // TODO: Teach Swift how to directly call these functions.
8793
+ auto attr = AvailableAttr::createPlatformAgnostic (
8794
+ C,
8795
+ " Swift cannot call Objective-C initializers marked with "
8796
+ " 'objc_direct'" ,
8797
+ /* Rename*/ " " ,
8798
+ PlatformAgnosticAvailabilityKind::UnavailableInSwift);
8799
+ MappedDecl->getAttrs ().add (attr);
8800
+ AnyUnavailable = true ;
8801
+ } else {
8802
+ MappedDecl->getAttrs ().add (new (C) FinalAttr (/* IsImplicit=*/ true ));
8803
+ if (auto accessorDecl = dyn_cast<AccessorDecl>(MappedDecl)) {
8804
+ auto attr = new (C) FinalAttr (/* isImplicit=*/ true );
8805
+ accessorDecl->getStorage ()->getAttrs ().add (attr);
8806
+ }
8795
8807
}
8796
8808
}
8797
8809
}
Original file line number Diff line number Diff line change 2
2
3
3
// REQUIRES: objc_interop
4
4
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}}
5
7
var something = Bar ( ) as AnyObject
6
8
7
9
something. directProperty = 123 // expected-error {{value of type 'AnyObject' has no member 'directProperty'}}
Original file line number Diff line number Diff line change 1
1
#import < Foundation/Foundation.h>
2
2
3
3
@interface Bar : NSObject
4
+ + (instancetype )barWithValue : (int )value __attribute__((objc_direct));
5
+ - (instancetype )initWithValue : (int )value __attribute__((objc_direct));
4
6
@property(direct) int directProperty;
5
7
- (int )objectAtIndexedSubscript : (int )i __attribute__((objc_direct));
6
8
- (void )setObject : (int )obj atIndexedSubscript : (int )i __attribute__((objc_direct));
You can’t perform that action at this time.
0 commit comments