Skip to content

Add whitespace before else #1518

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
Apr 12, 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
2 changes: 1 addition & 1 deletion CodeGeneration/Sources/SyntaxSupport/KeywordSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public let KEYWORDS: [KeywordSpec] = [
KeywordSpec("do", isLexerClassified: true),
KeywordSpec("dynamic"),
KeywordSpec("each"),
KeywordSpec("else", isLexerClassified: true, requiresTrailingSpace: true),
KeywordSpec("else", isLexerClassified: true, requiresLeadingSpace: true, requiresTrailingSpace: true),
KeywordSpec("enum", isLexerClassified: true, requiresTrailingSpace: true),
KeywordSpec("escaping"),
KeywordSpec("exclusivity"),
Expand Down
2 changes: 2 additions & 0 deletions Sources/SwiftBasicFormat/generated/BasicFormat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ open class BasicFormat: SyntaxRewriter {
return true
case .keyword(.`catch`):
return true
case .keyword(.`else`):
return true
case .keyword(.`in`):
return true
case .keyword(.`where`):
Expand Down
10 changes: 4 additions & 6 deletions Sources/SwiftSyntax/generated/SyntaxCollections.swift
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is those changes part of fixing the leading whitespace?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess not. They may come from missing regeneration from a prior PR, or maybe caused by rebasing PRs on top of main.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was part of this PR: #1482
More specific this commit: 0e21bb7

But I see that some of the code is correctly generated in that PR 🫣

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe caused by missing regeneration after rebase?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think #1455 and #1482 raced here and the code for the new nodes wasn’t properly generated. My bad.

Original file line number Diff line number Diff line change
Expand Up @@ -2387,8 +2387,7 @@ public struct ClosureParameterListSyntax: SyntaxCollection, SyntaxHashable {

public let _syntaxNode: Syntax

@_spi(RawSyntax)
public var layoutView: RawSyntaxLayoutView {
private var layoutView: RawSyntaxLayoutView {
data.raw.layoutView!
}

Expand Down Expand Up @@ -2420,7 +2419,7 @@ public struct ClosureParameterListSyntax: SyntaxCollection, SyntaxHashable {

/// The number of elements, `present` or `missing`, in this collection.
public var count: Int {
return raw.layoutView!.children.count
return layoutView.children.count
}

/// Creates a new `ClosureParameterListSyntax` by replacing the underlying layout with
Expand Down Expand Up @@ -4689,8 +4688,7 @@ public struct EnumCaseParameterListSyntax: SyntaxCollection, SyntaxHashable {

public let _syntaxNode: Syntax

@_spi(RawSyntax)
public var layoutView: RawSyntaxLayoutView {
private var layoutView: RawSyntaxLayoutView {
data.raw.layoutView!
}

Expand Down Expand Up @@ -4722,7 +4720,7 @@ public struct EnumCaseParameterListSyntax: SyntaxCollection, SyntaxHashable {

/// The number of elements, `present` or `missing`, in this collection.
public var count: Int {
return raw.layoutView!.children.count
return layoutView.children.count
}

/// Creates a new `EnumCaseParameterListSyntax` by replacing the underlying layout with
Expand Down
24 changes: 22 additions & 2 deletions Tests/SwiftSyntaxBuilderTest/IfStmtTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,26 @@ final class IfStmtTests: XCTestCase {
}
"""
),
#line: (
ExprSyntax(
"""
if foo == x {
return foo
}
else {
return bar
}
"""
).cast(IfExprSyntax.self),
"""
if foo == x {
return foo
}
else {
return bar
}
"""
),
#line: (
try IfExprSyntax("if foo == x") { StmtSyntax("return foo") },
"""
Expand All @@ -62,7 +82,7 @@ final class IfStmtTests: XCTestCase {
"""
if foo == x {
return foo
}else {
} else {
return bar
}
"""
Expand All @@ -72,7 +92,7 @@ final class IfStmtTests: XCTestCase {
"""
if foo == x {
return foo
}else if foo == z {
} else if foo == z {
return baz
}
"""
Expand Down