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

Allow coercing elgible variants to string/int/float #6311

Merged
merged 7 commits into from
Jun 27, 2023
Merged

Conversation

zth
Copy link
Collaborator

@zth zth commented Jun 26, 2023

This lets you coerce variants to their underlying string/int/float runtime representation, when applicable.

// These are represented by strings at runtime
type x = | One | @as("two") Two

let d = One

// This now works
let f = (d :> string)

type d = | @as(1) One1 | @as(2) Two2

let c = One1

// This also works now because all constructors are represented as ints at runtime.
let dd = (c :> int)

@zth zth requested a review from cristianoc June 26, 2023 16:51
@zth zth changed the title Allow coercing elgible variants to string/int Allow coercing elgible variants to string/int/float Jun 26, 2023
Copy link
Collaborator

@cristianoc cristianoc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great.
Just some comments on code organisation.

jscomp/ml/ctype.ml Outdated Show resolved Hide resolved
jscomp/ml/variant_coercion.ml Show resolved Hide resolved
Copy link
Collaborator

@cristianoc cristianoc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!
Just a tiny observation
Also, changelog

jscomp/ml/variant_coercion.ml Outdated Show resolved Hide resolved
@zth zth merged commit 8840a5f into master Jun 27, 2023
7 checks passed
@zth zth deleted the variant-coercion branch June 27, 2023 11:41
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.

None yet

2 participants