Skip to content

Commit a6f5fda

Browse files
Merge pull request #63 from CheekyGhost-Labs/develop
- Added explicit Swift 6.0 support with default now being 6.1. - Fixed bug where Variable.hasSetter would return true for a comptued property with an explicit get keyword. - Fixed bug where Variable.isComputed would return false for a comptued property with an explicit get keyword.
2 parents 60c0896 + ea84efa commit a6f5fda

File tree

7 files changed

+121
-14
lines changed

7 files changed

+121
-14
lines changed

.github/workflows/unit-tests.yml

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,25 @@ on:
2323

2424
jobs:
2525
swift_tests_latest:
26-
name: Latest Swift
26+
name: Latest Swift (6.1)
27+
runs-on: macos-15
28+
steps:
29+
- uses: maxim-lobanov/setup-xcode@v1
30+
with:
31+
xcode-version: latest
32+
- uses: actions/checkout@v3
33+
- uses: actions/cache@v3
34+
with:
35+
path: .build
36+
key: macos-latest-spm-${{ hashFiles('**/Package.resolved') }}
37+
restore-keys: |
38+
macos-latest-tests-spm-
39+
- name: Build
40+
run: swift build
41+
- name: Run tests
42+
run: swift test
43+
swift_tests_600:
44+
name: Swift 6.0
2745
runs-on: macos-15
2846
steps:
2947
- uses: maxim-lobanov/setup-xcode@v1
@@ -35,12 +53,12 @@ jobs:
3553
path: .build
3654
key: macos-latest-spm-${{ hashFiles('**/Package.resolved') }}
3755
restore-keys: |
38-
macos-latest-spm-
56+
macos-600-tests-spm-
3957
- name: Build
4058
run: swift build
4159
- name: Run tests
4260
run: swift test
43-
swift_tests_previous:
61+
swift_tests_510:
4462
name: Swift 5.10
4563
runs-on: macos-14
4664
steps:
@@ -53,7 +71,9 @@ jobs:
5371
path: .build
5472
key: macos-14-swift-510-spm-${{ hashFiles('**/Package.resolved') }}
5573
restore-keys: |
56-
macos-14-swift-510-spm-
74+
macos-14-swift-510-tests-spm-
75+
- name: Remove Resolved
76+
run: rm -rf Package.resolved
5777
- name: Build
5878
run: swift build
5979
- name: Run tests
@@ -78,7 +98,9 @@ jobs:
7898
path: .build
7999
key: ${{ matrix.os }}-${{ matrix.swift }}-spm-${{ hashFiles('**/Package.resolved') }}
80100
restore-keys: |
81-
${{ matrix.os }}-spm-
101+
${{ matrix.os }}-tests-spm-
102+
- name: Remove Resolved
103+
run: rm -rf Package.resolved
82104
- name: Build
83105
run: swift build
84106
- name: Run tests

Package.resolved

