Update parseType to support Swift 6.4 :: module selector syntax (#2399)

Co-authored-by: calda <1811727+calda@users.noreply.github.com>
This commit is contained in:
Copilot
2026-03-03 08:09:28 -08:00
committed by Cal Stephens
co-authored by calda
parent 54ab2c763a
commit e0524731fa
2 changed files with 41 additions and 0 deletions
+11
View File
@@ -1490,6 +1490,17 @@ extension Formatter {
return TypeName(range: startOfTypeIndex ... followingType.range.upperBound, formatter: self)
}
// `::` can also continue a type (e.g. `Module::Type`), but unlike `.` and `&`,
// there must be no newline between `::` and the following identifier.
if let nextTokenIndex = index(of: .nonSpaceOrCommentOrLinebreak, after: baseType.range.upperBound),
tokens[nextTokenIndex] == .operator("::", .infix),
let afterDoubleColonIndex = index(of: .nonSpaceOrComment, after: nextTokenIndex),
!tokens[afterDoubleColonIndex].isLinebreak,
let followingType = parseType(at: afterDoubleColonIndex, excludeLowercaseIdentifiers: excludeLowercaseIdentifiers)
{
return TypeName(range: startOfTypeIndex ... followingType.range.upperBound, formatter: self)
}
return baseType
}
+30
View File
@@ -2397,6 +2397,36 @@ final class ParsingHelpersTests: XCTestCase {
XCTAssertEqual(formatter.parseType(at: 2)?.string, "Foo.Bar.Baaz.Quux.InnerType1.InnerType2")
}
func testParseModuleQualifiedType() {
let formatter = Formatter(tokenize("""
let foo: Module::Type
"""))
XCTAssertEqual(formatter.parseType(at: 5)?.string, "Module::Type")
}
func testParseNestedModuleQualifiedType() {
let formatter = Formatter(tokenize("""
let foo: Module::Type.Module::Subtype
"""))
XCTAssertEqual(formatter.parseType(at: 5)?.string, "Module::Type.Module::Subtype")
}
func testParseModuleQualifiedTypeWithNewlineBeforeDoubleColon() {
let formatter = Formatter(tokenize("""
let foo: NationalAeronauticsAndSpaceAdministration
::RocketEngine
"""))
XCTAssertEqual(formatter.parseType(at: 5)?.string, "NationalAeronauticsAndSpaceAdministration::RocketEngine")
}
func testDoesntParseModuleQualifiedTypeWithNewlineAfterDoubleColon() {
let formatter = Formatter(tokenize("""
let foo: NationalAeronauticsAndSpaceAdministration::
RocketEngine
"""))
XCTAssertEqual(formatter.parseType(at: 5)?.string, "NationalAeronauticsAndSpaceAdministration")
}
func testParseTuples() {
let input = """
let tuple: (foo: Foo, bar: Bar)