Skip to content

Commit 3b0e9a3

Browse files
committed
Extend lifetime of children in SyntaxCollection initializer
We were already doing this for layout nodes but we forgot to do it for collection nodes.
1 parent 875a3ad commit 3b0e9a3

File tree

2 files changed

+537
-194
lines changed

2 files changed

+537
-194
lines changed

CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/SyntaxCollectionsFile.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,15 @@ let syntaxCollectionsFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
169169
"""
170170
public init(_ children: [Element]) {
171171
let arena = SyntaxArena()
172-
let raw = RawSyntax.makeLayout(kind: SyntaxKind.\(node.varOrCaseName),
173-
from: children.map { $0.raw }, arena: arena)
172+
// Extend the lifetime of children so their arenas don't get destroyed
173+
// before they can be added as children of the new arena.
174+
let raw = withExtendedLifetime(children) {
175+
RawSyntax.makeLayout(
176+
kind: SyntaxKind.\(node.varOrCaseName),
177+
from: children.map { $0.raw },
178+
arena: arena
179+
)
180+
}
174181
self.init(SyntaxData.forRoot(raw, rawNodeArena: arena))
175182
}
176183
"""

0 commit comments

Comments
 (0)