This feels tangential to #174 but in fact is distinct and specifically related to Yams's Decoder implementation.
While string values may be quoted or (more often) not in YAML, the easiest way to differentiate a number from a string scalar containing only the textual representation of a number is to quote the string representation.
number: 1234
string: '1234'
Currently, Yams will successfully decode the above YAML as the following type.
struct Funky: Codable {
let number: Int
let string: Int
}
This is arguably a problem for validity checking and definitely causes inconsistency in that re-encoding the same struct would result in different YAML.
number: 1234
string: 1234
An additional problem arises when a type to be decoded might sometimes be a number and other times a string. For example, you may be working with an AnyCodable type (there are a few popular implementations of such a type) because you need to decode an arbitrary structure. These types tend to employ a fallback strategy of decoding that results in trying to decode an integer or other numeric type and succeeding even for quoted YAML scalars as long as those string values happen to be valid string representations of the given numeric type.
This feels tangential to #174 but in fact is distinct and specifically related to Yams's
Decoderimplementation.While string values may be quoted or (more often) not in YAML, the easiest way to differentiate a number from a string scalar containing only the textual representation of a number is to quote the string representation.
Currently, Yams will successfully decode the above YAML as the following type.
This is arguably a problem for validity checking and definitely causes inconsistency in that re-encoding the same struct would result in different YAML.
An additional problem arises when a type to be decoded might sometimes be a number and other times a string. For example, you may be working with an
AnyCodabletype (there are a few popular implementations of such a type) because you need to decode an arbitrary structure. These types tend to employ a fallback strategy of decoding that results in trying to decode an integer or other numeric type and succeeding even for quoted YAML scalars as long as those string values happen to be valid string representations of the given numeric type.