Skip to content

fix #25608; improve implicit range conversion checks#25838

Open
ringabout wants to merge 2 commits into
develfrom
pr_mm
Open

fix #25608; improve implicit range conversion checks#25838
ringabout wants to merge 2 commits into
develfrom
pr_mm

Conversation

@ringabout
Copy link
Copy Markdown
Member

fix #25608

This pull request improves how the compiler handles warnings for implicit range conversions, ensuring that only non-constant values trigger downsizing warnings. It also adds new test cases to verify that assignments and function calls involving compile-time constants do not produce unnecessary warnings.

Improvements to range conversion warnings:

  • Updated the logic in compiler/sempass2.nim to skip implicit range conversion warnings for compile-time constants by checking if an expression is constant with getConstExpr. Now, only non-constant values will trigger the warning.

Testing enhancements:

  • Added new test cases in tests/range/timplicitrangedownsizing.nim to confirm that assignments and function calls with constant enum and integer values do not trigger downsizing warnings.

Copilot AI review requested due to automatic review settings May 26, 2026 15:00
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 fixes #25608 by refining the compiler’s implicit range conversion warning logic so that compile-time constants do not trigger downsizing warnings, and it extends the existing range-warning test to cover constant assignments/calls.

Changes:

  • Update compiler/sempass2.nim to suppress ImplicitRangeConversion warnings when the converted expression is a compile-time constant (via getConstExpr).
  • Add test coverage ensuring constant enum/int values assigned/passed to range types don’t trigger downsizing warnings.

Reviewed changes

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

File Description
compiler/sempass2.nim Suppresses implicit range conversion warnings for compile-time constants during effect tracking.
tests/range/timplicitrangedownsizing.nim Adds cases for constant enum/int values to ensure no ImplicitRangeConversion warnings are emitted.

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

Comment thread compiler/sempass2.nim Outdated
Comment thread tests/range/timplicitrangedownsizing.nim
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.

ImplicitRangeConversion does not recognize constants

2 participants