-
Notifications
You must be signed in to change notification settings - Fork 815
Allow let!
and use!
binding with type annotation without parentheses.
#18508
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
base: main
Are you sure you want to change the base?
Conversation
❗ Release notes required
|
src/Compiler/pars.fsy
Outdated
@@ -4462,6 +4462,30 @@ declExpr: | |||
let trivia: SynExprLetOrUseBangTrivia = { LetOrUseBangKeyword = rhs parseState 1 ; EqualsRange = Some mEquals } | |||
SynExpr.LetOrUseBang(spBind, ($1 = "use"), true, $2, $4, $7, $8, m, trivia) } | |||
|
|||
| BINDER atomicPatternLongIdent COLON typeWithTypeConstraints EQUALS typedSequentialExprBlock IN opt_OBLOCKSEP moreBinders typedSequentialExprBlock %prec expr_let |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new rule allows type annotations without requiring parentheses in let!/use! bindings
let! x: int = ...
use! x: int = ...
It's worth noting that this is consistent with how patterns are handled in regular let bindings as well - e.g. when you want to annotate individual elements of a tuple, you need parentheses
let (a: int, b: string) = (1, "hello") // Valid
let a: int, b: string = (1, "hello") // Not valid
let! (a: int , b: int) = async { return 1, 3 } // Valid
let! a: int , b: int = async { return 1, 3 } // Invalid
src/Compiler/pars.fsy
Outdated
let trivia: SynExprLetOrUseBangTrivia = { LetOrUseBangKeyword = rhs parseState 1 ; EqualsRange = Some mEquals } | ||
SynExpr.LetOrUseBang(spBind, ($1 = "use"), true, pat, $6, $9, $10, m, trivia) } | ||
|
||
| OBINDER atomicPatternLongIdent COLON typeWithTypeConstraints EQUALS typedSequentialExprBlock hardwhiteDefnBindingsTerminator opt_OBLOCKSEP moreBinders typedSequentialExprBlock %prec expr_let |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the associated offside-sensitive version of the new type annotation rule. e.g. in cases where let!
or use!
bindings are used outside of the CE context. This is invalid code but we will want the tokens to be parsed.
let example=
// No braces, indentation defines scope
let! x = async { return 1 }
let! y = async { return 2 }
return x + y
It might be interesting in a follow up PR to add error recovery for cases where we have a let! x:
use! stream:
let x:
use x: Where we can use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love the depth of test coverage here.
Description
Allow
let!
anduse!
binding with type annotation without parentheses.Fixes #10697
BEFORE
AFTER
Once #18487 is merged
Checklist