Closed AlexZd closed 4 years ago
This is probably a Swift issue.
If we change the value()
function to:
public func value<T>(_ value: Any?) throws -> T {
print(T.self as? Optional<Int>.Type) // Cast type as Int?
guard let value: T = value as? T else {
throw MachError(.aborted)
}
return value
}
in the debugger we will see this:
Optional(Swift.Optional<Swift.Int>)
Which means that the cast succeed.
But if we change the function to:
public func value<T>(_ value: Any?) throws -> T {
print(T.self as? Int.Type) // Cast type as Int
guard let value: T = value as? T else {
throw MachError(.aborted)
}
return value
}
in the debugger we will see nil.
So, the T
type is not Int
but Int?
(since IUO are Optionals in swift 4.1+)
Probably the "optionality" of a Type is inside the actual type (T
in this case) in swift 4.2
But this behaviour defeats the purpose of guard let statement.
This is interesting.
I'm using OM 3.3 and Xcode 10. I found issue during parsing
nil
valueImmutableMappable.swift
This method returns value event if
currentValue = nil
, but should throw an error.You can try this code in playground, you will see that it will not go inside
catch
block. Replacevar a: Int!
tovar a: Int = 0
and now it will go to catch.