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

Add support for functions in untagged variants. #6279

Merged
merged 4 commits into from
Jun 1, 2023
Merged

Conversation

cristianoc
Copy link
Collaborator

@cristianoc cristianoc commented May 31, 2023

This was done at speed: need to double check that there are no corner cases missing.

Fixes #6278

TODO:

  • changelog
  • check corner cases: can this overlap with other cases etc
  • check gentype

This was done at speed: need to double check that there are no corner cases missing.

Fixes #6278
@@ -298,6 +311,8 @@ module DynamicChecks = struct
typeof e != number
| ArrayType ->
not (is_array e)
| FunctionType ->
typeof e != function_
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Functions cannot overlap with literals so this case should be OK.

@@ -341,9 +356,8 @@ module DynamicChecks = struct
let add_runtime_type_check ~tag_type ~(block_cases: block_type list) x y =
let has_array() = Ext_list.exists block_cases (fun t -> t = ArrayType) in
match tag_type with
| Untagged IntType
| Untagged StringType
| Untagged FloatType -> typeof y == x
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This seems OK as functions can't overlap with int, string, float, object, array.

@cristianoc cristianoc requested a review from zth June 1, 2023 03:17
Copy link
Collaborator

@zth zth left a comment

Choose a reason for hiding this comment

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

Awesome, this is great!

@fhammerschmidt
Copy link
Contributor

Works as expected!

@cristianoc cristianoc merged commit 9afac86 into master Jun 1, 2023
14 checks passed
@cristianoc cristianoc deleted the untagged_function branch June 1, 2023 08:37
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.

Allow function type in untagged variants
3 participants