Skip to content

Commit 2778a19

Browse files
Use representedLiteralValue to get the string value of a string literal
1 parent 6aaa056 commit 2778a19

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

SourceKitLSPDevUtils/Sources/ConfigSchemaGen/OptionSchema.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,14 @@ struct OptionSchemaContext {
156156
}
157157
let name: String
158158
if let rawValue = $0.rawValue?.value {
159-
if let stringLiteral = rawValue.as(StringLiteralExprSyntax.self), stringLiteral.segments.count == 1 {
160-
name = stringLiteral.segments.first!.description
159+
if let stringLiteral = rawValue.as(StringLiteralExprSyntax.self),
160+
let literalValue = stringLiteral.representedLiteralValue
161+
{
162+
name = literalValue
161163
} else {
162-
throw ConfigSchemaGenError("Only string literals without interpolation are supported as enum case raw values: \(caseDecl)")
164+
throw ConfigSchemaGenError(
165+
"Only string literals without interpolation are supported as enum case raw values: \(caseDecl)"
166+
)
163167
}
164168
} else {
165169
name = $0.name.text

0 commit comments

Comments
 (0)