Skip to content

Potential fix for code scanning alert no. 34: Cast to same type#8

Merged
DoubledDoge merged 1 commit into
mainfrom
alert-autofix-34
Mar 8, 2026
Merged

Potential fix for code scanning alert no. 34: Cast to same type#8
DoubledDoge merged 1 commit into
mainfrom
alert-autofix-34

Conversation

@DoubledDoge
Copy link
Copy Markdown
Owner

Potential fix for https://github.com/DoubledDoge/typeguard/security/code-scanning/34

In general, to fix “cast to same type” issues, remove explicit casts where the compiler already knows the expression has the same type, relying on implicit typing and conversions instead. This keeps code clearer and avoids implying there is some special conversion or nullability change when there is not.

Here, on line 45 in src/TypeGuard.Winforms/WinFormsInput.cs, the expression (string?)_control.Invoke(() => _control.Text) is assigned to string? text. Since CodeQL has determined the static type of _control.Invoke(() => _control.Text) is string, the (string?) cast is unnecessary: a non-nullable string can be implicitly converted to string?. The best fix that preserves functionality is to remove only the cast and leave the rest of the expression as is. No new imports or helper methods are required. The edit is restricted to that single line inside the GetInput method.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

Simplification of datatype casting

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@DoubledDoge DoubledDoge marked this pull request as ready for review March 8, 2026 20:12
@DoubledDoge DoubledDoge merged commit 7bf2d3f into main Mar 8, 2026
7 checks passed
@DoubledDoge DoubledDoge deleted the alert-autofix-34 branch March 8, 2026 20:35
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