Bug Report
Equal.equals throws TypeError: Cannot convert undefined or null to object when comparing values where one is null and the other is a non-null object, inside a structuralRegion.
Reproduction
import * as Equal from "effect/Equal"
import * as Utils from "effect/Utils"
// This crashes:
Utils.structuralRegion(() => Equal.equals({ name: "hello" }, null))
// TypeError: Cannot convert undefined or null to object
// at Object.getPrototypeOf (<anonymous>)
// at compareBoth (Equal.ts)
Root Cause
In compareBoth, when selfType === "object":
- Line checking
self !== null && that !== null correctly prevents entering the first block when one is null
- But it falls through to the
structuralRegionState.enabled block
Object.getPrototypeOf(self) is called without a null guard — crashes when self is null
This is because typeof null === "object" in JavaScript, so null passes the type check but then Object.getPrototypeOf(null) throws.
Suggested Fix
Add a null guard before the getPrototypeOf calls:
if (structuralRegionState.enabled) {
if (self === null || that === null) {
return false;
}
// ... rest of structural comparison
}
Environment
- effect@3.20.0
- Discovered when using structural equality comparison on form state objects containing nullable fields
Bug Report
Equal.equalsthrowsTypeError: Cannot convert undefined or null to objectwhen comparing values where one isnulland the other is a non-null object, inside astructuralRegion.Reproduction
Root Cause
In
compareBoth, whenselfType === "object":self !== null && that !== nullcorrectly prevents entering the first block when one is nullstructuralRegionState.enabledblockObject.getPrototypeOf(self)is called without a null guard — crashes whenselfisnullThis is because
typeof null === "object"in JavaScript, so null passes the type check but thenObject.getPrototypeOf(null)throws.Suggested Fix
Add a null guard before the
getPrototypeOfcalls:Environment