Skip to content

fix: avoid deprecated implicit Compare promotion for MoonBit v0.10.9 - #52

Merged
brickfrog merged 1 commit into
mainfrom
fix/compare-promotion-v0.10.9
Aug 26, 2026
Merged

fix: avoid deprecated implicit Compare promotion for MoonBit v0.10.9#52
brickfrog merged 1 commit into
mainfrom
fix/compare-promotion-v0.10.9

Conversation

@brickfrog

Copy link
Copy Markdown
Owner

derive(Compare) generates a trait impl, and v0.10.9 deprecated the implicit promotion of derived trait methods to type methods. The internal comparison helpers called self.compare(other), which relied on exactly that promotion, so the build emitted 18 [0020] deprecation warnings across Date, Time, and DateTimeis_before, is_after, min, max, and both clamp bounds on each.

Note that moon check stayed silent; only the moon test build path reported them.

Change

Every site had the shape self.compare(x) OP 0, so use the comparison operators directly:

self.compare(other) < 0   ->  self < other
if self.compare(lo) < 0   ->  if self < lo

They desugar through the Compare impl without any method promotion, and read better than the explicit Compare::compare(self, other) OP 0 form the compiler suggests.

Deliberately not adding extend T with Compare::{compare, ..}: the generated interface exports derive(Compare, ...) and no compare method, so an extend declaration would widen the public API rather than fix the deprecation.

Verification

  • src/pkg.generated.mbti byte-identical after moon info — no visible change for downstream users.
  • 297/297 tests pass on wasm, wasm-gc, js, and native.
  • Warning count in the full moon test --target all build: 0.
  • moon fmt produced no further changes.

Checked under moonc v0.10.10+f8a486b6f (upgraded from v0.10.7+bc794d341). No other surface in the 0.10.7 -> 0.10.10 jump touches this repo: no defer/errdefer, no fragile_catch_all or guard_inexhaustive hits, StringBuilder() already the constructor form, and no use of @immut/hashmap/hashset/vector, bigint, @fs, Iter2 Show, from_sorted_array, or lexmatch/lexscan.

`derive(Compare)` generates a trait impl, and v0.10.9 deprecated the
implicit promotion of derived trait methods to type methods. The internal
comparison helpers called `self.compare(other)`, which relied on exactly
that promotion, so the build emitted 18 `[0020]` deprecation warnings
across `Date`, `Time`, and `DateTime` (`is_before`, `is_after`, `min`,
`max`, and both `clamp` bounds on each). Note `moon check` stayed silent;
only the `moon test` build path reported them.

Every site had the shape `self.compare(x) OP 0`, so use the comparison
operators directly: they desugar through the `Compare` impl without any
method promotion, and read better than the explicit `Compare::compare`
call the compiler suggests.

Deliberately not adding `extend T with Compare::{compare, ..}`: the
generated interface exports `derive(Compare, ...)` and no `compare`
method, so an `extend` declaration would widen the public API rather
than fix the deprecation. `src/pkg.generated.mbti` is byte-identical
after `moon info`; 297/297 tests pass on wasm, wasm-gc, js, and native.
@brickfrog
brickfrog merged commit b2e8018 into main Aug 26, 2026
2 checks passed
@brickfrog
brickfrog deleted the fix/compare-promotion-v0.10.9 branch August 26, 2026 09:59
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.

1 participant