Repository navigation
Give list items past the end of the expected pairs the item before's type - #446
Merged
Rigidity merged 1 commit intoNov 19, 2026
Conversation
…type An item of a list literal past the end of the pairs its expected type has, where that type ends in `nil`, gets the type the item before it was expected to be: the expected type is often another list literal's inferred type, which only has as many items as that literal, such as `(2, nil)` for `[2]`, and that's what the type would be as a `List`. So `first(([2], [3, make()]))` compiles, with `make()` as `2`, where only `first::<List<Int>>` did. A list expected to be a type of its own that ends there can't be longer anyway, so this only matters for lists whose expected type is a hint, and a call with arguments there still infers its generics from them. An expected type that goes on as something other than `nil`, such as `(Int, Any)`, isn't the end of a list, and is left as it was.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #362 (step 13e, layer 7 of 9).
An item of a list literal past the end of the pairs its expected type has gets the type the item before it was expected to be, if the remaining expected type ends in
nil. The expected type is often another list literal's inferred type, which only has as many items as that literal, such as(2, nil)for[2], and that's what the type would be as aList. Sofirst(([2], [3, make()]))compiles, withmake()as2; on main, onlyfirst::<List<Int>>compiled.optional(nil)there isnil. Both cases pin their inferred types through a binding.nil, such as(Int, Any), isn't the end of a list.[1, make()]there still can't infermake, as on main, and that's pinned ingeneric_inference_element_bounds_errors.The stack (#362 step 13e, layers 6–9)
These layers close the gaps that the merged 13e layers (#438–#442) left, so the generics campaign ends with no follow-ups. Each layer is its own PR:
6. An argument's expected type counts when it's what the call's solution has to be:
wrap(map(fn(x) => x, 5))with(5, Int)expected.7. List items past the end of the expected pairs:
first(([2], [3, make()])).8. Struct fields and inner pairs keep a lambda parameter's generic references.
9. A lambda's shared or caller generics are instantiated when its body captures none of their values: the soundness limits that 13e pinned.
Fuzzer, per layer.
infer-fuzz --compareagainst baselines from main6aea07a5, on all four configurations (generators 1 and 2, seeds0..4000and4000..8000). Every layer has 0 regressions and 0 unsound variants, changes no variant that main infers, and leaks no{generic N}. Newly inferred variants, cumulative: 37 (6), 40 (7), 40 (8), 143 (9). The top PR has the full table.Breaking changes. None. No program that compiles on main changes its type, CLVM output or diagnostics. Pinned errors that now compile get the type that explicit instantiation gives, and each is a test.
Review. Three rounds:
Any; it's limited to a real list end now.T(x as T), so a value escaped with the wrong type. It's fixed, and pinned innames_the_callers_generic.one_of_two_lambdas_captures.Mutant rule. Every mutant ran in a scratch worktree, under
timeout 120, after a separate build step.Note
Medium Risk
This changes which types are inferred for calls with lambda arguments, list literals and field accesses, all in the compiler's call inference. A mistake would reject valid programs or accept unsound ones. The risk is limited by these points:
Changes by area:
call_inference.rs: the hint rule for an argument's expected type; which lambda parameters are instantiated (generic_parameter_types,names_restored_generics); instantiation in the alternative solve.lambda.rs:LambdaParameterandLambdaBody::captures_generics.list.rs: items past the end of the expected pairs.field.rs:wrapped_atandkeeps_reference.compiler.rs:ArgumentFrame::lambda_parametersholdsLambdaParameters.rue-hir/database.rs:next_hir_id,hirs_betweenandsymbol_count.tests/types/generic_inference_*: new tests and moved pins.