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

[Feature] Implement support for custom inline type unions #496

Open
2 of 4 tasks
Luna-Klatzer opened this issue Jul 27, 2023 · 0 comments
Open
2 of 4 tasks

[Feature] Implement support for custom inline type unions #496

Luna-Klatzer opened this issue Jul 27, 2023 · 0 comments
Assignees
Labels
feature New feature or enhancement
Milestone

Comments

@Luna-Klatzer
Copy link
Member

Luna-Klatzer commented Jul 27, 2023

Is there an existing proposal for this?

  • I have searched the existing issues

This feature does not exist in the latest version

  • I am using the latest version

Proposal

Implement support for union types, which allow declarations to have more complex types and be used in more complex situations.

The syntax for unions would be:

T1 | T2 | T3 | ... | Tn

Where n would be any desired value i.e. there is no compiler-enforced limit of the maximum amount of unioned types.

For example:

def func(value: num | str) -> num {
  // Convert the value if it is of type 'str'
  if (typeof(value) == str) {
    value = value as str;
  }
  return value * value;
}

Exact behaviour / changes you want

  • Implement union-type syntax allowing multiple types for any declaration.
  • Implement internal compiler support for type unions, so they are properly handled in all cases i.e. enforced to be narrowed down to a single type if a specific use case requires it.

Related issues

@Luna-Klatzer Luna-Klatzer added the feature New feature or enhancement label Jul 27, 2023
@Luna-Klatzer Luna-Klatzer added this to the v0.11.0 milestone Jul 27, 2023
@Luna-Klatzer Luna-Klatzer self-assigned this Jul 27, 2023
@Luna-Klatzer Luna-Klatzer changed the title [Feature] Implement support for custom inline union types [Feature] Implement support for custom inline type unions Jul 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or enhancement
Projects
Development

No branches or pull requests

1 participant