Skip to content

Override hashCode on SProductField to match its equals#5281

Merged
adamw merged 2 commits into
masterfrom
sproductfield-hashcode
Jun 9, 2026
Merged

Override hashCode on SProductField to match its equals#5281
adamw merged 2 commits into
masterfrom
sproductfield-hashcode

Conversation

@adamw

@adamw adamw commented Jun 9, 2026

Copy link
Copy Markdown
Member

Fixes #5220.

SProductField overrode equals() to compare name and schema, but lacked a matching hashCode() implementation, violating the Java contract that equal objects must have equal hash codes. This causes issues when SProductField instances are used in Sets or HashMaps.

Adds hashCode() override derived from the same fields used in equals comparison. Includes test verifying equal fields have matching hash codes and work correctly in collections.

Closes #5220.

@adamw

adamw commented Jun 9, 2026

Copy link
Copy Markdown
Member Author

The failure is clear and consistent across all platforms. Here's the summary:


The test should have matching hashCodes for equal SProductFields fails across all platforms (JVM, JS, Native) for all Scala versions (2.12, 2.13, 3):

SchemaTest.scala:280 — X was not equal to Y

Examples:

  • JVM 2.13: 1686160193 was not equal to 1729653852
  • JS 2.13: 10 was not equal to 11
  • Native 3: 1895159083 was not equal to 1895158859

Root cause: SProductField has a custom equals implementation but no hashCode override, violating the equals/hashCode contract. Two SProductField instances that are equal per equals produce different hash codes. This PR adds the failing test to document the problem, but does not yet add the hashCode implementation to fix it.

@adamw adamw changed the title Add test: SProductField hashCode must match equals override Override hashCode on SProductField to match its equals Jun 9, 2026
@adamw adamw merged commit eb7c064 into master Jun 9, 2026
37 of 38 checks passed
@adamw adamw deleted the sproductfield-hashcode branch June 9, 2026 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SProductField overrides equals on (name, schema) without a matching hashCode

1 participant