Skip to content

Explicit Swift 6.x support and fixes #63

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 2 commits into from
Jun 29, 2025
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
32 changes: 27 additions & 5 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,25 @@ on:

jobs:
swift_tests_latest:
name: Latest Swift
name: Latest Swift (6.1)
runs-on: macos-15
steps:
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: .build
key: macos-latest-spm-${{ hashFiles('**/Package.resolved') }}
restore-keys: |
macos-latest-tests-spm-
- name: Build
run: swift build
- name: Run tests
run: swift test
swift_tests_600:
name: Swift 6.0
runs-on: macos-15
steps:
- uses: maxim-lobanov/setup-xcode@v1
Expand All @@ -35,12 +53,12 @@ jobs:
path: .build
key: macos-latest-spm-${{ hashFiles('**/Package.resolved') }}
restore-keys: |
macos-latest-spm-
macos-600-tests-spm-
- name: Build
run: swift build
- name: Run tests
run: swift test
swift_tests_previous:
swift_tests_510:
name: Swift 5.10
runs-on: macos-14
steps:
Expand All @@ -53,7 +71,9 @@ jobs:
path: .build
key: macos-14-swift-510-spm-${{ hashFiles('**/Package.resolved') }}
restore-keys: |
macos-14-swift-510-spm-
macos-14-swift-510-tests-spm-
- name: Remove Resolved
run: rm -rf Package.resolved
- name: Build
run: swift build
- name: Run tests
Expand All @@ -78,7 +98,9 @@ jobs:
path: .build
key: ${{ matrix.os }}-${{ matrix.swift }}-spm-${{ hashFiles('**/Package.resolved') }}
restore-keys: |
${{ matrix.os }}-spm-
${{ matrix.os }}-tests-spm-
- name: Remove Resolved
run: rm -rf Package.resolved
- name: Build
run: swift build
- name: Run tests
Expand Down
11 changes: 6 additions & 5 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 6.0
// swift-tools-version: 6.1
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand All @@ -20,7 +20,7 @@ let package = Package(
),
],
dependencies: [
.package(url: "https://github.com/swiftlang/swift-syntax.git", from: "600.0.1"),
.package(url: "https://github.com/swiftlang/swift-syntax.git", from: "601.0.1"),
],
targets: [
.target(
Expand Down
51 changes: 51 additions & 0 deletions Package@swift-6.0.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "SyntaxSparrow",
platforms: [
.macOS(.v10_15),
.iOS(.v13),
.tvOS(.v13),
.watchOS(.v6),
.macCatalyst(.v13)
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "SyntaxSparrow",
targets: ["SyntaxSparrow"]
),
],
dependencies: [
.package(url: "https://github.com/swiftlang/swift-syntax.git", from: "600.0.1"),
],
targets: [
.target(
name: "SyntaxSparrow",
dependencies: [
.product(name: "SwiftSyntax", package: "swift-syntax"),
.product(name: "SwiftParser", package: "swift-syntax"),
],
resources: [
.copy("Resources/PrivacyInfo.xcprivacy")
],
swiftSettings: [
.swiftLanguageMode(.v6)
]
),
.testTarget(
name: "SyntaxSparrowTests",
dependencies: [
"SyntaxSparrow",
]
),
]
)

// Supplementary
package.dependencies.append(contentsOf: [
.package(url: "https://github.com/SwiftPackageIndex/SPIManifest.git", from: "0.12.0"),
])
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ struct VariableSemanticsResolver: SemanticsResolving {
// Resolver accessors for assessment
let accessors = resolveAccessors()
let accessorKinds = accessors.compactMap(\.kind)
// Only getter accessors mean that there is no setters
guard accessorKinds != [.get] else { return false }
// General setter check
let hasSetterAccessor = accessorKinds.contains(where: { [.set, .willSet, .didSet].contains($0) })
let hasEffectGetter = accessors.contains(where: {
let hasSpecifier = ($0.effectSpecifiers?.throwsSpecifier != nil || $0.effectSpecifiers?.asyncSpecifier != nil)
Expand All @@ -125,7 +128,7 @@ struct VariableSemanticsResolver: SemanticsResolving {
guard !hasEffectGetter else { return false }
// If setter exists in accessors can return true (usually protocol context or manually written will/did/set accessor).
if hasSetterAccessor { return true }
// If no accessors, but a direct return/code block, can assume there is no setter
// If no accessors, but a direct return/code block, can assume there is no setter. (computed var)
if accessors.isEmpty, resolveHasCodeBlockItems() { return false }
// Otherwise if the keyword is not `let` (immutable)
guard resolveKeyword() != "let" else { return false }
Expand Down
12 changes: 12 additions & 0 deletions Sources/SyntaxSparrow/Public/Semantics/Components/EntityType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,16 @@ public enum EntityType: Equatable, Hashable, CustomStringConvertible {
public init(_ typeSyntax: TypeSyntax) {
self = EntityType.parseType(typeSyntax)
}

#if swift(>=6.1)
/// Creates a new ``SyntaxSparrow/EntityType`` instance from a `GenericArgumentSyntax.Argument` node.
public init(_ argument: GenericArgumentSyntax.Argument) {
switch argument {
case .type(let typeSyntax):
self = EntityType.parseType(typeSyntax)
default:
self = .empty
}
}
#endif
}
20 changes: 19 additions & 1 deletion Tests/SyntaxSparrowTests/Declarations/VariableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,24 @@ final class VariableTests: XCTestCase {
XCTAssertFalse(variable.hasSetter)
}

func test_variable_mutable_onlyGetter_willReturnFalseForHasSetter() {
let source = #"""
var name: String {
get { "test" }
}
var other: String {
"test"
}
"""#
instanceUnderTest.updateToSource(source)
XCTAssertTrue(instanceUnderTest.isStale)
instanceUnderTest.collectChildren()
XCTAssertFalse(instanceUnderTest.isStale)
XCTAssertEqual(instanceUnderTest.variables.count, 2)
XCTAssertFalse(instanceUnderTest.variables[0].hasSetter)
XCTAssertFalse(instanceUnderTest.variables[1].hasSetter)
}

func test_variable_multiplePatternBindings_willResolveExpectedValues() {
let source = #"""
var firstName, lastName: String
Expand Down Expand Up @@ -297,7 +315,7 @@ final class VariableTests: XCTestCase {
XCTAssertFalse(instanceUnderTest.variables[4].isComputed)
XCTAssertTrue(instanceUnderTest.variables[5].isComputed)
XCTAssertTrue(instanceUnderTest.variables[6].isComputed)
XCTAssertFalse(instanceUnderTest.variables[7].isComputed)
XCTAssertTrue(instanceUnderTest.variables[7].isComputed)
}

func test_variable_hasSetterHelper_willResolveExpectedValues() {
Expand Down