rescript-compiler icon indicating copy to clipboard operation
rescript-compiler copied to clipboard

Recursive type definition breaks @unboxed

Open cknitt opened this issue 2 years ago • 4 comments

This works:

type x = {id: string}
@unboxed type xOrArray = X(x) | Array(array<x>)

but this doesn't:

type rec x = {id: string}
@unboxed and xOrArray = X(x) | Array(array<x>)

It gives the error

This untagged variant definition is invalid: Case X has a payload that is not of one of the recognized shapes (object, array, etc). Then it must be the only case with payloads.

(I came across the problem when creating type definitions for JSON schema.)

cknitt avatar Jul 14 '23 12:07 cknitt

@cknitt not related to this, but I have JSON schema type publicly available https://github.com/DZakh/rescript-json-schema/blob/main/src/JSONSchema7.res

Haven't started updating it to use @unboxed variables though. It'll be much more convenient to use when it happens.

DZakh avatar Jul 14 '23 14:07 DZakh

@DZakh Thanks for the hint! I already took inspiration from there 😄, but I needed JSON schema v4 and wanted to use unboxed variants.

cknitt avatar Jul 14 '23 14:07 cknitt

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Sep 03 '24 01:09 github-actions[bot]

This is still open.

fhammerschmidt avatar Sep 03 '24 06:09 fhammerschmidt

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Aug 30 '25 02:08 github-actions[bot]

This was fixed by https://github.com/rescript-lang/rescript/pull/7320

mediremi avatar Sep 01 '25 09:09 mediremi