fix: unwrap cast receivers in CC027 lifetime analysis#39
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b89799d1c0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| case CastExpressionSyntax cast: | ||
| expression = cast.Expression; |
There was a problem hiding this comment.
Do not unwrap user-defined cast conversions
When a using-declared type has a user-defined conversion to another object, unconditionally unwrapping the cast reports CC027 even though the converted object—not the disposable local—is the invocation receiver. For example, return ((Worker)resource).DoAsync(); is safe when an explicit conversion creates an independent Worker, but this walk resolves resource and emits a false positive. Only unwrap identity/reference casts such as the intended base/interface conversions, and stop when the conversion invokes a user-defined operator.
Useful? React with 👍 / 👎.
Verdict
CC027 now diagnoses a returned async call made through an interface or base-type cast of a
using-scoped resource; the cast does not extend the resource lifetime.Evidence
((IResource)resource).DoAsync().CastExpressionSyntaxbefore resolving the using local.command not found).Next action
Merge after required CI passes, then publish and verify v1.27.184.