skiptools / skiptools/skip-lib
ClosedRange .lowerBound and .upperBound transpiled incorrectly
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 13
- Forks
- 4
- Avg merge
- 1h 49m
- Merged PRs (30d)
- 2
Description
Issue
I have a function with the following Swift code:
if value > bounds.lowerBound {
self.value -= 1
}
if value < bounds.upperBound {
self.value += 1
}
This gets transpiled to the following Kotlin code:
if (value > bounds.lowerBound) {
this.value -= 1
}
if (value < bounds.upperBound) {
this.value += 1
}
I'm getting an error from the compiler that refers to the following line:
if (value > bounds.lowerBound) {
and
if (value < bounds.upperBound) {
Unresolved reference. None of the following candidates is applicable because of a receiver type mismatch:
Proposed solution:
I think this:
if (value > bounds.lowerBound) {
}
needs to change to this:
if (value > bounds.start) {
}
and this:
if (value < bounds.upperBound) {
}
needs to change to this:
if (value < bounds.endInclusive) {
}
Workaround:
if isHigher(value: value, than: bounds) {
self.value -= 1
}
if isLower(value: value, than: bounds) {
self.value += 1
}
// SKIP REPLACE:
// private fun isHigher(value: Int, than: ClosedRange<Int>): Boolean {
// val bounds = than
// return value > bounds.start
// }
fileprivate func isHigher(value: Int, than bounds: ClosedRange<Int>) -> Bool {
return value > bounds.lowerBound
}
// SKIP REPLACE:
// private fun isLower(value: Int, than: ClosedRange<Int>): Boolean {
// val bounds = than
// return value < bounds.endInclusive
// }
fileprivate func isLower(value: Int, than bounds: ClosedRange<Int>) -> Bool {
return value < bounds.upperBound
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No source file or test is named. Start by reproducing the transpilation from the Swift ClosedRange snippet and inspect the generated Kotlin references to lowerBound and upperBound. Done means the generated comparisons use the Kotlin ClosedRange properties shown in the proposed solution and compile successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin, swift
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100