Skip to content

Commit befe26f

Browse files
committed
Make garbage parameters in SyntaxFactory unlabeled
If the `garbage` parameters in the SyntaxFactory are labelled, it’s not possible to specify e.g. the second garbage node but leave the others to their default (swiftlang/swift#60274). We could either give these `garbage` parameters distinct names or make them unlabeled to work around that issue. I chose to go for the unlabeled approach because it should be clear that these parameters contain garbage because of their type.
1 parent f0dae2d commit befe26f

File tree

6 files changed

+885
-881
lines changed

6 files changed

+885
-881
lines changed

Sources/SwiftSyntax/SyntaxFactory.swift.gyb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ public enum SyntaxFactory {
5757
% param_type = param_type + "?"
5858
% end
5959
% if child.is_garbage_nodes():
60-
% child_params.append("garbage %s: %s = nil" % (child.swift_name, param_type))
60+
% # It would be nice if we could label all of these arguments 'garbage'.
61+
% # But if we do this, we hit https://github.com/apple/swift/issues/60274.
62+
% child_params.append("_ %s: %s = nil" % (child.swift_name, param_type))
6163
% else:
6264
% child_params.append("%s: %s" % (child.swift_name, param_type))
6365
% end

Sources/SwiftSyntax/gyb_generated/SyntaxFactory.swift

Lines changed: 202 additions & 202 deletions
Large diffs are not rendered by default.

Sources/SwiftSyntaxBuilder/BuildableNodes.swift.gyb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,15 @@ public struct ${type.buildable()}${conformance_clause(conformances)} {
117117
/// - Returns: The built `${type.syntax()}`.
118118
func build${type.base_name()}(format: Format, leadingTrivia additionalLeadingTrivia: Trivia? = nil) -> ${type.syntax()} {
119119
let result = SyntaxFactory.make${type.base_name()}(
120-
${',\n '.join(['%s: %s' % (child.factory_parameter_name(), child.generate_expr_build_syntax_node(child.name(), 'format')) for child in children])}
120+
% parameters = []
121+
% for (index, child) in enumerate(children):
122+
% comma = ',' if index != len(children) - 1 else ''
123+
% if child.child.is_garbage_nodes():
124+
${child.generate_expr_build_syntax_node(child.name(), 'format')}${comma}
125+
% else:
126+
${child.name()}: ${child.generate_expr_build_syntax_node(child.name(), 'format')}${comma}
127+
% end
128+
% end
121129
)
122130
let combinedLeadingTrivia = leadingTrivia + (additionalLeadingTrivia ?? []) + (result.leadingTrivia ?? [])
123131
return result.withLeadingTrivia(combinedLeadingTrivia)

0 commit comments

Comments
 (0)