Skip to content

Commit b12b70c

Browse files
committed
Fix a string interpolation error in CodeGeneration
`leafProtocolDecl` placed two declarations within the same `DeclSyntax`, which didn’t parse correctly, triggering `logStringInterpolationParsingError`. Split the function so that one returns the protocol declaration and the other returns the extension.
1 parent 86f50c2 commit b12b70c

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxBaseNodesFile.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ let syntaxBaseNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
321321
}
322322

323323
leafProtocolDecl(type: node.kind.leafProtocolType, inheritedType: node.kind.protocolType)
324+
leafProtocolExtension(type: node.kind.leafProtocolType, inheritedType: node.kind.protocolType)
324325
}
325326

326327
try! ExtensionDeclSyntax(
@@ -350,18 +351,25 @@ let syntaxBaseNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
350351
}
351352

352353
leafProtocolDecl(type: "_LeafSyntaxNodeProtocol", inheritedType: "SyntaxProtocol")
354+
leafProtocolExtension(type: "_LeafSyntaxNodeProtocol", inheritedType: "SyntaxProtocol")
353355
}
354356

355357
private func leafProtocolDecl(type: TypeSyntax, inheritedType: TypeSyntax) -> DeclSyntax {
356358
DeclSyntax(
357-
#"""
359+
"""
358360
/// Protocol that syntax nodes conform to if they don't have any semantic subtypes.
359361
/// These are syntax nodes that are not considered base nodes for other syntax types.
360362
///
361363
/// Syntax nodes conforming to this protocol have their inherited casting methods
362364
/// deprecated to prevent incorrect casting.
363-
public protocol \#(type): \#(inheritedType) {}
365+
public protocol \(type): \(inheritedType) {}
366+
"""
367+
)
368+
}
364369

370+
private func leafProtocolExtension(type: TypeSyntax, inheritedType: TypeSyntax) -> DeclSyntax {
371+
DeclSyntax(
372+
#"""
365373
public extension \#(type) {
366374
/// Checks if the current leaf syntax node can be cast to a different specified type.
367375
///

Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ public extension _LeafDeclSyntaxNodeProtocol {
275275
func `is`<S: DeclSyntaxProtocol>(_ syntaxType: S.Type) -> Bool {
276276
return false
277277
}
278+
278279

279280
/// Attempts to cast the current leaf syntax node to a different specified type.
280281
///
@@ -286,6 +287,7 @@ public extension _LeafDeclSyntaxNodeProtocol {
286287
func `as`<S: DeclSyntaxProtocol>(_ syntaxType: S.Type) -> S? {
287288
return nil
288289
}
290+
289291

290292
/// Force-casts the current leaf syntax node to a different specified type.
291293
///
@@ -591,6 +593,7 @@ public extension _LeafExprSyntaxNodeProtocol {
591593
func `is`<S: ExprSyntaxProtocol>(_ syntaxType: S.Type) -> Bool {
592594
return false
593595
}
596+
594597

595598
/// Attempts to cast the current leaf syntax node to a different specified type.
596599
///
@@ -602,6 +605,7 @@ public extension _LeafExprSyntaxNodeProtocol {
602605
func `as`<S: ExprSyntaxProtocol>(_ syntaxType: S.Type) -> S? {
603606
return nil
604607
}
608+
605609

606610
/// Force-casts the current leaf syntax node to a different specified type.
607611
///
@@ -862,6 +866,7 @@ public extension _LeafPatternSyntaxNodeProtocol {
862866
func `is`<S: PatternSyntaxProtocol>(_ syntaxType: S.Type) -> Bool {
863867
return false
864868
}
869+
865870

866871
/// Attempts to cast the current leaf syntax node to a different specified type.
867872
///
@@ -873,6 +878,7 @@ public extension _LeafPatternSyntaxNodeProtocol {
873878
func `as`<S: PatternSyntaxProtocol>(_ syntaxType: S.Type) -> S? {
874879
return nil
875880
}
881+
876882

877883
/// Force-casts the current leaf syntax node to a different specified type.
878884
///
@@ -1143,6 +1149,7 @@ public extension _LeafStmtSyntaxNodeProtocol {
11431149
func `is`<S: StmtSyntaxProtocol>(_ syntaxType: S.Type) -> Bool {
11441150
return false
11451151
}
1152+
11461153

11471154
/// Attempts to cast the current leaf syntax node to a different specified type.
11481155
///
@@ -1154,6 +1161,7 @@ public extension _LeafStmtSyntaxNodeProtocol {
11541161
func `as`<S: StmtSyntaxProtocol>(_ syntaxType: S.Type) -> S? {
11551162
return nil
11561163
}
1164+
11571165

11581166
/// Force-casts the current leaf syntax node to a different specified type.
11591167
///
@@ -1425,6 +1433,7 @@ public extension _LeafTypeSyntaxNodeProtocol {
14251433
func `is`<S: TypeSyntaxProtocol>(_ syntaxType: S.Type) -> Bool {
14261434
return false
14271435
}
1436+
14281437

14291438
/// Attempts to cast the current leaf syntax node to a different specified type.
14301439
///
@@ -1436,6 +1445,7 @@ public extension _LeafTypeSyntaxNodeProtocol {
14361445
func `as`<S: TypeSyntaxProtocol>(_ syntaxType: S.Type) -> S? {
14371446
return nil
14381447
}
1448+
14391449

14401450
/// Force-casts the current leaf syntax node to a different specified type.
14411451
///
@@ -1754,6 +1764,7 @@ public extension _LeafSyntaxNodeProtocol {
17541764
func `is`<S: SyntaxProtocol>(_ syntaxType: S.Type) -> Bool {
17551765
return false
17561766
}
1767+
17571768

17581769
/// Attempts to cast the current leaf syntax node to a different specified type.
17591770
///
@@ -1765,6 +1776,7 @@ public extension _LeafSyntaxNodeProtocol {
17651776
func `as`<S: SyntaxProtocol>(_ syntaxType: S.Type) -> S? {
17661777
return nil
17671778
}
1779+
17681780

17691781
/// Force-casts the current leaf syntax node to a different specified type.
17701782
///

0 commit comments

Comments
 (0)