forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't treat Swift methods named "init" as ObjC ARC init methods. (swi…
…ftlang#2989) Under ARC, methods in the "init" family are considered to have NS_REPLACES_RECEIVER semantics ("consumes" self and returning a value at +1). This is correct for Objective-C "init methods", which are equivalent for Swift's initializers, but almost never correct for any other methods that happen to start with the word "init". Note that Swift still follows all the other ARC conventions, so if you name a method or property, say, "newItemController", the value will be returned at +1. For methods this is probably desirable, but for properties maybe not. We could do something similar for property accessors to make sure they always have the default "no method family" semantics in Objective-C. rdar://problem/25759260
- Loading branch information
1 parent
9ef626f
commit e7fe0ab
Showing
8 changed files
with
176 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
@import Foundation; | ||
#import "swift.h" | ||
|
||
int main() { | ||
@autoreleasepool { | ||
Test *test = [[Test alloc] init]; | ||
id result = [test initAllTheThings]; // CHECK: method called | ||
NSCAssert(result != nil, @"failed to get a return value back"); | ||
result = [test initAllTheThings]; // CHECK: method called | ||
NSCAssert(result != nil, @"failed to get a return value back"); | ||
#if !__has_feature(objc_arc) | ||
[test release]; | ||
#endif | ||
} // CHECK: deinitialized | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// RUN: rm -rf %t && mkdir %t | ||
// RUN: %target-build-swift -c %s -parse-as-library -force-single-frontend-invocation -o %t/swift.o -emit-objc-header-path %t/swift.h | ||
|
||
// RUN: %target-clang -c -Weverything -Werror -Wno-unused-macros -Wno-incomplete-module -fobjc-arc -fmodules %S/Inputs/arc-conventions.m -o %t/main.o -I %t | ||
// RUN: %target-build-swift %t/swift.o %t/main.o -o %t/main | ||
// RUN: %target-run %t/main | FileCheck %S/Inputs/arc-conventions.m | ||
|
||
// RUN: %target-clang -c -Weverything -Werror -Wno-unused-macros -Wno-incomplete-module -fno-objc-arc -fmodules %S/Inputs/arc-conventions.m -o %t/main.o -I %t | ||
// RUN: %target-build-swift %t/swift.o %t/main.o -o %t/main | ||
// RUN: %target-run %t/main | FileCheck %S/Inputs/arc-conventions.m | ||
|
||
// REQUIRES: executable_test | ||
// REQUIRES: objc_interop | ||
|
||
import Foundation | ||
|
||
public class Test: NSObject { | ||
public func initAllTheThings() -> AnyObject { | ||
print("method called") | ||
return "initialized" | ||
} | ||
|
||
deinit { | ||
print("deinitialized \(self)") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters