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
if v[i]: over a Vec[bool] element is rejected: 'if condition must be bool' (D22 contextual Copy not applied to conditions) #1472
Spec: §21.1 Rule 10 / D22 contextual Copy / D27 ("xs[i] denotes the element place"). A bool condition is an owned-value demand of a Copy type, so a bool element used as a condition should materialize, the same way let b: bool = v[0] does.
type D { flags: Vec[bool] }
fn f(d: &D, i: i32) -> str: if d.flags[i]: "a" else: "b"
fn main:
let v: Vec[bool] = Vec.new()
v.push(true)
let x = if v[0]: 1 else: 2
let d = D { flags: v }
print(f"{x} {f(d, 0)}")
Expected: prints 1 a. Actual:
error: if condition must be bool
--> bv.w:2:32
2 | fn f(d: &D, i: i32) -> str: if d.flags[i]: "a" else: "b"
error: if condition must be bool
--> bv.w:6:16
6 | let x = if v[0]: 1 else: 2
Workaround used (modeled-C stage 6, src/compiler/FacadeRender.w): bind the element to a typed local first (let optional: bool = deps.slot_optional[si]). Remove it when this is fixed.
Found while implementing modeled-C stage 6; not fixed there (out of scope).
Activity