Repository navigation
Type-argument arity is unchecked in BOTH directions in alias_chain_type_arg_subst — a floor-band bijection failure where correct and incorrect compile identically #9585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4ebe478
Refuse a generic application whose type-argument count disagrees with…
e26952d
Judge type-argument arity only where the carrier is a use-site leaf
4d6facb
Merge remote-tracking branch 'origin/main' into session/nimble-crab-536
7550f25
Merge remote-tracking branch 'origin/main' into session/nimble-crab-536
355485c
Regenerate the infer mirror from the merged authority (branch cleanup…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| module test.claim.type_argument_arity_witness | ||
|
|
||
| import std.types { String, Bool, Int, List } | ||
| import v2.std.live_tree { LiveTreeDisposition, SubstrateInputsOnly } | ||
| import tools.multi_module_compile_fixture { | ||
| MultiModuleCompileFixture, | ||
| MultiModuleCompileFixtureOutcome, | ||
| FixtureInstrumentRefused, | ||
| FixtureCompileRefused, | ||
| FixtureCompileCompleted, | ||
| FixtureSource, | ||
| fixture_source, | ||
| compile_fixture, | ||
| fixture_blocking_rows, | ||
| fixture_has_class | ||
| } | ||
|
|
||
| data live_tree_disposition: LiveTreeDisposition = SubstrateInputsOnly | ||
|
|
||
| // THE SUBJECT. v1.compiler.infer alias_chain_type_arg_subst folded a generic declaration's | ||
| // PARAMETERS against a use site's supplied TYPE ARGUMENTS positionally and absorbed a | ||
| // disagreement in BOTH directions: a surplus argument was never read, and a missing argument | ||
| // left its parameter unsubstituted so the expanded record kept a type-variable field. Neither | ||
| // state produced a diagnostic anywhere, so a correct application and an arity-wrong one | ||
| // compiled identically -- the floor band's exact-bijection rule failing silently, which | ||
| // DESIGN section 4b calls a below-baseline safety regression rather than a missing feature. | ||
| // | ||
| // The one call site that noticed widened a `lossy` flag that stood the field-presence wall | ||
| // DOWN instead of refusing -- the absorbing fallback of DESIGN section 5, whose deficit | ||
| // frequency is zero by construction. That flag is deleted with this wall (section 4b(4) | ||
| // dissolution on climb: the proof replaces the degradation rather than accumulating beside it), | ||
| // and the evidence that the higher rung is real is exactly the two REDs and the control below. | ||
| // | ||
| // WHY THE ISOLATED FIXTURE. The RED is an invalid program, so it is authorable only where a | ||
| // fixture hands source to the compiler -- never in the accepted corpus. A single module | ||
| // expresses the whole subject, but tools.multi_module_compile_fixture is used rather than the | ||
| // live-tree census because it compiles a caller-authored manifest in isolation, which is what | ||
| // lets this witness declare SubstrateInputsOnly truthfully and therefore actually execute on | ||
| // the required floor. | ||
|
|
||
|
|
||
| data surplus_source: String = "module ta.entry\ntype TaBoxed<T> { item: T }\ntype TaPair<A, B> { left: A, right: B }\nfn ta_surplus(b: TaBoxed<Int, String>) -> Int { b.item }\n" | ||
| data deficit_source: String = "module ta.entry\ntype TaBoxed<T> { item: T }\ntype TaPair<A, B> { left: A, right: B }\nfn ta_deficit(p: TaPair<Int>) -> Int { p.left }\n" | ||
| data green_source: String = "module ta.entry\ntype TaBoxed<T> { item: T }\ntype TaPair<A, B> { left: A, right: B }\nfn ta_one(b: TaBoxed<Int>) -> Int { b.item }\nfn ta_two(p: TaPair<Int, String>) -> Int { p.left }\n" | ||
|
|
||
| fn arity_run(source: String) -> MultiModuleCompileFixtureOutcome { | ||
| compile_fixture(MultiModuleCompileFixture { | ||
| sources: [fixture_source("ta/entry.dag", source)], | ||
| entry: "ta/entry.dag" | ||
| }) | ||
| } | ||
|
|
||
| fn refused_with_class(o: MultiModuleCompileFixtureOutcome, wanted: String) -> Bool { | ||
| match o { | ||
| FixtureCompileRefused { module_count: n, diagnostics: rows, source_digest: sd, compiler_digest: cd } => | ||
| fixture_has_class(rows, wanted) && count(fixture_blocking_rows(rows)) > 0, | ||
| FixtureCompileCompleted { module_count: n, emitted_files: files, diagnostics: rows, source_digest: sd, compiler_digest: cd } => false, | ||
| FixtureInstrumentRefused { cause: c } => false | ||
| } | ||
| } | ||
|
|
||
| fn completed_with_no_diagnostics(o: MultiModuleCompileFixtureOutcome) -> Bool { | ||
| match o { | ||
| FixtureCompileCompleted { module_count: n, emitted_files: files, diagnostics: rows, source_digest: sd, compiler_digest: cd } => | ||
| count(rows) == 0 && count(files) > 0 && n > 0, | ||
| FixtureCompileRefused { module_count: n, diagnostics: rows, source_digest: sd, compiler_digest: cd } => false, | ||
| FixtureInstrumentRefused { cause: c } => false | ||
| } | ||
| } | ||
|
|
||
| // DISCRIMINATING RED, DIRECTION ONE: more type arguments than the declaration has parameters. | ||
| // The class name is asserted, not merely "something refused" -- a typo in the fixture source | ||
| // would satisfy the weaker reading. | ||
| test fn surplus_type_argument_refuses() -> Bool { | ||
| refused_with_class(arity_run(surplus_source), "TypeArgumentArityMismatch") | ||
| } | ||
|
|
||
| // DISCRIMINATING RED, DIRECTION TWO: fewer type arguments than parameters. Authored separately | ||
| // from the surplus arm because the two absorbed through DIFFERENT mechanisms -- the surplus | ||
| // argument was never read, the missing one left a parameter unsubstituted -- so one arm is not | ||
| // evidence about the other. | ||
| test fn deficit_type_argument_refuses() -> Bool { | ||
| refused_with_class(arity_run(deficit_source), "TypeArgumentArityMismatch") | ||
| } | ||
|
|
||
| // THE POSITIVE CONTROL. The same declarations applied at their declared arity compile clean -- | ||
| // zero diagnostics of ANY severity. Without this the REDs above are satisfied by a wall that | ||
| // refuses every generic application. | ||
| test fn matched_type_argument_arity_compiles_clean() -> Bool { | ||
| completed_with_no_diagnostics(arity_run(green_source)) | ||
| && !refused_with_class(arity_run(green_source), "TypeArgumentArityMismatch") | ||
| } |
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a wrong-arity application appears only in a type annotation and is never dereferenced (for example,
fn f(b: TaBoxed<Int, String>) -> Int { 0 }), inference never callsexpand_type_for_field_access, which is the only path invokingalias_chain_arity_diagnostics. The compiler therefore still accepts and emits such invalid applications; both new negative fixtures conceal this gap by accessing.itemor.left. Run this validation while traversing every authored type application rather than only during field lookup.Useful? React with 👍 / 👎.