Skip to content

Commit af573bf

Browse files
ahoppenrintaro
authored andcommitted
Make RawSyntax a class
1 parent bbdb60c commit af573bf

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

Sources/SwiftSyntax/RawSyntax.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ fileprivate enum RawSyntaxData {
8585
/// Represents the raw tree structure underlying the syntax tree. These nodes
8686
/// have no notion of identity and only provide structure to the tree. They
8787
/// are immutable and can be freely shared between syntax nodes.
88-
struct RawSyntax {
88+
final class RawSyntax {
8989
fileprivate let data: RawSyntaxData
9090
let presence: SourcePresence
9191

@@ -124,6 +124,13 @@ struct RawSyntax {
124124
}
125125
}).value
126126
}
127+
128+
/// Creates a copy of `other`.
129+
init(_ other: RawSyntax) {
130+
self.data = other.data
131+
self.presence = other.presence
132+
self.id = other.id
133+
}
127134

128135
init(kind: SyntaxKind, layout: [RawSyntax?], presence: SourcePresence,
129136
id: SyntaxNodeId? = nil) {
@@ -336,7 +343,7 @@ extension RawSyntax {
336343

337344
extension RawSyntax: Codable {
338345
/// Creates a RawSyntax from the provided Foundation Decoder.
339-
init(from decoder: Decoder) throws {
346+
required convenience init(from decoder: Decoder) throws {
340347
let container = try decoder.container(keyedBy: CodingKeys.self)
341348
let id = try container.decodeIfPresent(SyntaxNodeId.self, forKey: .id)
342349
let omitted = try container.decodeIfPresent(Bool.self, forKey: .omitted) ?? false
@@ -352,7 +359,7 @@ extension RawSyntax: Codable {
352359
guard let lookupNode = lookupFunc(id) else {
353360
throw IncrementalDecodingError.nodeLookupFailed(id)
354361
}
355-
self = lookupNode
362+
self.init(lookupNode)
356363
return
357364
}
358365

0 commit comments

Comments
 (0)