-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[ty] Don't include already-bound legacy typevars in function generic context #19558
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
Conversation
|
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.
Looks good!
db: &'db dyn Db, | ||
module: &ParsedModuleRef, | ||
index: &SemanticIndex<'db>, | ||
scope: FileScopeId, |
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.
Related to above, I'd suggest instead of taking module
or index
we might just take a File
here.
Or take only a ScopeId
, which encompasses a File
and a FileScopeId
.
I guess the one argument in favor of taking module
and index
is that it kind of makes it explicit that this method has a dependency on the AST of the module containing scope
. But I'm not sure how obvious this is; it's not the way we've typically handled this.
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.
Done.
I guess the one argument in favor of taking
module
andindex
is that it kind of makes it explicit that this method has a dependency on the AST of the module containingscope
.
That wasn't my intent, and I think it's an open question how we want to model that better more generally, so I'm going with the simpler function signatures that you've suggested
@@ -385,6 +385,47 @@ pub(crate) fn nearest_enclosing_class<'db>( | |||
}) | |||
} | |||
|
|||
/// Returns in iterator of any generic context introduced by the given scope or any enclosing |
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.
infer.rs
is already massive with TypeInferenceBuilder
and the various *Inference
structs. Is it the best place for these new free functions? Seems like they kind of would belong in generics.rs
.
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.
Moved. That also let me make them file-local instead of pub(crate)
Co-authored-by: Carl Meyer <[email protected]>
* main: [ty] Added support for "document symbols" and "workspace symbols" (#19521) Add `TextEmitter::with_color` and disable colors in `unreadable_files` test (#19562) [ty] Added support for document highlights in playground. (#19540) [`refurb`] Ignore decorated functions for `FURB118` (#19339) [ty] Add workflow to comment diagnostic diff for conformance tests (#19556)
Co-authored-by: Alex Waygood <[email protected]>
We now correctly exclude legacy typevars from enclosing scopes when constructing the generic context for a generic function.
more detail:
A function is generic if it refers to legacy typevars in its signature:
Generic functions are allowed to appear inside of other generic contexts. When they do, they can refer to the typevars of those enclosing generic contexts, and that should not rebind the typevar:
This substitution was already being performed correctly, but we were also still including the enclosing legacy typevars in the method's own generic context, which can be seen via
ty_extensions.generic_context
(which has been updated to work on generic functions and methods):