Witness report for Strideable.distance (to: A) & # 8594; A.Stride according to Int64 + 124 - what does this error message mean?
I have a bunch of crash logs from iTunesConnect for my ios swift app with the top of the stacktrace displaying an error message:
protocol for Strideable.distance (to: A) -> A.Stride according to Int64 + 124
This comes from a harmless line in my code that looks like this:
if (var1 - var2 > MyClass.THRESHOLD) {
// Do something
}
var1
and are var2
declared as a type Int64
, and THRESHOLD
:
static let THRESHOLD = 900 * 1000
I have a hunch that this is because it has THRESHOLD
not been declared as Int64
, although I still have no hypothesis on how this might cause the problem. Also, the error is not reproducible, so I cannot confirm.
Any help as to what this error message means and what could be the problem here?
source to share
A mixed type comparison may be the cause of the problem. The subtraction operator is inferred from the types of its operands as
@available(swift, deprecated: 3.0, obsoleted: 4.0, message: "Mixed-type subtraction is deprecated. Please use explicit type conversion.")
public func -<T>(lhs: T, rhs: T) -> T.Stride where T : SignedInteger
with T == Int64
and T.Stride == Int
. Your code will raise a warning with Xcode 8.3.2:
let THRESHOLD = 900 * 1000
let var1: Int64 = 0x100000000
let var2: Int64 = 0
// warning: '-' is deprecated: Mixed-type subtraction is deprecated. Please use explicit type conversion.
if var1 - var2 > THRESHOLD {
print("foo")
} else {
print("bar")
}
On a 32-bit device, the difference may be too big for Int
and the above example will be interrupted by a runtime error
* thread # 1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code = EXC_I386_INVOP, subcode = 0x0) frame # 0: 0x0223d428 libswiftCore.dylib`protocol witness for Swift.Strideable.distance (to: A) -> A.Stride in conformance Swift.Int64: Swift.Strideable in Swift + 72
The solution is to explicitly transform the right side:
if var1 - var2 > Int64(THRESHOLD) { ... }
source to share