[ty] impl VarianceInferable for KnownInstanceType#20924
[ty] impl VarianceInferable for KnownInstanceType#20924sharkdp merged 2 commits intoastral-sh:mainfrom
VarianceInferable for KnownInstanceType#20924Conversation
Diagnostic diff on typing conformance testsNo changes detected when running ty on typing conformance tests ✅ |
|
| } | ||
| } | ||
|
|
||
| pub(crate) fn raw_value_type(self, db: &'db dyn Db) -> Type<'db> { |
There was a problem hiding this comment.
Can we please document what raw_value_type does compared to value_type?
More importantly, value_type has fixpoint handling, but raw_value_type does not. Does this lead to problems with recursive type aliases?
There was a problem hiding this comment.
raw_value_type is called by KnownInstanceType::variance_of except within the queried value_type.
As already explained, KnownInstanceType::variance_of is not normally called. In current usage, the only time it may be called is during a hover request.
Clearly, the type inference functions that raw_value_type depends on never call a hover request. Therefore, in current usage, there is no possibility of infinite recursion.
For safety, I added a note that raw_value_type is not tracked, so that anyone using it in the future knows to be careful.
sharkdp
left a comment
There was a problem hiding this comment.
Thank you for the update and the explanations!
Summary
Derived from #20900
Implement
VarianceInferableforKnownInstanceType(especially forKnownInstanceType::TypeAliasType).The variance of a type alias matches its value type. In normal usage, type aliases are expanded to value types, so the variance of a type alias can be obtained without implementing this. However, for example, if we want to display the variance when hovering over a type alias, we need to be able to obtain the variance of the type alias itself (cf. #20900).
Test Plan
I couldn't come up with a way to test this in mdtest, so I'm testing it in a test submodule at the end of
types.rs.I also added a test to
mdtest/generics/pep695/variance.md, but it passes without the changes in this PR.