Skip to content

feat(ts): translate &mut dyn Debug and &mut dyn Display - #453

Merged
moq-bot[bot] merged 4 commits into
mainfrom
ts-dyn-fmt-mut
Nov 2, 2026
Merged

moq-bot[bot] merged 4 commits into
mainfrom
ts-dyn-fmt-mut

Conversation

@kixelated

@kixelated kixelated commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

A &dyn Debug or &dyn Display, and since #445 a Box, Arc, or Rc of one, translate as a function writing the value, but a &mut dyn Debug or &mut dyn Display was refused as "a coercion to &mut dyn Debug, which is not supported yet". The trait objects quest names it. moq builds none; this is std coverage the quest calls for.

Approach

A &mut dyn Debug or &mut dyn Display is the same function a &dyn one is. Debug::fmt and Display::fmt take &self, so nothing writes through the borrow. A value JS copies is read through its rt.Place as the function writes, not as it is made, so it shows what the place holds then. The change is one line: fmt_object accepts either mutability of reference.

Tests: fmt::objects in the lang fixture's differential test against native wasm32 now also covers:

  • A Vec<&mut dyn Debug> of a number and a String that JS copies, the crate's type, a Box<dyn Debug>, and a tuple holding the crate's type over a Cell. Each is written with {:?} and {:#?}.
  • The Cell set while the borrows live, then written again through a reborrowed &mut dyn Debug and a &dyn Debug coerced from it.
  • &mut dyn Display of a number written after the number changes, of the crate's type centered, and of a String after a push.
  • The box's drop.

Census at the moq pin, before → after: unchanged (692 / 186 / 119 for moq-net / model / kio), since moq builds none.

Impact

  • The translator's output: &mut dyn Debug and &mut dyn Display translate instead of failing.
  • No breaking change.

Alternatives

  • Reading a value JS copies out of its place as the object is made: the same output, since the exclusive borrow lets nothing write the place meanwhile, but a copy per object where reading as it writes needs none.

Follow-ups

  • Debug of a Cell is refused, as Debug of a RefCell is (quest/m3/ts-refcell-debug.md, from #447). Met writing the fixture; the fixture writes the cell through the crate's own wrapper.
  • String + &str is an "unsupported call", met in a scratch test: new quest quest/m3/ts-string-add.md.

Review

Codex gpt-6.1-sol at medium effort, via quest review, round 1 on head 5e7bb518e42eb51a5681431456e74e5d41bb7454: no findings. Head bfb9718c adds only the ts-string-add quest; just check passes.

🤖 Generated with Claude Code

kixelated and others added 2 commits November 2, 2026 12:08
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 30fb962f-52ba-42c2-9d9a-8c1dda0793c1
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated
kixelated enabled auto-merge (squash) November 2, 2026 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant