Skip to content

Printed @as names of fields and constructors turn non-ASCII letters into other characters #9142

Description

@cknitt

When a type declaration is printed (error messages, hover, createInterface), the @as names of record fields and variant constructors are escaped the OCaml way (%S in Printtyp.tree_of_constructor, String.escaped in Res_outcome_printer). Non-ASCII bytes become decimal escapes like \195\169, which ReScript reads back as different characters.

module Make = (X: {type t}) => {
  type record = {@as("prénom") name: X.t}
  type variant = | @as("é") E | @as("a\"b") Q
}

module Applied = Make({
  type t = string
})

createInterface prints the types of Applied through this printer:

module Applied: {
  type record = {@as("pr\195\169nom") name: string}
  type variant = @as("\195\169") E | @as("a\"b") Q
}

Read back, @as("pr\195\169nom") names the field prénom:

type record = {@as("pr\195\169nom") name: string}
let r = {name: "x"}

compiles to

let r = {
  "prénom": "x"
};

so a generated interface gives the fields and constructors other runtime names than the implementation. Error messages and hover show the escapes too.

The @tag name of a declaration is printed with String_literal.encode_js_string since #9136, which keeps non-ASCII letters and escapes only what a string literal needs.

Activity

  1. added theissue type on Oct 30, 2026
  2. added 3 commits that reference this issue on Oct 30, 2026
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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions