-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Rust: Fix type inference for library parameters #19658
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
base: main
Are you sure you want to change the base?
Conversation
bec542f
to
c4d46f2
Compare
c4d46f2
to
07fe1bf
Compare
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.
Pull Request Overview
This PR fixes type inference for library parameters by switching from pattern-based inference to using explicit type representations, updates related test expectations for Pin
methods, and renames a debug helper to match its new signature.
- Replace
inferAnnotatedType
on parameter patterns withTypeMention.resolveTypeAt
for library parameters - Adjust modeled dataflow tests and expected outputs to account for
into_inner_unchecked
- Rename
debugResolveMethodCallExpr
to acceptMethodCall
instead ofMethodCallExpr
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
rust/ql/test/library-tests/dataflow/modeled/main.rs | Reorder imports and update test comment for Pin::into_inner_unchecked |
rust/ql/test/library-tests/dataflow/modeled/inline-flow.expected | Update expected model entries and edge labels |
rust/ql/lib/codeql/rust/internal/TypeInference.qll | Use TypeMention.resolveTypeAt for parameter types and rename debug function signature |
Comments suppressed due to low confidence (1)
rust/ql/test/library-tests/dataflow/modeled/main.rs:98
- [nitpick] These two imports from
std::pin
could be combined into a single statement:use std::pin::{pin, Pin};
for clarity and conciseness.
use std::pin::pin;
@@ -569,7 +569,7 @@ private module CallExprBaseMatchingInput implements MatchingInputSig { | |||
exists(Param p, int i, boolean inMethod | | |||
paramPos(this.getParamList(), p, i, inMethod) and | |||
dpos = TPositionalDeclarationPosition(i, inMethod) and | |||
result = inferAnnotatedType(p.getPat(), path) | |||
result = p.getTypeRepr().(TypeMention).resolveTypeAt(path) |
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.
The unchecked cast to TypeMention
may fail if a parameter's TypeRepr
isn't a TypeMention
. Consider adding a guard (e.g., instanceof TypeMention
) or using a safe resolution method to avoid runtime errors.
Copilot uses AI. Check for mistakes.
Function debugResolveMethodCallExpr(MethodCallExpr mce) { | ||
mce = getRelevantLocatable() and | ||
result = resolveMethodCallTarget(mce) | ||
Function debugResolveMethodCallExpr(MethodCall mc) { |
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.
[nitpick] The debug function signature and parameter name changed from MethodCallExpr
/mce
to MethodCall
/mc
. Consider updating any related comments or docs to prevent confusion when maintaining this helper.
Function debugResolveMethodCallExpr(MethodCall mc) { | |
Function debugResolveMethodCall(MethodCall mc) { |
Copilot uses AI. Check for mistakes.
The old logic relied on parameters having a pattern, which is not the case for parameters extracted from library code.
The updated test output reveals that we do not handle operator calls correctly. For example,
i32
implements bothAdd
andAdd<Rhs = &i32>
, and currently we resolve1 + 2
to bothadd
methods, which means that2
will have reverse-propagated type&i32
in addition toi32
.