Skip to content

🐛 Unsatisfied claim in KDoc of number types' hashCode function #1051

Description

@LVMVRQUXL

🎯 Goal

Affected version: 5.2.0

In the types from org.kotools.types.number package (Decimal, Integer, NonNegativeInteger, NonPositiveInteger, NonZeroInteger), the documentation of the hashCode function states the following:

This function follows the contract of Any.hashCode, with an additional property: if two instances are not equal, then calling this function on these objects must produce different hash codes.

This claim can't be satisfied mathematically. Int is a bounded type on 32-bit: collisions can occur. Here's an example:

// On Kotlin/JVM platform:
"Aa".hashCode() == "BB".hashCode()

The fix is to only guaranty that the implementation satisfies only the contract of Any.hashCode, not more, not less.

✅ Checklist

  • ...
  • 📝 Update unreleased changelog

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions