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
24 changes: 22 additions & 2 deletions Sources/SwiftParser/Parameters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,30 @@ extension Parser {
let modifiers = parseParameterModifiers(isClosure: false)
let misplacedSpecifiers = parseMisplacedSpecifiers()

let names = self.parseParameterNames()
var names = self.parseParameterNames()
let (unexpectedBeforeColon, colon) = self.expect(.colon)

let type = self.parseType(misplacedSpecifiers: misplacedSpecifiers)
let type: RawTypeSyntax

if colon.presence == .missing, let secondName = names.secondName, secondName.tokenText.isStartingWithUppercase {
// Synthesize the secondName parameter as a type node.
type = RawTypeSyntax(
RawSimpleTypeIdentifierSyntax(
name: secondName,
genericArgumentClause: nil,
arena: self.arena
)
)
names = ParameterNames(
unexpectedBeforeFirstName: names.unexpectedBeforeFirstName,
firstName: names.firstName,
unexpectedBeforeSecondName: nil,
secondName: nil
)
} else {
// Parse the type node as we would normally do.
type = self.parseType(misplacedSpecifiers: misplacedSpecifiers)
}

let ellipsis = self.consumeIfContextualPunctuator("...", remapping: .ellipsis)

Expand Down
6 changes: 3 additions & 3 deletions Tests/SwiftParserTest/translated/InvalidTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -312,19 +312,19 @@ final class InvalidTests: XCTestCase {
do {
class Starfish {}
struct Salmon {}
func f(s Starfish1️⃣,
func f(s 1️⃣Starfish,
_ ss: Salmon) -> [Int] {}
func g() { f(Starfish(), Salmon()) }
}
""",
diagnostics: [
DiagnosticSpec(message: "expected ':' and type in parameter", fixIts: ["insert ':' and type"])
DiagnosticSpec(message: "expected ':' in parameter", fixIts: ["insert ':'"])
],
fixedSource: """
do {
class Starfish {}
struct Salmon {}
func f(s Starfish: <#type#>,
func f(s: Starfish,
_ ss: Salmon) -> [Int] {}
func g() { f(Starfish(), Salmon()) }
}
Expand Down