Skip to content

fix: unwrap cast receivers in CC027 lifetime analysis#39

Merged
georgepwall1991 merged 1 commit into
masterfrom
fix/cc027-cast-receiver
Jul 21, 2026
Merged

fix: unwrap cast receivers in CC027 lifetime analysis#39
georgepwall1991 merged 1 commit into
masterfrom
fix/cc027-cast-receiver

Conversation

@georgepwall1991

Copy link
Copy Markdown
Owner

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

  • Red-first regression reproduced the false negative with ((IResource)resource).DoAsync().
  • Receiver walking now unwraps CastExpressionSyntax before resolving the using local.
  • Direct receiver, using-statement, completed-task argument, alias, and unrelated-task behavior remains green.
  • Release build: 62 intentional sample diagnostics, 0 errors.
  • Tests: 641 passed, 0 failed.
  • Touched-file whitespace verification passed.
  • NuGet package v1.27.184 contains both analyzer assemblies and no dependency groups.
  • Self-review: no actionable findings.
  • Slopwatch was attempted after code changes but is unavailable on this host (command not found).
  • Per explicit instruction, no Claude review was used.

Next action

Merge after required CI passes, then publish and verify v1.27.184.

@georgepwall1991
georgepwall1991 merged commit 1053124 into master Jul 21, 2026
1 check passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +172 to +173
case CastExpressionSyntax cast:
expression = cast.Expression;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant