Wrong warning message for Kotlin OffsetDateTime equality check

Answered

The IDE shows the following warning when using `==` on two instances of `OffsetDateTime`. However, `==` is NOT an “identity-sensitive operation” in Kotlin, so the message seems objectively wrong and unhelpful.

Maybe a useful message would express that the comparison of `OffsetDateTime` with '==' checks for structural equality including the offset, while `isEqual()` has more chance of being the intended check: if the two instances represent the exact same instant in time, regardless of their offsets.

0
5 comments
Greetings from JetBrains Support. 
Since the problem seems to be Kotlin-specific, our Kotlin team will take a look at it as soon as they get a chance. 
It might take a while to receive a reply, but rest assured that your request will be addressed.
0
Hi there! Could you please attach a sample project where the issue can be reproduced?
If the project is private, feel free to upload it here: https://uploads.jetbrains.com/
Once the upload is complete, just share the Upload ID with us.
0

Hi!

Like this:

```kotlin
// Project with single file: scratch.kts
import java.time.OffsetDateTime

val dt1: OffsetDateTime = OffsetDateTime.now()
val dt2: OffsetDateTime = OffsetDateTime.now()
if (dt1 == dt2) {  // IDEA shows the warning here.
    print("same")
}
```

0
Hi there, thank you so much for the details! It looks like https://youtrack.jetbrains.com/issue/KTIJ-35101/False-positive-Identity-sensitive-operation-on-an-instance-of-value-type-LocalDate I've added your example there too. Feel free to follow the issue to track the progress. 
0

That's exactly it. Thank you!

0

Please sign in to leave a comment.