Skip to content

Fix trimmable typemap constructor UCO generation#11296

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/fix-generated-constructor-uco-methods
Draft

Fix trimmable typemap constructor UCO generation#11296
Copilot wants to merge 3 commits intomainfrom
copilot/fix-generated-constructor-uco-methods

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 6, 2026

Generated trimmable typemap constructor UCO wrappers were activating peers through the (IntPtr, JniHandleOwnership) constructor even when Java invoked a managed constructor with parameters. This skipped JNI argument resolution and called the wrong constructor.

  • Constructor metadata flow

    • Carry concrete managed constructor parameter types from scanner results into the typemap model.
    • Preserve the declaring type/assembly for constructor calls emitted into the typemap assembly.
  • UCO IL generation

    • Emit direct calls to the matching managed constructor when available.
    • Convert JNI object parameters with JavaConvert.FromJniHandle<T>().
    • Set the peer reference before invoking the managed constructor.
    • Keep activation-only fallback behavior for inherited seed constructors with no concrete managed constructor.
  • Regression coverage

    • Add generator tests that inspect emitted IL for:
      • nctor_*_uco calling the matching managed constructor.
      • JNI object handle conversion before constructor invocation.

Example generated behavior now follows the Java constructor signature:

// Java invokes: nctor_1(self, contextHandle)
// Generated UCO now resolves contextHandle and calls:
obj.SetPeerReference(new JniObjectReference(self));
obj.CustomView(JavaConvert.FromJniHandle<Context>(
    contextHandle,
    JniHandleOwnership.DoNotTransfer));

Copilot AI and others added 2 commits May 6, 2026 09:47
Agent-Logs-Url: https://github.com/dotnet/android/sessions/2a0c90c9-484f-417c-875c-bea6afda1c98

Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/android/sessions/2a0c90c9-484f-417c-875c-bea6afda1c98

Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix generated constructor UCO methods in TrimmableTypeMap Fix trimmable typemap constructor UCO generation May 6, 2026
Copilot AI requested a review from simonrozsival May 6, 2026 09:52
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.

[TrimmableTypeMap] Fix generated constructor UCO methods

2 participants