Skip to content

Conversation

Copy link

Copilot AI commented Jan 30, 2026

Issue

The Abs() function in builtin/lib.go contained unreachable conditional branches for unsigned integer types. Unsigned integers cannot be negative, yet the code checked if x < 0 before returning.

case uint:
    if x < 0 {      // Always false - uint cannot be < 0
        return -x   // Unreachable
    } else {
        return x
    }

This pattern was repeated for uint, uint8, uint16, uint32, and uint64.

Changes

  • builtin/lib.go: Removed impossible conditional checks for all unsigned integer types, simplified to direct return
  • builtin/builtin_test.go: Added test coverage for all unsigned integer types including edge case of zero values

Result

case uint:
    return x
case uint8:
    return x
// etc.

Eliminates 20 lines of dead code, improves clarity, and removes a potential source of confusion for maintainers.

Original prompt

Find bugs


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits January 30, 2026 15:09
Co-authored-by: antonmedv <141232+antonmedv@users.noreply.github.com>
Co-authored-by: antonmedv <141232+antonmedv@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix bugs found during code review Fix impossible unsigned integer comparisons in Abs() function Jan 30, 2026
Copilot AI requested a review from antonmedv January 30, 2026 15:17
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.

2 participants