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
12 changes: 7 additions & 5 deletions Sources/SwiftExtract/SwiftTypes/SwiftFunctionSignature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -545,17 +545,19 @@ extension VariableDeclSyntax {
return [.get]
}

if let accessorBlock = binding.accessorBlock {
return accessorBlock.supportedAccessorKinds()
}

// Account for private(set) and similar modifiers
// Account for private(set) and similar modifiers. This is checked before the
// accessor block, because a variable can restrict its setter's access level and
// still spell out its accessors explicitly.
for modifier in self.modifiers where modifier.detail?.detail.text == "set" {
if !minimumAccessLevel.matches(modifier) {
return [.get]
}
}

if let accessorBlock = binding.accessorBlock {
return accessorBlock.supportedAccessorKinds()
}

return [.get, .set]
}
}
Expand Down
34 changes: 34 additions & 0 deletions Tests/JExtractSwiftTests/VariableImportTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,38 @@ final class VariableImportTests {
]
)
}

let class_privateSetWithAccessorBlockInterfaceFile =
"""
public class MySwiftClass {
public private(set) var counterInt: Int {
get { fatalError() }
set { fatalError() }
}
}
"""

@Test("Import: public private(set) var counterInt: Int with an explicit accessor block emits only the getter")
func variable_int_privateSet_explicitAccessorBlock() throws {
try assertOutput(
input: class_privateSetWithAccessorBlockInterfaceFile,
.ffm,
.java,
swiftModuleName: "FakeModule",
detectChunkByInitialLines: 1,
expectedChunks: [
"""
public long getCounterInt() throws SwiftIntegerOverflowException {
$ensureAlive();
long result$checked = swiftjava_FakeModule_MySwiftClass_counterInt$get.call(this.$memorySegment());
...
}
"""
],
notExpectedChunks: [
"swiftjava_FakeModule_MySwiftClass_counterInt$set",
"setCounterInt",
]
)
}
}
Loading