Skip to content

didc bind --target mo: emit PascalCase type names (Motoko convention) #733

Description

@marc0olo

Problem

didc bind --target mo emits snake_case type names, but the Motoko convention for types is PascalCase. This means generated bindings are not idiomatic Motoko and require a post-processing step to be usable in practice.

Example — current output:

public type canister_status_args = { canister_id : canister_id };
public type canister_status_result = { ... };

Expected idiomatic output:

public type CanisterStatusArgs = { canister_id : CanisterId };
public type CanisterStatusResult = { ... };

Note: record field labels and method names should stay snake_case — they are Candid identifiers, not Motoko identifiers. Only the type definition names and their references as types should be converted.

Context

This was discovered while maintaining caffeinelabs/mops-ic, the Motoko bindings package for the IC management canister. The initial generation in that repo was done with an undocumented post-processing step (snake→PascalCase); a follow-up PR (caffeinelabs/mops-ic#11) formalised this as scripts/pascal_types.py.

The Rust binding generator in didc already converts to PascalCase for struct/enum names (following Rust conventions). The Motoko generator should do the same.

Proposed fix

In rust/candid_parser/src/bindings/motoko.rs, convert type definition names (and their references) from snake_case to PascalCase when generating the public type declarations. Field labels (Label::Named) and method names should remain unchanged.

The conversion is straightforward: split on _, capitalise each word, join. The scripts/pascal_types.py in caffeinelabs/mops-ic#11 demonstrates the exact logic.

Additional note

didc 0.6.1 (current main) also fixes the float32 not supported in Motoko panic present in the released 0.5.4 binary — a release with both fixes would be very welcome.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions