Repository navigation
Reject template arguments with unresolved operator namespaces - #841
Conversation
ce9c442 to
31d2633
Compare
…s as unsafe in the verdict (#841) A ( .. : T) around a template call renames the operators in its ~ arguments when it closes; the instance was built at the call's (, before that, with Nat's operators. The call now keeps its Ref and the instance is picked, and the Ref renamed in place, when the outermost term has been parsed. The parser expands templates and the checker takes that on trust, so until instances are built after parsing and checked against their arguments, a def that is an instance counts as unsafe: a file with a template prints no bare "All terms check."
|
Real, and fixed in 2.0.16 differently from the PR: a template instance is now picked when the outermost term has been parsed, after every enclosing 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. |
…on, and from nothing else The SYNTAX table gives the annotation to the operator expression it closes: (a + b : T) is T.add(a, b). The parser instead pushed every leading-dot operator on a book-wide stack, and a closing ( .. : T) renamed in place all of them pushed since the paren opened, through call arguments, lambda bodies, constructor fields and ~ arguments; the array literal and the index spliced the same stack; a template call was deferred (Parse.ts, Parse.lv) until the outermost term closed so that rename could still reach its ~ argument; and an operator no annotation reached fell back to Nat in term_higher. parse_term_ns now walks the annotated term through operator applications (grouping parens leave no node, so a chain passes through them) and names what it reaches; the stack, the deferral, its two fields and the Nat default are gone, and a template instance is built at its call again. An operator that no annotation names is refused at the operator, with the repair spelled with that operator. The corpus' 41 bare Nat sites (35 in tests, 3 in demos, 3 in evals) now carry ( .. : Nat), Synth.noise annotates its shifts at the operator, op_ns_late pinned the propagation and is deleted, and chain_default_nat pinned the default and is chain_nat_suffix. (#841)
…s as unsafe in the verdict (bendlang#841) A ( .. : T) around a template call renames the operators in its ~ arguments when it closes; the instance was built at the call's (, before that, with Nat's operators. The call now keeps its Ref and the instance is picked, and the Ref renamed in place, when the outermost term has been parsed. The parser expands templates and the checker takes that on trust, so until instances are built after parsing and checked against their arguments, a def that is an instance counts as unsafe: a file with a template prints no bare "All terms check."
…on, and from nothing else The SYNTAX table gives the annotation to the operator expression it closes: (a + b : T) is T.add(a, b). The parser instead pushed every leading-dot operator on a book-wide stack, and a closing ( .. : T) renamed in place all of them pushed since the paren opened, through call arguments, lambda bodies, constructor fields and ~ arguments; the array literal and the index spliced the same stack; a template call was deferred (Parse.ts, Parse.lv) until the outermost term closed so that rename could still reach its ~ argument; and an operator no annotation reached fell back to Nat in term_higher. parse_term_ns now walks the annotated term through operator applications (grouping parens leave no node, so a chain passes through them) and names what it reaches; the stack, the deferral, its two fields and the Nat default are gone, and a template instance is built at its call again. An operator that no annotation names is refused at the operator, with the repair spelled with that operator. The corpus' 41 bare Nat sites (35 in tests, 3 in demos, 3 in evals) now carry ( .. : Nat), Synth.noise annotates its shifts at the operator, op_ns_late pinned the propagation and is deleted, and chain_default_nat pinned the default and is chain_nat_suffix. (bendlang#841)
A template argument containing an infix operator could be specialized before an enclosing ( ... : T) expression resolved the operator namespace.
For example, ~Unit + Unit was specialized as Nat.add(Unit, Unit) even when the source expression later resolved it as Bar.add(Unit, Unit), allowing the checker to accept an invalid Empty inhabitant.
This change rejects template arguments that still contain unresolved operators and adds a regression test covering the issue. The existing operator-namespace check was updated to expect the new parse error.
PoC of the exploit here: Bend2 Wrong namespace operator