name: debug-unification description: Debug unification failures in deep6. Use when unification returns null or produces unexpected results.
Debug Unification Failures
Debug why unification failed or produced unexpected variable bindings.
Steps
Identify the failing case
- Read the test or code that calls
unify()ormatch() - Note the left and right operands
- Note any options passed (openObjects, circular, etc.)
- Read the test or code that calls
Understand the unification flow
- Read
src/unify.jsmain loop (lines 309-438) - Key stages:
- Direct equality (
===) - Wildcard match (
any/_) - Variable binding
- Circular detection
- Custom unifiers (
Unifiersubclass) - Registered types (Date, RegExp, etc.)
- Generic object comparison
- Direct equality (
- Read
Add debug logging
- Temporarily add console.log in
src/unify.jsat key decision points:- After direct equality check
- When variables are bound
- When circular refs are detected
- Before/after registry checks
- Example:
console.log('unify pair:', {l, r, typeL: typeof l, typeR: typeof r})
- Temporarily add console.log in
Check variable bindings
- If using variables, check
env.getAllValues()after unification - Verify variables are bound as expected
- Check for alias conflicts
- If using variables, check
Test in isolation
- Create a minimal reproduction in
tests/tests.js - Test just the failing pair
- Gradually add complexity
- Create a minimal reproduction in
Common failure modes
- Type mismatch:
typeof l != typeof r(line 389) - Missing property: Object has different keys
- Circular conflict: Same object unified with different values
- Registered type failure: Date/RegExp/typed array comparison failed
- Function handling: Functions compared without
ignoreFunctions: true
- Type mismatch:
Fix and verify
- Apply the fix (code change, option adjustment, or pattern correction)
- Run
npm testto verify all tests pass - Remove debug logging
Unification Debugging Tips
- Use
match()withopenObjects: falseto require exact matches - Use
open(obj)orsoft(obj)to control matching strictness - Check
env.depthto understand variable scoping - Remember: unification is bidirectional — either side can have variables
Tools
npm test— Run full test suitenpm run debug— Debug with Node inspectorenv.getAllValues()— Inspect variable bindings