refactor(semantic): Apply full type-based diagnostics to all signature parts.#10170
Conversation
…e parts. Introduce `add_value_type_based_diagnostics`, which reports a phantom type used as a value and otherwise delegates to `add_type_based_diagnostics`. Route function parameters, return types, implicits, expressions and closure signatures through it, so signatures now also surface the non-phantom type errors (e.g. infinite size) that were previously only caught in the body. Seed the signature's parameter, implicit and return types as already analyzed so the body no longer re-diagnoses them, and drop the now-redundant inline phantom checks scattered across the constructor and signature paths.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
PR SummaryLow Risk Overview Call sites in function signatures (params, return, implicits), closures, and post-inference expression rewriting now use the helper instead of ad-hoc Several redundant phantom checks are removed (enum variant ctor, struct ctor, duplicate inline phantom reporting in expression paths). Snapshot tests drop extra E2019 on parameter use sites, keeping one diagnostic per value position. Reviewed by Cursor Bugbot for commit 7151918. Bugbot is set up for automated code reviews on this repo. Configure here. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 7151918. Configure here.
TomerStarkware
left a comment
There was a problem hiding this comment.
@TomerStarkware reviewed 5 files and all commit messages, and made 1 comment.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on eytan-starkware and orizi).


Summary
Introduces
add_value_type_based_diagnostics, a new function that wrapsadd_type_based_diagnosticsand additionally rejects phantom types when they appear in value positions (parameters, return types, implicit parameters, closure params, and expressions). The existingadd_type_based_diagnosticsis now reserved for type definition contexts (struct members, enum variants) where phantom types are permitted.Previously, phantom type checks were scattered across multiple call sites —
compute.rs,functions.rs, andcompute_expr_closure_semantic— each manually callingis_phantomand reportingInstancesOfPhantomTypesbefore or after callingadd_type_based_diagnostics. This also caused duplicate diagnostics: for example, a phantom type used as a function parameter would be reported both at the signature site and again when the parameter expression was analyzed.Type of change
Please check one:
Why is this change needed?
Phantom type diagnostics were being emitted multiple times for the same usage. For instance, using
Option<Ph>as a parameter type would produce anE2019error at the signature and a second one at the expression referencing the parameter. The fix consolidates phantom type checking intoadd_value_type_based_diagnostics, which is called at the canonical location for each value position, eliminating the duplicate reports.What was the behavior or documentation before?
Using a phantom type in a function parameter, return type, or expression could produce multiple
E2019: Phantom types cannot be instantiateddiagnostics pointing to different locations for the same underlying type usage.What is the behavior or documentation after?
Each phantom type usage in a value position produces exactly one
E2019diagnostic, reported at the most specific and relevant source location (the parameter, return type annotation, or expression site). Theanalyzed_typesset inapply_inference_rewriteris pre-seeded with types from the function signature so that expression-level checks do not re-report errors already covered by the signature.Related issue or discussion (if any)
N/A
Additional context
The
add_type_based_diagnosticsfunction is retained for use in type definition contexts where phantom types are valid. The newadd_value_type_based_diagnosticsfunction short-circuits toInstancesOfPhantomTypesif the type is phantom, and otherwise delegates toadd_type_based_diagnosticsfor structural checks (infinite-size types, arrays of zero-sized or phantom elements).