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

[enhancement][DSLX] if-expr followed by as should give diagnostic about precedence #1835

Open
cdleary opened this issue Jan 7, 2025 · 0 comments
Labels
dslx DSLX (domain specific language) implementation / front-end enhancement New feature or request

Comments

@cdleary
Copy link
Collaborator

cdleary commented Jan 7, 2025

What's hard to do? (limit 100 words)

$ ~/opt/xlsynth/latest/dslx_interpreter_main /tmp/if_expr.x 
/tmp/if_expr.x:1:56-1:58
0001: fn f(x: bool) -> u64 { if x { u32:42 } else { u32:64 } as u64 }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^ ParseError: Expected '}', got 'keyword:as'

We should give a nice diagnostic like rust does, via the rust playground:

error: expected expression, found `as`
 --> src/lib.rs:2:29
  |
2 |     if b { 42 } else { 64 } as u64
  |                             ^^ expected expression
  |
help: parentheses are required to parse this as an expression
  |
2 |     (if b { 42 } else { 64 }) as u64
  |     +  

-- https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=6b48b619a2f263d65f6adf674f126e62

Current best alternative workaround (limit 100 words)

Break into two statements.

Your view of the "best case XLS enhancement" (limit 100 words)

We add a similar diagnostic (otherwise it's confusing since we use expressions for the purposes of ternaries).

@cdleary cdleary added dslx DSLX (domain specific language) implementation / front-end enhancement New feature or request labels Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dslx DSLX (domain specific language) implementation / front-end enhancement New feature or request
Projects
Status: No status
Development

No branches or pull requests

1 participant