From db054b6a37c83c938f17090d95a326633dd104c7 Mon Sep 17 00:00:00 2001 From: Fanboynz Date: Tue, 1 Sep 2026 23:12:36 +1200 Subject: [PATCH] analytics: do not claim a twin with a Swift stdlib method I wrote this yesterday in #1785: /** `a - b`, or null when it would overflow. The Long twin of Swift's `subtractingReportingOverflow`. */ subtractingReportingOverflow is Swift STDLIB on FixedWidthInteger, not a declaration in this repository. So the reference resolves to nothing: a reader chasing it finds no such function here, and neither does an audit. Found by the parity ledger in #1534, which reported it as a dead-twin-reference within minutes of being run against a merged tree - and the same PR fixes the identical mistake in AICoach.swift, where "the twin of Kotlin's LocalDate.now().toEpochDay()" became "Kotlin computes the same value with". Two of us made it independently, which says the phrasing is easy to reach for. Reworded to say what is true: Apple expresses the same contract with that method, and it is stdlib rather than a twin. The file's PARITY note a few lines up already had this right - it contrasts Math.subtractExact with subtractingReportingOverflow without claiming a pairing - so this only brings the one line into line with the rest of the file. Fixed rather than baselined, deliberately: accepting it as known debt would launder a defect I introduced into the accepted set. Verified against the #1534 ledger that this specific finding is gone. --- .../java/com/noop/analytics/PreSleepHeartRateFeedback.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/android/app/src/main/java/com/noop/analytics/PreSleepHeartRateFeedback.kt b/android/app/src/main/java/com/noop/analytics/PreSleepHeartRateFeedback.kt index bf97270fe0..d120d3fdb2 100644 --- a/android/app/src/main/java/com/noop/analytics/PreSleepHeartRateFeedback.kt +++ b/android/app/src/main/java/com/noop/analytics/PreSleepHeartRateFeedback.kt @@ -236,7 +236,14 @@ object PreSleepHeartRateFeedback { ) } - /** `a - b`, or null when it would overflow. The Long twin of Swift's `subtractingReportingOverflow`. */ + /** + * `a - b`, or null when it would overflow. + * + * NOT a twin claim, though it reads like one and originally said so. Apple expresses the same + * contract with `subtractingReportingOverflow`, which is Swift STDLIB on `FixedWidthInteger` and + * therefore not a declaration in this repository at all — so a reader chasing the reference finds + * nothing, and a parity audit resolves it to nothing either. + */ private fun subtractOrNull(a: Long, b: Long): Long? = try { Math.subtractExact(a, b) } catch (_: ArithmeticException) { null }