You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A ?? in arithmetic operand position gives its carrier no demand: total += s.parse() ?? 0 cannot infer #2724
With #959's str.parse() (D160, on the fix-campaign stack), a ?? whose result is an arithmetic operand gives its carrier no demand, so a generic call on its left cannot infer its type:
var total: i64 = 0
for w in "40 x 2".fields(): total += w.parse() ?? 0
error: cannot infer generic method type parameter 'T'
The same for total = total + (w.parse() ?? 0). A typed binding works (let v: i64 = w.parse() ?? 0), and so does let n: i64 = s.parse() ?? 0.
Where: check_binary_operator (SemaCheck.w) gives an arithmetic operand its peer's type only when the operand is an untyped literal (§4.2.1 rule 3). A ?? operand is checked in value context, so the ?? has no expected type to hand its carrier.
The question is how far a peer type reaches. D103 says an operator's operands "are not demand sites; the peer type reaches an operand as a hint". Hinting a ?? operand with the peer would make i64_value + (m.get(k) ?? 0) over a HashMap[_, i32] join at i64 instead of i32 then widen, which may change which programs are accepted. That needs a look before it changes; it is why #959 did not take it.
This is awk's {s += $2} (#959's acceptance line for the one-liner lane).
Activity
Sema: a demand on a ?? reaches its carrier, and a ?? arithmetic opera…
Sema: a demand on a ?? reaches its carrier, and a ?? arithmetic opera…
ehartford commentedon Oct 26, 2026
Fixed on main by 2360317 (stack #2743, battery GREEN on its top ddb68e8: behavior-tests 1949/1949, gate, uat and battery-checks green).
std, Sema: str.parse() turns text into a number of the type its use d…