Lines changed: 6 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version: 6.0
1+
// swift-tools-version: 6.1
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
@@ -20,7 +20,7 @@ let package = Package(
2020
),
2121
],
2222
dependencies: [
23-
.package(url: "https://github.com/swiftlang/swift-syntax.git", from: "600.0.1"),
23+
.package(url: "https://github.com/swiftlang/swift-syntax.git", from: "601.0.1"),
2424
],
2525
targets: [
2626
.target(

Package@swift-6.0.swift

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// swift-tools-version: 6.0
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "SyntaxSparrow",
8+
platforms: [
9+
.macOS(.v10_15),
10+
.iOS(.v13),
11+
.tvOS(.v13),
12+
.watchOS(.v6),
13+
.macCatalyst(.v13)
14+
],
15+
products: [
16+
// Products define the executables and libraries a package produces, and make them visible to other packages.
17+
.library(
18+
name: "SyntaxSparrow",
19+
targets: ["SyntaxSparrow"]
20+
),
21+
],
22+
dependencies: [
23+
.package(url: "https://github.com/swiftlang/swift-syntax.git", from: "600.0.1"),
24+
],
25+
targets: [
26+
.target(
27+
name: "SyntaxSparrow",
28+
dependencies: [
29+
.product(name: "SwiftSyntax", package: "swift-syntax"),
30+
.product(name: "SwiftParser", package: "swift-syntax"),
31+
],
32+
resources: [
33+
.copy("Resources/PrivacyInfo.xcprivacy")
34+
],
35+
swiftSettings: [
36+
.swiftLanguageMode(.v6)
37+
]
38+
),
39+
.testTarget(
40+
name: "SyntaxSparrowTests",
41+
dependencies: [
42+
"SyntaxSparrow",
43+
]
44+
),
45+
]
46+
)
47+
48+
// Supplementary
49+
package.dependencies.append(contentsOf: [
50+
.package(url: "https://github.com/SwiftPackageIndex/SPIManifest.git", from: "0.12.0"),
51+
])

Sources/SyntaxSparrow/Internal/Resolvers/Declaration/VariableSemanticsResolver.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ struct VariableSemanticsResolver: SemanticsResolving {
116116
// Resolver accessors for assessment
117117
let accessors = resolveAccessors()
118118
let accessorKinds = accessors.compactMap(\.kind)
119+
// Only getter accessors mean that there is no setters
120+
guard accessorKinds != [.get] else { return false }
121+
// General setter check
119122
let hasSetterAccessor = accessorKinds.contains(where: { [.set, .willSet, .didSet].contains($0) })
120123
let hasEffectGetter = accessors.contains(where: {
121124
let hasSpecifier = ($0.effectSpecifiers?.throwsSpecifier != nil || $0.effectSpecifiers?.asyncSpecifier != nil)
@@ -125,7 +128,7 @@ struct VariableSemanticsResolver: SemanticsResolving {
125128
guard !hasEffectGetter else { return false }
126129
// If setter exists in accessors can return true (usually protocol context or manually written will/did/set accessor).
127130
if hasSetterAccessor { return true }
128-
// If no accessors, but a direct return/code block, can assume there is no setter
131+
// If no accessors, but a direct return/code block, can assume there is no setter. (computed var)
129132
if accessors.isEmpty, resolveHasCodeBlockItems() { return false }
130133
// Otherwise if the keyword is not `let` (immutable)
131134
guard resolveKeyword() != "let" else { return false }

Sources/SyntaxSparrow/Public/Semantics/Components/EntityType.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,16 @@ public enum EntityType: Equatable, Hashable, CustomStringConvertible {
139139
public init(_ typeSyntax: TypeSyntax) {
140140
self = EntityType.parseType(typeSyntax)
141141
}
142+
143+
#if swift(>=6.1)
144+
/// Creates a new ``SyntaxSparrow/EntityType`` instance from a `GenericArgumentSyntax.Argument` node.
145+
public init(_ argument: GenericArgumentSyntax.Argument) {
146+
switch argument {
147+
case .type(let typeSyntax):
148+
self = EntityType.parseType(typeSyntax)
149+
default:
150+
self = .empty
151+
}
152+
}
153+
#endif
142154
}

Tests/SyntaxSparrowTests/Declarations/VariableTests.swift

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,24 @@ final class VariableTests: XCTestCase {
6666
XCTAssertFalse(variable.hasSetter)
6767
}
6868

69+
func test_variable_mutable_onlyGetter_willReturnFalseForHasSetter() {
70+
let source = #"""
71+
var name: String {
72+
get { "test" }
73+
}
74+
var other: String {
75+
"test"
76+
}
77+
"""#
78+
instanceUnderTest.updateToSource(source)
79+
XCTAssertTrue(instanceUnderTest.isStale)
80+
instanceUnderTest.collectChildren()
81+
XCTAssertFalse(instanceUnderTest.isStale)
82+
XCTAssertEqual(instanceUnderTest.variables.count, 2)
83+
XCTAssertFalse(instanceUnderTest.variables[0].hasSetter)
84+
XCTAssertFalse(instanceUnderTest.variables[1].hasSetter)
85+
}
86+
6987
func test_variable_multiplePatternBindings_willResolveExpectedValues() {
7088
let source = #"""
7189
var firstName, lastName: String
@@ -297,7 +315,7 @@ final class VariableTests: XCTestCase {
297315
XCTAssertFalse(instanceUnderTest.variables[4].isComputed)
298316
XCTAssertTrue(instanceUnderTest.variables[5].isComputed)
299317
XCTAssertTrue(instanceUnderTest.variables[6].isComputed)
300-
XCTAssertFalse(instanceUnderTest.variables[7].isComputed)
318+
XCTAssertTrue(instanceUnderTest.variables[7].isComputed)
301319
}
302320

303321
func test_variable_hasSetterHelper_willResolveExpectedValues() {

0 commit comments

Comments
 (0)