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

Unexpected parse with unit tail expressions #117

Open
brson opened this issue Feb 8, 2022 · 2 comments
Open

Unexpected parse with unit tail expressions #117

brson opened this issue Feb 8, 2022 · 2 comments

Comments

@brson
Copy link
Contributor

brson commented Feb 8, 2022

I tried to type something like this recently

fn foo() { 4 }

async fn main() {
    foo()
    ()
}

It results in an unexpected error:

Error: expected something callable, found an unsigned integer
   ╭─[input.dada:4:5]
   │
 4 │     foo()
   ·     ──┬──  
   ·       ╰──── here
───╯

Without statement terminators, there are situations where a tail expression has a type but that is not desirable. The obvious solution is to end the block with (), but it parses wrong. Writing { () } does work but is unwieldy.

@brson
Copy link
Contributor Author

brson commented Feb 8, 2022

Ah, one can also write { } to produce a unit, and the compiler could heuristically suggest it. Still though, this seems like an unfortunate thing to run into.

@brson brson changed the title Ambiguity with unit tail expressions Unexpected parse with unit tail expressions Feb 8, 2022
@brson
Copy link
Contributor Author

brson commented Feb 8, 2022

Parenthesized exprs don't work yet but there may be similar issues with things like

fn main() {
    foo()
    (bar).baz
}

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

No branches or pull requests

1 participant