swift-macro-toolkit
swift-macro-toolkit copied to clipboard
Enum inferred raw value
Previously we could already get the raw value of a case with EnumCase.value and now that can also return a new case called inferredRawValue.
enum Foo: String {
case bar // implicit raw value of "bar"
}
enum Foo: Int {
case bar = 3
case baz // implicit raw value of 4
}
EnumCaseValue.rawValue and EnumCaseValue.inferredRawValue have the same associated value type so you can do:
switch value {
case .rawValue(let initializer), .inferredRawValue(let initializer):
// ..
default: break
}
This PR only adds raw representable checking when it is the first inherited type, which is the simplest case. It does not check eg typealias RawValue = String.
Requires #31