Skip to content

Commit 62a6437

Browse files
committed
Fix parsing generic argument lists of variadic types in expression context
We need to allow empty argument lists, and accept '...' in canParseType().
1 parent 715f125 commit 62a6437

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

Sources/SwiftParser/Types.swift

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -618,22 +618,26 @@ extension Parser.Lookahead {
618618
break
619619
}
620620

621-
guard self.isAtFunctionTypeArrow() else {
622-
return true
623-
}
621+
if self.isAtFunctionTypeArrow() {
622+
// Handle type-function if we have an '->' with optional
623+
// 'async' and/or 'throws'.
624+
var loopProgress = LoopProgressCondition()
625+
while let (_, handle) = self.at(anyIn: EffectsSpecifier.self), loopProgress.evaluate(currentToken) {
626+
self.eat(handle)
627+
}
624628

625-
// Handle type-function if we have an '->' with optional
626-
// 'async' and/or 'throws'.
627-
var loopProgress = LoopProgressCondition()
628-
while let (_, handle) = self.at(anyIn: EffectsSpecifier.self), loopProgress.evaluate(currentToken) {
629-
self.eat(handle)
629+
guard self.consume(if: .arrow) != nil else {
630+
return false
631+
}
632+
633+
return self.canParseType()
630634
}
631635

632-
guard self.consume(if: .arrow) != nil else {
633-
return false
636+
if self.currentToken.isEllipsis {
637+
self.consumeAnyToken()
634638
}
635639

636-
return self.canParseType()
640+
return true
637641
}
638642

639643
mutating func canParseTupleBodyType() -> Bool {
@@ -822,14 +826,16 @@ extension Parser.Lookahead {
822826
}
823827

824828
self.consumePrefix("<", as: .leftAngle)
825-
var loopProgress = LoopProgressCondition()
826-
repeat {
827-
guard self.canParseType() else {
828-
return false
829-
}
830-
// Parse the comma, if the list continues.
831-
} while self.consume(if: .comma) != nil && loopProgress.evaluate(currentToken)
832829

830+
if !self.currentToken.starts(with: ">") {
831+
var loopProgress = LoopProgressCondition()
832+
repeat {
833+
guard self.canParseType() else {
834+
return false
835+
}
836+
// Parse the comma, if the list continues.
837+
} while self.consume(if: .comma) != nil && loopProgress.evaluate(currentToken)
838+
}
833839

834840
guard self.currentToken.starts(with: ">") else {
835841
return false

0 commit comments

Comments
 (0)