Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotate generated code with types to disambiguate OCaml classic variants #331

Merged
merged 4 commits into from
Mar 1, 2023
Merged

Annotate generated code with types to disambiguate OCaml classic variants #331

merged 4 commits into from
Mar 1, 2023

Conversation

sebastiantoh
Copy link
Contributor

@sebastiantoh sebastiantoh commented Mar 1, 2023

This PR adds type annotations to generated code, in order to disambiguate OCaml classic variants

The generated code produced from the example below fails to compile due to ambiguity

type ambiguous = [
   | Int of int
   | String of string
 ]
   <json adapter.ocaml="Json_adapters.Identity">
 <ocaml repr="classic">

 type ambiguous' = [
   | Int of int
   | String of string
 ]
   <json adapter.ocaml="Json_adapters.Identity">
 <ocaml repr="classic">

PR checklist

  • New code has tests to catch future regressions
  • Documentation is up-to-date
  • CHANGES.md is up-to-date

@sebastiantoh sebastiantoh marked this pull request as ready for review March 1, 2023 09:24
@mjambon
Copy link
Collaborator

mjambon commented Mar 1, 2023

This is very nice. Thank you!

@mjambon mjambon merged commit 797b988 into ahrefs:master Mar 1, 2023
@sebastiantoh sebastiantoh deleted the disambiguate-classic-variants branch March 2, 2023 00:23
mjambon added a commit to mjambon/opam-repository that referenced this pull request May 12, 2023
…n-codec-runtime and atd (2.12.0)

CHANGES:

* atdgen: Annotate generated code with types to disambiguate OCaml
  classic variants (ahrefs/atd#331)
* atdpy: Support the option type more correctly so that it follows
  ATD's convention for JSON encoding. This allows compatibility with
  JSON produced by other tools of the ATD suite. The Python type,
  however, is still a nullable (`Optional`) to make things simpler for
  Python programmers. This prevents distinguishing `["Some", "None"]`
  from `"None"` which both translate to `None` in Python. (ahrefs/atd#332)
* (BREAKING) atdgen: revert default encoding of int64 values as string (ahrefs/atd#330)
* atdgen: Support `<json repr="string">` for `int` values (ahrefs/atd#330)
* atdpy: Treat default field values as expressions to evaluate each time
  they're assigned to a field. This allows the use of mutable defaults such as
  lists (ahrefs/atd#339)
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.

2 participants