Skip to content

ClosedRange .lowerBound and .upperBound transpiled incorrectly #28

Description

@vdkdamian

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
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions