Skip to content

Handle arrays and casts in ValidateRange type-mismatch warnings - #2273

Merged
Christoph Bergmeister (bergmeister) merged 3 commits into
copilot/validate-range-boundary-checkfrom
copilot/fix-code-for-comments
Oct 28, 2026
Merged

Christoph Bergmeister (bergmeister) merged 3 commits into
copilot/validate-range-boundary-checkfrom
copilot/fix-code-for-comments

Conversation

Copilot AI commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Integral ValidateRange bounds can allow out-of-range fractional values on double, single, and decimal parameters. The warning now covers array parameters and cast bounds while avoiding mixed-bound false positives.

  • Detection: Check array element types, resolve cast target types (including aliases), and warn only when both bounds are integral.
  • Regression coverage: Add cases for arrays, casts, aliases, and mixed bounds.
# Warns: array elements use integral boundaries
param([double[]][ValidateRange([int]0.0, [int32]100.0)]$Values)

# No warning: mixed bounds avoid the fractional-boundary issue
param([double][ValidateRange(1, 2.0)]$Value)

Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix code based on review comments Handle arrays and casts in ValidateRange type-mismatch warnings Oct 28, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are recorded for the expanded range-type detection and mixed-bound exclusions.

No open issues 🎉

What changed in this PR

Updates AvoidValidateRangeTypeMismatch to detect integral range bounds on floating-point and decimal array parameters and cast expressions, while avoiding mixed-bound false positives.

Changes:

  • Resolve parameter and cast types through reflection, including aliases, and inspect array element types.
  • Require both range bounds to be integral before warning.
  • Add regression cases for arrays, casts, aliases, and mixed bounds.
File Description
Tests/​Rules/​AvoidValidateRangeTypeMismatch.tests.ps1 Adds regression coverage for expanded detection and mixed-bound exclusions.
Rules/​AvoidValidateRangeTypeMismatch.cs Updates type resolution, array handling, and boundary checks.

Review effort: Balanced

@bergmeister
Christoph Bergmeister (bergmeister) marked this pull request as ready for review October 28, 2026 12:15
@bergmeister

Copy link
Copy Markdown
Collaborator

Copilot why not keep existing test case for decimal type?

Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com>

Copilot AI commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

Copilot why not keep existing test case for decimal type?

The prior decimal case used mixed bounds (1, 2.0), which should now be excluded. I restored decimal positive coverage with integral bounds (1, 2) in commit 09de08a.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified for the expanded ValidateRange type-mismatch checks.

No open issues 🎉

Review effort: Balanced

@bergmeister
Christoph Bergmeister (bergmeister) marked this pull request as ready for review October 28, 2026 12:31
@bergmeister
Christoph Bergmeister (bergmeister) merged commit 117fa6b into copilot/validate-range-boundary-check Oct 28, 2026
8 checks passed
@bergmeister
Christoph Bergmeister (bergmeister) deleted the copilot/fix-code-for-comments branch October 28, 2026 13:12
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.

3 participants