fix(core): from-singleton-list unwraps exactly one level (§10.3.2.9.4)
public
fix(core): from-singleton-list unwraps exactly one level (§10.3.2.9.4) The spec (Table 45) says: convert [e] → e by ONE level of unwrapping, then apply the conforms-to check. The initial implementation used `coerce(items[0], t)` which would have recursively unwrapped [[10]] all the way to 10 even when the target type is `number`. The 0082 test `invoke_005` is the canonical case: bkm_005([10]) → [[10]], coerced to number → null (not 10). Replace the recursive call with a single-level unwrap + direct conformance check. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
| Changeset | 7a63712efc9678ff4e429fa4557c5311573aca8c |
|---|---|
| Author (claimed) | Timo Stolz <timo.stolz@gmail.com>, |
| Parents | 808a4610acbc |
| Children | |
| Pushlog | by timo via ssh |
modified crates/feel-core/src/types.rs +6 −1
| @@ -120,10 +120,15 @@ | ||
| 120 | 120 | return Value::Null; |
| 121 | 121 | } |
| 122 | 122 | // Rule 2: from-singleton-list — target is NOT a list, value IS a singleton. |
| 123 | + // The spec (Table 45) converts `[e]` → `e` by ONE level of unwrapping, then | |
| 124 | + // applies the conforms-to check. This is NOT recursive: `[[10]]` coerced to | |
| 125 | + // `number` yields null, not 10 (the inner `[10]` does not conform to number; | |
| 126 | + // `invoke_005` in 0082 is the canonical test for this). | |
| 123 | 127 | if !matches!(t, FeelType::List(_)) { |
| 124 | 128 | if let Value::List(ref items) = v { |
| 125 | 129 | if items.len() == 1 { |
| 126 | - return coerce(items[0].clone(), t); | |
| 130 | + let elem = items[0].clone(); | |
| 131 | + return if value_conforms_to(&elem, t) { elem } else { Value::Null }; | |
| 127 | 132 | } |
| 128 | 133 | } |
| 129 | 134 | } |