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
it shorthand: names.iter().any(s.contains(it)) is refused (wrong argument type to iter_any_views) #2326
Restated 2026-10-25. The internal error is gone; the program is now refused with a wrong-type diagnostic. names.iter().any(s.contains(it)) still does not compile, while any(n => s.contains(n)) does.
Original report
Spec: §12 (closures; it shorthand), §15 (str views).
Repro (installed v0.15.3.0 and current stage1):
let names = [\"a(\", \"b\"]
let s = \"xa(y\"
print(names.iter().any(s.contains(it)))
Actual: BUG: a &str runtime argument is not a str value (LLVM type kind 10) [src/CodegenDispatch.w Codegen.str_view_arg].
Expected: true. The explicit closure names.iter().any(n => s.contains(n)) prints true, so the it shorthand lowers the element with a different representation than the named parameter (the element arrives as a pointer, LLVM kind 10, where a str value is expected).
Found writing a with -n one-liner during the D114 audit. Workaround: n => s.contains(n).
changed the title [-]BUG str_view_arg: `it` from a List[str] iterator passed to str.contains inside `.any(...)`[/-][+]it shorthand: names.iter().any(s.contains(it)) is refused (wrong argument type to iter_any_views)[/+]on Oct 25, 2026
Triage 2026-10-25, with v0.15.3.0 (main a261b65): reproduced as a refusal.
$ cat main.w
let names = ["a(", "b"]
let s = "xa(y"
print(names.iter().any(s.contains(it)))
$ with run main.w
error: wrong argument type in call to 'iter_any_views'
--> main.w:3:24
= note: actual type: bool
pre-release: a valid program is refused with a message that names an internal function; the named-closure spelling works.
Fix campaign 2026-10-25: half fixed, half flagged human attn needed.
Fixed on main by e3b0ad0 (PR #2660). The original abort came from Sema accepting any function value where any reference was demanded: types_compatible_fast (src/Sema.w) had if (exp_k == TY_PTR or exp_k == TY_REF) and act_k == TY_FN: return 1. I traced it in lldb through builtin_arg_type_compatible(expected=&str, actual=fn(u8) -> bool). s.contains(c => …) therefore passed Sema and Codegen stopped with "BUG: a &str runtime argument is not a str value". A reference now meets a function value only when it is a reference to a function type. s.contains(<closure>) is refused at contains ("wrong argument type in call to 'str.contains'"), with test/compile_errors/err_2326_closure_is_not_a_str_needle.w.
Open: which call the implicit it closure belongs to. The parser wraps it at the innermost call argument holding it (Parser.parse_call, maybe_wrap_implicit_it), so names.iter().any(s.contains(it)) is any(s.contains(x => x)). Two facts settle what the user meant: contains takes &str, and any takes a one-parameter function. But the parser cannot see types.
Others. Scala's _ expands to the smallest enclosing expression that properly contains it, so any(s.contains(_)) means x => s.contains(x), as this program intends. Kotlin and Swift (it, $0) need explicit braces, so the question never arises. With already has §9.4's s.contains(_), which works today: names.iter().any(s.contains(_)) prints true.
Spec §9.3.1: "it … may only appear in expression positions where the surrounding call site expects a single-parameter function type. The compiler infers it's type from the expected function parameter type." Whether "the surrounding call site" is the innermost call or the nearest one that takes a function is not said.
Mission fit. One meaning is forced (only any(n => s.contains(n)) type-checks), so With should infer it. That needs Sema, not the parser, to choose the closure's call: the parser keeps marking the it expression, and Sema wraps it at the nearest argument whose parameter is a one-parameter function.
Prediction (80%). Eric rules that it belongs to the nearest enclosing argument whose parameter takes a one-parameter function, chosen by type in Sema. A position where no such argument exists stays an error.
Narrowest question. Is that the reading of §9.3.1? If yes, the spec sentence gains "the nearest", and the implicit closure moves from the parser to Sema.
Correction to my parking this for a ruling: the brief's own prediction was 80%, the question is not C interop, ownership or safety, and it is easy to reverse, so D98 says implement it; Law 1 decides it on its own (only one meaning type-checks). Implemented as D161 (delegated) on branch fix-2326b (742d7b3), stacked on fix-2646: the parser records each it closure's slot and enclosing call argument, and Sema moves a closure that met no function demand to the nearest argument whose parameter takes a one-parameter function, then rechecks the body (D128's loop). §9.3.1 gains the rule; a move that nests one it closure in another is E0951. Tests: behav_2326_it_belongs_to_nearest_fn_argument, err_2326_moved_it_closure_nests; the 34 fixtures whose code uses it, the it diagnostic fixtures and parser_unit_test pass on stage1.
Activity
[-]BUG str_view_arg: `it` from a List[str] iterator passed to str.contains inside `.any(...)`[/-][+]it shorthand: names.iter().any(s.contains(it)) is refused (wrong argument type to iter_any_views)[/+]ehartford commentedon Oct 25, 2026
Triage 2026-10-25,
with v0.15.3.0(main a261b65): reproduced as a refusal.pre-release: a valid program is refused with a message that names an internal function; the named-closure spelling works.
Sema: a function value meets `&T` only when T is a function type, so …
ehartford commentedon Oct 25, 2026
Fix campaign 2026-10-25: half fixed, half flagged
human attn needed.Fixed on main by e3b0ad0 (PR #2660). The original abort came from Sema accepting any function value where any reference was demanded:
types_compatible_fast(src/Sema.w) hadif (exp_k == TY_PTR or exp_k == TY_REF) and act_k == TY_FN: return 1. I traced it in lldb throughbuiltin_arg_type_compatible(expected=&str, actual=fn(u8) -> bool).s.contains(c => …)therefore passed Sema and Codegen stopped with "BUG: a&strruntime argument is not a str value". A reference now meets a function value only when it is a reference to a function type.s.contains(<closure>)is refused atcontains("wrong argument type in call to 'str.contains'"), withtest/compile_errors/err_2326_closure_is_not_a_str_needle.w.Open: which call the implicit
itclosure belongs to. The parser wraps it at the innermost call argument holdingit(Parser.parse_call,maybe_wrap_implicit_it), sonames.iter().any(s.contains(it))isany(s.contains(x => x)). Two facts settle what the user meant:containstakes&str, andanytakes a one-parameter function. But the parser cannot see types._expands to the smallest enclosing expression that properly contains it, soany(s.contains(_))meansx => s.contains(x), as this program intends. Kotlin and Swift (it,$0) need explicit braces, so the question never arises. With already has §9.4'ss.contains(_), which works today:names.iter().any(s.contains(_))printstrue.it… may only appear in expression positions where the surrounding call site expects a single-parameter function type. The compiler infersit's type from the expected function parameter type." Whether "the surrounding call site" is the innermost call or the nearest one that takes a function is not said.any(n => s.contains(n))type-checks), so With should infer it. That needs Sema, not the parser, to choose the closure's call: the parser keeps marking theitexpression, and Sema wraps it at the nearest argument whose parameter is a one-parameter function.itbelongs to the nearest enclosing argument whose parameter takes a one-parameter function, chosen by type in Sema. A position where no such argument exists stays an error.Narrowest question. Is that the reading of §9.3.1? If yes, the spec sentence gains "the nearest", and the implicit closure moves from the parser to Sema.
ehartford commentedon Oct 26, 2026
Correction to my parking this for a ruling: the brief's own prediction was 80%, the question is not C interop, ownership or safety, and it is easy to reverse, so D98 says implement it; Law 1 decides it on its own (only one meaning type-checks). Implemented as D161 (delegated) on branch fix-2326b (742d7b3), stacked on fix-2646: the parser records each
itclosure's slot and enclosing call argument, and Sema moves a closure that met no function demand to the nearest argument whose parameter takes a one-parameter function, then rechecks the body (D128's loop). §9.3.1 gains the rule; a move that nests oneitclosure in another is E0951. Tests: behav_2326_it_belongs_to_nearest_fn_argument, err_2326_moved_it_closure_nests; the 34 fixtures whose code usesit, theitdiagnostic fixtures and parser_unit_test pass on stage1.Sema: an implicit `it` closure is the nearest argument that takes a f…
ehartford commentedon Oct 26, 2026
Fixed on main by b920db7 (stack #2749 via #2746, battery GREEN on its top 41f0547: behavior-tests 1953 files ok, gate, uat and battery-checks green).