Skip to content

Commit 26fd232

Browse files
committed
fix(fiat): don't enforce same currencies in plus/minus whe modifying with Zero
Signed-off-by: Brandon McAnsh <[email protected]>
1 parent 724ef8a commit 26fd232

File tree

1 file changed

+2
-0
lines changed
  • services/opencode/src/main/kotlin/com/getcode/opencode/model/financial

1 file changed

+2
-0
lines changed

services/opencode/src/main/kotlin/com/getcode/opencode/model/financial/Fiat.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,13 @@ data class Fiat(
180180

181181
// Operator overloads
182182
operator fun Fiat.plus(other: Fiat): Fiat {
183+
if (other.decimalValue == 0.0) return this
183184
require(currencyCode == other.currencyCode) { "Cannot add different currencies" }
184185
return Fiat(quarks = this.quarks + other.quarks, currencyCode = currencyCode)
185186
}
186187

187188
operator fun Fiat.minus(other: Fiat): Fiat {
189+
if (other.decimalValue == 0.0) return this
188190
require(currencyCode == other.currencyCode) { "Cannot subtract different currencies" }
189191
return Fiat(quarks = this.quarks - other.quarks, currencyCode = currencyCode)
190192
}

0 commit comments

Comments
 (0)