Skip to content
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
4 changes: 2 additions & 2 deletions Sources/SwiftParser/Attributes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,12 @@ extension Parser {
case .customAttribute:
shouldParseArgument = self.withLookahead { $0.atAttributeOrSpecifierArgument() }
case .optional:
shouldParseArgument = self.at(.leftParen)
shouldParseArgument = self.at(TokenSpec(.leftParen, allowAtStartOfLine: false))
case .noArgument:
shouldParseArgument = false
}
if shouldParseArgument {
var (unexpectedBeforeLeftParen, leftParen) = self.expect(.leftParen)
var (unexpectedBeforeLeftParen, leftParen) = self.expect(TokenSpec(.leftParen, allowAtStartOfLine: false))
if unexpectedBeforeLeftParen == nil
&& (attributeName.raw.trailingTriviaByteLength > 0 || leftParen.leadingTriviaByteLength > 0)
{
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftParser/Directives.swift
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ extension Parser {
/// Parse a line control directive.
mutating func parsePoundSourceLocationDirective() -> RawPoundSourceLocationSyntax {
let line = self.consumeAnyToken()
let (unexpectedBeforeLParen, lparen) = self.expect(.leftParen)
let (unexpectedBeforeLParen, lparen) = self.expect(TokenSpec(.leftParen, allowAtStartOfLine: false))
let arguments: RawPoundSourceLocationArgumentsSyntax?
if !self.at(.rightParen) {
let (unexpectedBeforeFile, file) = self.expect(.keyword(.file))
Expand Down
15 changes: 15 additions & 0 deletions Tests/SwiftParserTest/AttributeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,21 @@ final class AttributeTests: ParserTestCase {
)
}

func testObjCAttributeNewlineParen() {
assertParse(
"""
@objc
1️⃣(foo) func foo()
""",
diagnostics: [
DiagnosticSpec(
locationMarker: "1️⃣",
message: "unexpected code '(foo)' in function"
)
]
)
}

func testRethrowsAttribute() {
assertParse(
"""
Expand Down
29 changes: 29 additions & 0 deletions Tests/SwiftParserTest/AvailabilityTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,33 @@ final class AvailabilityTests: ParserTestCase {
]
)
}

func testAvailableNewlineParen() {
assertParse(
"""
@available1️⃣
2️⃣(*, unavailable) func foo() {}
""",
diagnostics: [
DiagnosticSpec(
locationMarker: "1️⃣",
message: "expected '()' in attribute",
fixIts: ["insert '()'"]
),
DiagnosticSpec(
locationMarker: "1️⃣",
message: "expected argument for '@available' attribute",
fixIts: ["insert attribute argument"]
),
DiagnosticSpec(
locationMarker: "2️⃣",
message: "unexpected code '(*, unavailable)' in function"
),
],
fixedSource: """
@available()
(*, unavailable) func foo() {}
"""
)
}
}
24 changes: 23 additions & 1 deletion Tests/SwiftParserTest/DirectiveTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ final class DirectiveTests: ParserTestCase {
)
}

func testIfConfigRRR() {
func testIfConfigAfterAttribute() {
assertParse(
"""
@frozen1️⃣
Expand Down Expand Up @@ -436,4 +436,26 @@ final class DirectiveTests: ParserTestCase {
"""
)
}

func testSourcelocationDirectiveNewlineParen() {
assertParse(
"""
#sourceLocation1️⃣
(file: "other.swift", line: 1)
var someName: Int
""",
diagnostics: [
DiagnosticSpec(
locationMarker: "1️⃣",
message: "expected '(', arguments, and ')' in '#sourceLocation' directive",
fixIts: ["insert '(', arguments, and ')'"]
)
],
fixedSource: """
#sourceLocation(file: "", line: <#integer literal#>)
(file: "other.swift", line: 1)
var someName: Int
"""
)
}
}