Skip to content

Add missing parameter #1294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions CodeGeneration/Sources/SyntaxSupport/Node.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,14 @@ public class Node {
isOptional: true,
collectionElementName: unexpectedName
),
child,
child
]
}
} + (children.last != nil ? [Child(
name: "UnexpectedAfter\(children.last!.name)",
kind: "UnexpectedNodes",
isOptional: true,
collectionElementName: "UnexpectedAfter\(children.last!.name)"
)] : [])
}

self.nonUnexpectedChildren = children.filter { !$0.isUnexpectedNodes }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ let syntaxTraitsFile = SourceFileSyntax {
}
}

ExtensionDeclSyntax("public extension \(trait.traitName)Syntax") {
ExtensionDeclSyntax("public extension \(raw: trait.traitName)Syntax") {
FunctionDeclSyntax("""
/// Without this function, the `with` function defined on `SyntaxProtocol`
/// does not work on existentials of this protocol type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,8 @@ private func createConvenienceInitializer(node: Node) -> InitializerDeclSyntax?
} else {
produceExpr = ExprSyntax(FunctionCallExprSyntax("\(raw: child.swiftName)Builder()"))
}
let defaultArgument = ClosureExprSyntax {
if child.type.isOptional {
NilLiteralExprSyntax()
} else {
FunctionCallExprSyntax("\(builderInitializableType.syntax)([])")
}
}
builderParameters.append(FunctionParameterSyntax(
"@\(builderInitializableType.resultBuilderBaseName) \(child.swiftName)Builder: () -> \(builderInitializableType.syntax) = \(defaultArgument)",
"@\(builderInitializableType.resultBuilderBaseName) \(child.swiftName)Builder: () -> \(builderInitializableType.syntax)",
for: .functionParameters
))
} else {
Expand All @@ -103,7 +96,7 @@ private func createConvenienceInitializer(node: Node) -> InitializerDeclSyntax?

return InitializerDeclSyntax(
leadingTrivia: .docLineComment("/// A convenience initializer that allows initializing syntax collections using result builders") + .newline,
modifiers: [DeclModifierSyntax(name: .keyword(.public))],
modifiers: [DeclModifierSyntax(leadingTrivia: .newline, name: .keyword(.public))],
signature: FunctionSignatureSyntax(
input: ParameterClauseSyntax {
FunctionParameterSyntax("leadingTrivia: Trivia? = nil", for: .functionParameters)
Expand Down
1 change: 0 additions & 1 deletion Sources/SwiftParser/Lexer/Cursor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1298,7 +1298,6 @@ extension Lexer.Cursor {
}

mutating func lexHexNumber() -> Lexer.Result {
let tokStart = self
// We assume we're starting from the 'x' in a '0x...' floating-point literal.
let zeroConsumed = self.advance(matching: "0")
let xConsumed = self.advance(matching: "x")
Expand Down
301 changes: 129 additions & 172 deletions Sources/SwiftSyntaxBuilder/generated/BuildableNodes.swift

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Tests/SwiftParserTest/DeclarationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1183,7 +1183,7 @@ final class DeclarationTests: XCTestCase {
substructure: Syntax(
SourceFileSyntax(
CodeBlockItemListSyntax {
MacroExpansionDeclSyntax(macro: "expand")
MacroExpansionDeclSyntax(macro: "expand") {}
}
)
)
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftSyntaxBuilderTest/FunctionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ final class FunctionTests: XCTestCase {
}

func testParensEmittedForArgumentAndTrailingClosure() {
let buildable = FunctionCallExprSyntax(callee: ExprSyntax("test"), trailingClosure: ClosureExprSyntax()) {
let buildable = FunctionCallExprSyntax(callee: ExprSyntax("test"), trailingClosure: ClosureExprSyntax {}) {
TupleExprElementSyntax(expression: ExprSyntax("42"))
}
AssertBuildResult(buildable, "test(42) {\n}")
Expand Down
6 changes: 4 additions & 2 deletions Tests/SwiftSyntaxBuilderTest/StructTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ final class StructTests: XCTestCase {
.carriageReturns(1),
],
structKeyword: .keyword(.struct),
identifier: "CarriateReturnsStruct"
identifier: "CarriateReturnsStruct",
members: MemberDeclBlockSyntax(members: [])
)
let carriageReturnFormFeedsStruct = StructDeclSyntax(
leadingTrivia: [
Expand All @@ -55,7 +56,8 @@ final class StructTests: XCTestCase {
.carriageReturnLineFeeds(1),
],
structKeyword: .keyword(.struct),
identifier: "CarriageReturnFormFeedsStruct"
identifier: "CarriageReturnFormFeedsStruct",
members: MemberDeclBlockSyntax(members: [])
)
let testStruct = try StructDeclSyntax("public struct TestStruct") {
nestedStruct
Expand Down