-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Make bridged String and collection types conform to CVarArg. #3974
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
Conversation
@swift-ci Please smoke test |
@gribozavr Do you mind reviewing? |
How about the Foundation-level bridged types? What about Linux? cc @phausler |
NSLog is omitted since print is preferred. public convenience init(format: String, arguments argList: CVaListPointer) {
let str = CFStringCreateWithFormatAndArguments(kCFAllocatorSystemDefault, nil, format._cfObject, argList)!
self.init(str._swiftObject)
} which defers to CF, but there is no adoption else wise. |
@jrose-apple We can add more conformances easily enough. |
@shahmishal Linux build seems to be broken by an LLVM change:
|
Is this a good idea for String? It's not obvious that converting to an NSString is better than, say, converting to const char*. |
@rjmccall It mirrors our Swift 2 behavior, where strings in |
Alright, fair enough. |
I'm not sure this is the right thing to do. Do people actually expect that String is passed as NSString, or do they prefer Also, please add tests for all new APIs and new usecases (e.g., passing an Array as a vararg). |
@gribozavr This preserves the Swift 2 behavior for Darwin, and this never worked for Linux. I don't see how we can realistically support %s at all without a major redesign of CVarArg, and I doubt that's ever in the cards, since the affected APIs aren't particularly idiomatic to begin with. |
@gribozavr The behavior should also already be exercised by existing tests where I've rolled back |
1a23cb2
to
384c880
Compare
@swift-ci Please smoke test |
Looks like we never really exercised (NS)Array or Dictionary varargs. Added a test for that. |
(Just curious if the linux smoke test is fixed, Mishal cleared the workspace) |
We have a policy in the library that we don't add APIs without directed tests for them. Incidental tests can come and go as those files are refactored. We can't rely on them. |
I understand, but we are trying to do the right thing, and not just preserve the behavior. If we were trying to preserve the behavior, we would not do id-as-Any. |
// CHECK-NEXT: ) { | ||
// CHECK-NEXT: y = z; | ||
// CHECK-NEXT: } | ||
print(NSString(format: "%@ %@", ["x"], ["y": "z"])) |
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.
Please add a better, more descriptive test or at least a comment about what is important about this line. It is not clear what this line is testing.
This allows String, Array, Dictionary, and Set to be passed as variadic arguments to Cocoa APIs like NSLog, NSPredicate, stringWithFormat:, etc. rdar://problem/27651717
384c880
to
7535acc
Compare
@gribozavr OK, I added comments to the tests. |
This allows String, Array, Dictionary, and Set to be passed as variadic arguments to Cocoa APIs like NSLog, NSPredicate, stringWithFormat:, etc. rdar://problem/27651717