Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-structural-proto-equality.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

Fix structural equality for request-style values when structural hashes collide.
2 changes: 1 addition & 1 deletion packages/effect/src/internal/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const StructuralProto = {
const thatKeys = Object.keys(that)
if (selfKeys.length !== thatKeys.length) return false
for (let i = 0; i < selfKeys.length; i++) {
if (selfKeys[i] !== thatKeys[i] && !Equal.equals(this[selfKeys[i]], that[selfKeys[i]])) {
if (selfKeys[i] !== thatKeys[i] || !Equal.equals(this[selfKeys[i]], that[selfKeys[i]])) {
return false
}
}
Expand Down
12 changes: 11 additions & 1 deletion packages/effect/test/Request.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assert, describe, expect, it } from "@effect/vitest"
import { Array, Context, Data, Fiber } from "effect"
import { Array, Context, Data, Equal, Fiber, Hash } from "effect"
import * as Cause from "effect/Cause"
import * as Effect from "effect/Effect"
import * as Exit from "effect/Exit"
Expand Down Expand Up @@ -133,6 +133,16 @@ const provideEnv = flow(
)

describe.sequential("Request", () => {
it("compares StructuralProto values when hashes collide", () => {
class Req extends Request.Class<{ id: string; account: string }, string> {}

const a = new Req({ id: "id-8", account: "acct-2811" })
const b = new Req({ id: "id-14", account: "acct-755" })

assert.strictEqual(Hash.hash(a), Hash.hash(b))
assert.strictEqual(Equal.equals(a, b), false)
})

it.effect(
"requests are executed correctly",
Effect.fnUntraced(function*() {
Expand Down
Loading