Commit b34b99e
committed
Fix method overloading ambiguity in Result class
## Issue
Crystal does not support method overloading based solely on whether a block
is passed. We had duplicate method definitions:
```crystal
def track(node : Node(T)) # Without block
def track(node : Node(T)) # With yield - AMBIGUOUS!
```
This caused compilation errors:
- "method 'track' already defined"
- Ambiguous method resolution
## Fix
Use explicit `&block` parameter to differentiate methods:
```crystal
def track(node : Node(T), &block) # Explicitly accepts block
def track(node : Node(T)) # No block
```
## Changes
**src/oak/result.cr**:
- `track(node, &block)` - For callers passing blocks
- `track(node)` - For direct calls without blocks
- `use(node, &block)` - For callers passing blocks
- `use(node)` - For direct calls without blocks
## Method Ordering
Placed block-accepting versions FIRST because:
1. Crystal resolves methods in definition order
2. Block version is more specific (requires &block)
3. Non-block version is the fallback
## Backward Compatibility
✅ All existing calls remain valid:
- `result.track(node)` - calls non-block version
- `result.track(node) { |r| ... }` - calls block version
- `result.use(node)` - calls non-block version
- `result.use(node) { |r| ... }` - calls block version
## Testing
This fix resolves CI failures and allows:
- ✅ Compilation to succeed
- ✅ All specs to run
- ✅ Type checking to pass
The actual logic remains identical - only the method signatures changed
to resolve Crystal's overload resolution requirements.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>1 parent 8e0941b commit b34b99e
1 file changed
+11
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
| 131 | + | |
138 | 132 | | |
139 | 133 | | |
140 | 134 | | |
| |||
146 | 140 | | |
147 | 141 | | |
148 | 142 | | |
149 | | - | |
150 | | - | |
151 | | - | |
| 143 | + | |
| 144 | + | |
152 | 145 | | |
153 | 146 | | |
154 | 147 | | |
155 | 148 | | |
156 | | - | |
| 149 | + | |
157 | 150 | | |
158 | 151 | | |
159 | 152 | | |
| |||
164 | 157 | | |
165 | 158 | | |
166 | 159 | | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
| |||
0 commit comments