Skip to content

Detect 'Is.NaN' with unsupported types.#942

Merged
manfred-brands merged 2 commits intomasterfrom
Issue929_NaN
Oct 31, 2025
Merged

Detect 'Is.NaN' with unsupported types.#942
manfred-brands merged 2 commits intomasterfrom
Issue929_NaN

Conversation

@manfred-brands
Copy link
Copy Markdown
Member

Fixes #929

@mikkelbu mikkelbu requested a review from Copilot October 30, 2025 21:34
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances the EqualToIncompatibleTypes analyzer to detect when Is.NaN or Is.Not.NaN constraints are used with non-floating-point types (e.g., int, decimal, string). Since only float and double types support NaN values, using this constraint with other types will always fail and represents a test logic error.

Key Changes:

  • Added detection logic for Is.NaN constraint usage with unsupported types
  • Added null-safety checks and nullable type unwrapping for the actual type
  • Added comprehensive test coverage for both valid and invalid uses of Is.NaN

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/nunit.analyzers/EqualToIncompatibleTypes/EqualToIncompatibleTypesAnalyzer.cs Implements null-safety checks, nullable type unwrapping, and detection logic for Is.NaN used with non-float/double types
src/nunit.analyzers.tests/EqualToIncompatibleTypes/EqualToIncompatibleTypesAnalyzerTests.cs Adds test cases validating the analyzer correctly allows Is.NaN with float/double/nullable double and flags usage with decimal, int, and string
documentation/NUnit2021.md Documents the new detection capability with an example of invalid NaN testing on integer types

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Member

@mikkelbu mikkelbu left a comment

Choose a reason for hiding this comment

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

Nice and simple solution (simpler than I would have expected). I've only added a couple of comments, but I'm happy to merge it when you are

@mikkelbu mikkelbu added this to the Release 4.12 milestone Oct 30, 2025
@manfred-brands manfred-brands merged commit bff7b5c into master Oct 31, 2025
6 checks passed
@manfred-brands manfred-brands deleted the Issue929_NaN branch October 31, 2025 07:12
@mikkelbu mikkelbu modified the milestones: Release 4.12, Release 4.11.2 Nov 2, 2025
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.

Alert when using Is.NaN or Is.Not.NaN on an incompatible type

3 participants