What is expected behavior for loop below (what sho...
# general-advice
p
What is expected behavior for loop below (what should be printed)?
Copy code
for (v in UByte.MIN_VALUE..UByte.MAX_VALUE) {
    println(v) // it is going after 255 and more. Why?
}
e
Copy code
val range = UByte.MIN_VALUE..UByte.MAX_VALUE
for (v in range) println(v)
seems to work, so it seems like a compiler bug with intrinsification
Copy code
for (v in UByte.MIN_VALUE.toUInt()..UByte.MAX_VALUE.toUInt()) {
    println(v)
}
also seems to work, despite being the same type of range
Copy code
for (v in UByte.MAX_VALUE..UByte.MAX_VALUE) println(v)
println(UInt.MAX_VALUE)
prints the same thing so there is some inappropriate sign extension happening
file a YouTrack issue
May be it is some regression in K2
e
no I think this is a backend bug.
for (v in UByte.MAX_VALUE..UByte.MAX_VALUE) println(v)
prints the same wrong thing since Kotlin 1.7
k
And it's not just UByte. It's also a bug with UShort.
e
that's not surprising, they both
operator fun rangeTo(...): UIntRange