DiceRoll sentinel value (-1) can display to user before roll() #78

Closed
opened 2026-04-04 18:39:51 +02:00 by shahondin1624 · 0 comments
Owner

Description

DiceRoll uses numberOfSuccesses: Int = -1 as a sentinel value. If UI code accidentally renders a DiceRoll before .roll() is called, the user sees "-1 successes". This is a code smell that could surface as a visible bug.

Files

  • sharedUI/src/commonMain/kotlin/org/shahondin1624/lib/functions/Dice.kt (lines 11-17)

Expected Behavior

  • Use a sealed type, nullable Int?, or require rolling at construction to make invalid states unrepresentable
  • UI should never be able to display a negative success count

Acceptance Criteria

  • DiceRoll cannot represent an un-rolled state that displays as a negative number
  • Existing dice roll tests pass
  • Roll result dialog handles the new type correctly
## Description `DiceRoll` uses `numberOfSuccesses: Int = -1` as a sentinel value. If UI code accidentally renders a `DiceRoll` before `.roll()` is called, the user sees "-1 successes". This is a code smell that could surface as a visible bug. ## Files - `sharedUI/src/commonMain/kotlin/org/shahondin1624/lib/functions/Dice.kt` (lines 11-17) ## Expected Behavior - Use a sealed type, nullable `Int?`, or require rolling at construction to make invalid states unrepresentable - UI should never be able to display a negative success count ## Acceptance Criteria - [ ] `DiceRoll` cannot represent an un-rolled state that displays as a negative number - [ ] Existing dice roll tests pass - [ ] Roll result dialog handles the new type correctly
shahondin1624 added the epic:dice-rollingpriority:should-havetype:bug labels 2026-04-04 18:39:51 +02:00
Sign in to join this conversation.