Open
Description
Previous ID | SR-8951 |
Radar | None |
Original Reporter | benasher44 (JIRA User) |
Type | Bug |
Environment
macOS 10.13.6
Swift 4.2
Xcode 10.0 (10A255)
Additional Detail from JIRA
Votes | 0 |
Component/s | Compiler |
Labels | Bug, 4.0Regression |
Assignee | None |
Priority | Medium |
md5: d8d439d344924ff347951eb1e0ab863e
Issue Description:
I went to add an extension to RangeReplaceableCollection
today, and some tests started failing because some String
s in our codebase started behaving funny. It turns out that a flatMap
picked a different init
without warning, which changed behavior and failed our tests.
Consider the following code:
import Foundation
//extension RangeReplaceableCollection {
// public init(minimumCapacity: Int) {
// self.init()
// self.reserveCapacity(minimumCapacity)
// }
//}
let num: Int? = 100
let str = num.flatMap(String.init) ?? ""
print("|\(str)|")
As is, this code prints |100|, but if you un-comment the extension, it prints ||. I would expect uncommenting the extension to cause a compiler error because that would make String.init
ambiguous.