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 else branch to be omitted in certain cases. #598

Merged
merged 1 commit into from
May 18, 2023

Conversation

gdotdesign
Copy link
Member

This PR contains three separate changes (sorry about that):

  1. Allow omitting the else branch when the return type and value can be inferred. The reason for this is there are cases when the else branch is unnecessary like when working with Html (which could be omitted before) or next { } branches. The inferred return values for omitted else branches are:
    • String returns empty string ""
    • Array(a) returns empty array
    • Promise(Void) returns null (maybe it will need to return an actual promise we will see)
    • Maybe(a) returns Maybe::Nothing
    • Void returns null
    • Html returns null
  2. next { } now compiles to null. Previously it would compile to something like this ( which essentially does nothing):
    new Promise((resolve) => { this.setState(new Record({})) })
    
  3. Remove NEVER from the type checker and replace it with VOID

@gdotdesign gdotdesign added enhancement New feature or request language Language feature labels May 11, 2023
@gdotdesign gdotdesign added this to the 0.18.0 milestone May 11, 2023
@gdotdesign gdotdesign requested a review from Sija May 11, 2023 06:08
@jansul
Copy link
Contributor

jansul commented May 11, 2023

String might be the only one that's a little too magic for my taste 😅 (Can always use Maybe(String) for an optional string?)

Do you have any use cases for that one in mind?

@gdotdesign
Copy link
Member Author

String might be the only one that's a little too magic for my taste sweat_smile (Can always use Maybe(String) for an optional string?)

Do you have any use cases for that one in mind?

It's mainly for Html (as it currently works):

<div>
  if condition {
    "value"
  }
</div>

@gdotdesign gdotdesign closed this May 18, 2023
@gdotdesign gdotdesign reopened this May 18, 2023
@gdotdesign gdotdesign merged commit 27e7139 into master May 18, 2023
@gdotdesign gdotdesign deleted the if-without-else branch May 18, 2023 04:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request language Language feature
Development

Successfully merging this pull request may close these issues.

3 participants