GeezerVison is showing github.com — Handle arrays and casts in ValidateRange type-mismatch warnings by Copilot · Pull Request #2273 · PowerShell/PSScriptAnalyzer
Conversation
Copilot
AI
commented
Oct 28, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
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)
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Copilot
AI
changed the title
[WIP] Fix code based on review comments
Handle arrays and casts in ValidateRange type-mismatch warnings
Oct 28, 2026
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.
🟢 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
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Copilot why not keep existing test case for decimal type?
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
🟢 Approval recommended
No active review issues were identified for the expanded ValidateRange type-mismatch checks.
No open issues 🎉
Review effort: Balanced
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|