Skip to content

Fix #4132: Make PathCodec.Annotated equals symmetric with matching hashCode - #4170

Open
987Nabil wants to merge 1 commit into
mainfrom
fix-4132-pathcodec-annotated-equals-hashcode
Open

Fix #4132: Make PathCodec.Annotated equals symmetric with matching hashCode#4170
987Nabil wants to merge 1 commit into
mainfrom
fix-4132-pathcodec-annotated-equals-hashcode

Conversation

@987Nabil

Copy link
Copy Markdown
Contributor

Fixes #4132.\n\n## Summary\nPathCodec.Annotated (the public wrapper from ?? / example / annotate, used for docs + OpenAPI) had:\nscala\noverride def equals(that: Any): Boolean = codec.equals(that)\n\nThis was asymmetric, ignored annotations, and used the default case-class hashCode (which includes the annotations Chunk).\n\nAll core operations peel Annotated correctly, but public ==, RoutePattern equality, and hash-based collections were broken.\n\n## Fix\nscala\noverride def equals(that: Any): Boolean = that match {\n case o: Annotated[_] => codec.equals(o.codec)\n case _ => false\n}\n\noverride def hashCode(): Int = codec.hashCode\n\nAnnotations stay as pure metadata (consistent with how everything else handles them).\n\n(Verified on main + full call-site analysis.)

…shCode

Annotated's equals delegated directly to the inner codec (asymmetric, annotations ignored) while the case-class hashCode included the annotations Chunk. Violates equals/hashCode contract.

Fixed to symmetrically compare Annotated instances by their codec only (matching hashCode). Annotations remain metadata.

Fixes #4132
Copilot AI review requested due to automatic review settings June 19, 2026 18:00
@netlify

netlify Bot commented Jun 19, 2026

Copy link
Copy Markdown

Deploy Preview for zio-http ready!

Name Link
🔨 Latest commit 04f0f65
🔍 Latest deploy log https://app.netlify.com/projects/zio-http/deploys/6a3583d6dc93130007fbe2cb
😎 Deploy Preview https://deploy-preview-4170--zio-http.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Grok via xAI seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot couldn't run its full agentic review because no GitHub Actions runner was available. Make sure your repository has a runner available to run Copilot's review, or add a copilot-setup-steps.yml file specifying one with the runs-on attribute. See the docs for more details.

This PR fixes incorrect equals/hashCode behavior for PathCodec.Annotated, ensuring equality is symmetric and that hash-based collections behave consistently by treating annotations as metadata only.

Changes:

  • Make PathCodec.Annotated.equals symmetric by comparing only underlying codec when both sides are Annotated.
  • Override PathCodec.Annotated.hashCode to align with equals by delegating to codec.hashCode.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +760 to +763
override def equals(that: Any): Boolean = that match {
case o: Annotated[_] => codec.equals(o.codec)
case _ => false
}
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.

PathCodec.Annotated.equals is asymmetric and case class is missing a matching hashCode

3 participants