Skip to content

Preserve expected types for generic constructor arguments - #1621

Closed
sebastian-griego wants to merge 1 commit into
bendlang:mainfrom
sebastian-griego:fix/safe-constructor-expected-types
Closed

sebastian-griego wants to merge 1 commit into
bendlang:mainfrom
sebastian-griego:fix/safe-constructor-expected-types

Conversation

@sebastian-griego

Copy link
Copy Markdown
Contributor

Generic constructor arguments can pass Bend's source checker but fail
--verdict. During BendTT export, arg_term does not pass their expected type
to ctr_term. Generic fields then use placeholder datatype parameters. This
can assign the wrong quantity to a lambda or leave a call through a bound
function without a known type.

Pass the existing expected type to unannotated constructor arguments through
the annotation path already used for lambdas and matches. ctr_term can then
use the datatype parameters to instantiate each field type. Existing explicit
annotations remain in use.

Add two proof tests:

  • generic_constructor_erased_lambda.bend compares Box{x => Type} values at
    Box<@-x: Type -> Type>. The expected field type requires an erased lambda
    binder. Before this change, export gives it a live binder.
  • generic_constructor_dependent_function.bend stores a function in a generic
    constructor field. Its result type depends on an earlier field. Before
    this change, export loses the type needed for a call through its argument.

Both tests pass source checking before and after the change. Both fail
--verdict before the change and pass after it with the unchanged BendTT
kernel. The local safety-gate run covers all 1,652 existing upstream files
and retains every baseline classification. This was a local gate run, not
a full CI run. With CI's ttok 0.3, safe.ts uses 23,986 of its 24,000 tokens.

The local repository gate reports one existing failure: bend2/comp.ts uses
64,092 tokens against its 64,000-token limit. The file is unchanged from
main (234cb9b), where it has the same count. All other repository rules
pass.

@sebastian-griego

Copy link
Copy Markdown
Contributor Author

Closing as a duplicate of #1620. Both PRs make the same change to safe.ts. I missed the earlier PR. I will offer the two additional regression tests on #1620.

ScottMoore0 added a commit to ScottMoore0/bend that referenced this pull request Oct 16, 2026
…function type (bendlang#1619)

Two more tests for a bare constructor in a type losing its goal: a
lambda in a generic Box at @-x: Type -> Type (the kernel reported "a λ of
its binder's liveness"), and a field whose type depends on an earlier
field (export reported "an application past its head's known type" and
--verdict rejected the file). Both pass with the fix in this PR.
Written by Sebastian Griego in bendlang#1621.

Co-authored-by: Sebastian Griego <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant