Skip to content

Reject JsClass types as class fields; guide users to Class<'js, T>#677

Merged
richarddd merged 1 commit intoDelSkayn:masterfrom
richarddd:fix/nested-class-field-clone
Apr 23, 2026
Merged

Reject JsClass types as class fields; guide users to Class<'js, T>#677
richarddd merged 1 commit intoDelSkayn:masterfrom
richarddd:fix/nested-class-field-clone

Conversation

@richarddd
Copy link
Copy Markdown
Collaborator

Issue # (if available)

Fixes #532

Description of changes

#[rquickjs::class] fields typed directly as a JsClass silently dropped nested mutations because the generated getter cloned the value and wrapped the clone in a fresh class instance. Now such fields produce a clear compile error (E0277 via #[diagnostic::on_unimplemented]) directing users to wrap the field in Class<'js, T> to share the underlying cell. Implemented with autoref-specialization: a JsClassFieldCheck<T> helper whose inherent check method is bounded on an unimplementable marker trait NotAJsClassField when T: JsClass, and otherwise falls back to a trivial trait impl.

Checklist

  • Added change to the changelog
  • Created unit tests for my feature if needed

@richarddd richarddd force-pushed the fix/nested-class-field-clone branch from 671f0d9 to 1849313 Compare April 23, 2026 10:05
@richarddd richarddd force-pushed the fix/nested-class-field-clone branch from 1849313 to 057147c Compare April 23, 2026 10:15
Copy link
Copy Markdown
Collaborator

@Sytten Sytten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really a fan of the implementation that adds useless code but I dont see a better way.

@richarddd
Copy link
Copy Markdown
Collaborator Author

This is a bit hacky but wont affect build if you avoid this pattern.

@richarddd richarddd merged commit fb324c7 into DelSkayn:master Apr 23, 2026
34 checks passed
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.

Nested Class changes ignored because generated getter clones

2 participants