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

Document match statements #701

Closed
Akuli opened this issue Jan 26, 2025 · 3 comments · Fixed by #729
Closed

Document match statements #701

Akuli opened this issue Jan 26, 2025 · 3 comments · Fixed by #729
Labels
documentation Improvements or additions to documentation

Comments

@Akuli
Copy link
Owner

Akuli commented Jan 26, 2025

Introduced in #617

@Akuli Akuli added the documentation Improvements or additions to documentation label Jan 26, 2025
@Akuli
Copy link
Owner Author

Akuli commented Jan 26, 2025

Should probably document how match statements work in general:

  • match foo: syntax accepts integers and enums only (doesn't really make sense to match other types, e.g. floats)
  • you will get a warning about duplicate/missing case only if you use match some_enum:

@Akuli
Copy link
Owner Author

Akuli commented Jan 28, 2025

Match statements are partially documented in enum documentation. Will need to make sure that there's not too much duplication.

@Akuli Akuli changed the title Document match ... with syntax Document match statements Feb 4, 2025
@Akuli
Copy link
Owner Author

Akuli commented Feb 4, 2025

I think I should document the following as UB:

import "stdlib/io.jou"

enum Foo:
    Bar  # internally 0
    Baz  # internally 1

def main() -> int:
    f = 7 as Foo
    match f:
        case Foo.Bar:
            printf("Bar\n")
        case Foo.Baz:
            printf("Baz\n")
    return 0

Then the compiler could assume that one of the cases runs, so that if each case e.g. sets a variable or returns a value, the compiler will not warn about possibly undefined values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant