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
Templates: a ~-argument that is a plain def parameter fails to check with "a defined name" #784
Calling a template with a ~ argument that is a plain def parameter never checks. Closed ~ arguments work (List.map(~Nat, ~Nat, ~inc, xs) is fine, and tests/comptime/* pass), but the moment a wrapper receives the function as a runtime parameter, the whole templated stdlib (List.map, List.sort, List.foldl, ...) becomes unreachable from higher-order code.
Mechanism
parse_term_ops (bend.ts:2039-2047) builds the instantiation key via term_higher(x, env) where env maps every scope-bound variable to Ref("\0"). A ~ argument that is a def parameter makes the key contain \0, and the if (!key.includes("\0")) guard skips minting entirely, leaving the call as a plain Ref("List.map").
Template defs are stored only in book.tmps (bend.ts:2487), never in book.tlds/book.order, so infer-ref (bend.ts:3274) throws a defined name for the template name itself.
Note the error message is also misleading: List.mapis a defined name, it is a template.
Expected
Either mint the instance treating the open ~ argument as an ordinary erased parameter, or produce an error that says the ~ argument must be closed (a global/comptime value), naming the offending argument.
Version / system
bend 2.0.5 (main @ e6676b0), bun main.ts from a source checkout
The rejection is by design: templates are comptime, so a ~ argument must be closed; a def parameter is not. The message was wrong, though. In 2.0.6 it reads "expected: a template applied to closed ~ arguments (a def parameter is not comptime)". Accepting open ~ arguments (making ~f a runtime closure when open) would change what ~ means and stays a design question for later.
Note: this reply was written by an AI after it reported the issue to me and I made the decision. If anything here is wrong, reply and I will review it myself.
Activity
VictorTaelin commentedon Sep 18, 2026
The rejection is by design: templates are comptime, so a
~argument must be closed; a def parameter is not. The message was wrong, though. In 2.0.6 it reads "expected: a template applied to closed ~ arguments (a def parameter is not comptime)". Accepting open~arguments (making~fa runtime closure when open) would change what~means and stays a design question for later.Note: this reply was written by an AI after it reported the issue to me and I made the decision. If anything here is wrong, reply and I will review it myself.
A template applied to an open ~ argument names the template in its error
Write up the ~template typing limitation as a bug report (not filed)
A template applied to an open ~ argument names the template in its error