When running our unit tests, spotted a weird regression in some conversion to `NSDecimalNumber` that's acting very odd, specifically in Xcode 10.
I reduced the issue to as few lines as possible.
Given the following, seemingly unrelated extension:
extensionDictionarywhereKey == String {
funcvalue<T>(forkey: Key, or: T) -> T {
returnself[key] as? T ?? or
}
}
The following code behaves irregularly (see Example 2). Seems related to inference but not entirely sure how, since the "String" return type is properly explicit; having this wasn't an issue in Xcode 9.
letjson = ["x": "5", "b": "12"]
// ### Example 1 ###// #################// Returns 5, as expected, on all versions of Xcodeprint(#line, NSDecimalNumber(string: json.value(for: "x", or: "0")))
// ### Example 2 ###// #################// Xcode 9.4.1 Swift 4.1: Prints 0.// Xcode 10 GM Swift 4.2: Should be 0, Printing NaN.// Xcode 10 GM Swift 4 mode: Should be 0, Printing NaN.print(#line, NSDecimalNumber(string: json.value(for: "y", or: "0")))
// ### Example 3 ###// #################// Same, but explicitly casting, works correctly on all versions of Xcodeprint(#line, NSDecimalNumber(string: json.value(for: "y", or: "0") asString))
// ### Example 4 ###// #################// Same, when extracting string separately.// Works as expected on all versions of xcodeletvalue = json.value(for: "y", or: "0") // Returns "0" on all versions of Xcodeprint(#line, NSDecimalNumber(string: value))
Appreciate your help!
Shai.
The text was updated successfully, but these errors were encountered:
NSDecimalNumber.init(string:) takes an optional String, so T is getting inferred to String? rather than String in Xcode 10. That matches the dictionary lookup, and then you pass nil to the initializer.
@rudkx, we have another bug for this behavior change, right?
Environment
Xcode 10 GM
Xcode 9.4.1
Additional Detail from JIRA
md5: 215ce993c53eac04883adc50b9b63c05
Issue Description:
When running our unit tests, spotted a weird regression in some conversion to `NSDecimalNumber` that's acting very odd, specifically in Xcode 10.
I reduced the issue to as few lines as possible.
Given the following, seemingly unrelated extension:
The following code behaves irregularly (see Example 2). Seems related to inference but not entirely sure how, since the "String" return type is properly explicit; having this wasn't an issue in Xcode 9.
Appreciate your help!
Shai.
The text was updated successfully, but these errors were encountered: