Skip to content

Commit 1357c37

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 503da1f commit 1357c37

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

Sources/SwiftSyntax/SyntaxCollection.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,15 @@ extension SyntaxCollection {
3535

3636
public init(_ children: [Element]) {
3737
let arena = SyntaxArena()
38-
let raw = RawSyntax.makeLayout(
39-
kind: Self.syntaxKind,
40-
from: children.map { $0.raw },
41-
arena: arena
42-
)
38+
// Extend the lifetime of children so their arenas don't get destroyed
39+
// before they can be added as children of the new arena.
40+
let raw = withExtendedLifetime(children) {
41+
RawSyntax.makeLayout(
42+
kind: Self.syntaxKind,
43+
from: children.map { $0.raw },
44+
arena: arena
45+
)
46+
}
4347
self.init(SyntaxData.forRoot(raw, rawNodeArena: arena))
4448
}
4549

0 commit comments

Comments
 (0)