Skip to content

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

Merged
merged 38 commits into from
May 16, 2025
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
c4b40cb
new parser production rule.
edgarfgp Apr 25, 2025
0b489a1
Add let! and use! syntax tree tests
edgarfgp Apr 26, 2025
be13fe0
Update existing syntax tree tests
edgarfgp Apr 26, 2025
4e00653
try update mkSynMemberDefnGetSet
edgarfgp Apr 26, 2025
b223cd4
format code
edgarfgp Apr 26, 2025
7c592a8
try different parser rule
edgarfgp Apr 26, 2025
e3f7b8c
Add new test
edgarfgp Apr 26, 2025
43e9ea2
Revert "new parser production rule."
edgarfgp Apr 26, 2025
b26be8b
Revert "try update mkSynMemberDefnGetSet"
edgarfgp Apr 26, 2025
cbe3d48
Revert "Update existing syntax tree tests"
edgarfgp Apr 26, 2025
acb8742
update ce let! and use! test
edgarfgp Apr 26, 2025
00e687c
Merge branch 'main' into fix-10697
edgarfgp Apr 28, 2025
3034ffb
more tests
edgarfgp Apr 28, 2025
99cc8d4
reduce diff
edgarfgp Apr 28, 2025
dd416dc
release notes
edgarfgp Apr 28, 2025
5eb3102
Merge branch 'main' into fix-10697
edgarfgp Apr 30, 2025
e54cb12
more tests
edgarfgp Apr 30, 2025
9e65095
Merge branch 'main' into fix-10697
edgarfgp Apr 30, 2025
f7837a4
Merge branch 'main' into fix-10697
edgarfgp May 1, 2025
e608ce6
try headBindingPattern
edgarfgp May 1, 2025
50114d1
Update tests
edgarfgp May 1, 2025
b16bbb5
more tests
edgarfgp May 1, 2025
84ea9ba
opt_topReturnTypeWithTypeConstraints
edgarfgp May 2, 2025
2b09352
Merge branch 'main' into fix-10697
edgarfgp May 2, 2025
420a92d
Merge branch 'main' into fix-10697
edgarfgp May 5, 2025
afcfc17
Merge branch 'main' into fix-10697
edgarfgp May 6, 2025
4b22d90
Merge branch 'main' into fix-10697
edgarfgp May 7, 2025
a15afa2
Merge branch 'main' into fix-10697
edgarfgp May 12, 2025
2669c9b
Merge branch 'main' into fix-10697
edgarfgp May 13, 2025
71788e5
Merge branch 'main' into fix-10697
edgarfgp May 14, 2025
6b6e86f
Update SyntaxTree tests to include WarnDirectives
edgarfgp May 14, 2025
85a3401
Add LanguageFeature
edgarfgp May 14, 2025
fda8a38
Language release notes
edgarfgp May 14, 2025
e404fa1
Update CheckLanguageFeatureAndRecover in pars.fsy
edgarfgp May 14, 2025
05d11d8
update tests
edgarfgp May 14, 2025
0d83611
Merge branch 'main' into fix-10697
edgarfgp May 15, 2025
03f1ced
update release notes
edgarfgp May 15, 2025
64d72d8
Better naming
edgarfgp May 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Compiler.Service/9.0.300.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* Fix confusing type inference error in task expression ([Issue #13789](https://github.com/dotnet/fsharp/issues/13789), [PR #18450](https://github.com/dotnet/fsharp/pull/18450))
* Fix missing `null` highlighting in tooltips ([PR #18457](https://github.com/dotnet/fsharp/pull/18457))
* Allow `_` in `use!` bindings values (lift FS1228 restriction) ([PR #18487](https://github.com/dotnet/fsharp/pull/18487))
* Allow `let!` and `use!` binding with type annotation without parentheses. ([PR #18508](https://github.com/dotnet/fsharp/pull/18508))
* Make `[<CallerMemberName; Struct>]` combination work([PR #18444](https://github.com/dotnet/fsharp/pull/18444/))
* Fix code completion considers types from own namespace non-imported ([PR #18518](https://github.com/dotnet/fsharp/issues/18518))

Expand Down
24 changes: 24 additions & 0 deletions src/Compiler/pars.fsy
Original file line number Diff line number Diff line change
Expand Up @@ -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
{ // Handle type annotations on simple identifier patterns in let!/use! bindings
let spBind = DebugPointAtBinding.Yes(rhs2 parseState 1 7)
let vis, lidwd = $2
let pat = mkSynPatMaybeVar lidwd vis (rhs parseState 2)
let pat = SynPat.Typed(pat, $4, unionRanges pat.Range $4.Range)
let mEquals = rhs parseState 5
let m = unionRanges (rhs parseState 1) $10.Range
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
{ // Handle type annotations on simple identifier patterns in let!/use! bindings (offside-sensitive version)
let report, mIn, _ = $7
report (if $1 = "use" then "use!" else "let!") (rhs parseState 1) // report unterminated error
let spBind = DebugPointAtBinding.Yes(unionRanges (rhs parseState 1) $6.Range)
let vis, lidwd = $2
let pat = mkSynPatMaybeVar lidwd vis (rhs parseState 2)
let pat = SynPat.Typed(pat, $4, unionRanges pat.Range $4.Range)
let mEquals = rhs parseState 5
let m = unionRanges (rhs parseState 1) $10.Range
let trivia: SynExprLetOrUseBangTrivia = { LetOrUseBangKeyword = rhs parseState 1 ; EqualsRange = Some mEquals }
SynExpr.LetOrUseBang(spBind, ($1 = "use"), true, pat, $6, $9, $10, m, trivia) }

| OBINDER headBindingPattern EQUALS typedSequentialExprBlock hardwhiteDefnBindingsTerminator opt_OBLOCKSEP error %prec expr_let
{ // error recovery that allows intellisense when writing incomplete computation expressions
let spBind = DebugPointAtBinding.Yes(unionRanges (rhs parseState 1) $4.Range)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@ let x = lb {1; 2;}
|> compile
|> shouldSucceed
|> ignore

[<Fact>]
let ``Allow let! and use! binding with type annotation without parentheses.``() =
FSharp """
module ComputationExpressionTests
let f =
async {
let! (a: int) = async { return 1 }
let! b: int = async { return 1 }
return a
}
"""
|> typecheck
|> shouldSucceed
|> ignore

[<Fact>]
let ``A CE explicitly using Zero fails without a defined Zero``() =
Expand Down
6 changes: 6 additions & 0 deletions tests/service/data/SyntaxTree/SynType/Typed LetBang 01.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Module

async {
let! res: int = async { return 1 }
return res
}
38 changes: 38 additions & 0 deletions tests/service/data/SyntaxTree/SynType/Typed LetBang 01.fs.bsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
ImplFile
(ParsedImplFileInput
("/root/SynType/Typed LetBang 01.fs", false, QualifiedNameOfFile Module, [],
[],
[SynModuleOrNamespace
([Module], false, NamedModule,
[Expr
(App
(NonAtomic, false, Ident async,
ComputationExpr
(false,
LetOrUseBang
(Yes (4,4--4,38), false, true,
Typed
(LongIdent
(SynLongIdent ([res], [], [None]), None, None,
Pats [], None, (4,9--4,12)),
LongIdent (SynLongIdent ([int], [], [None])),
(4,9--4,17)),
App
(NonAtomic, false, Ident async,
ComputationExpr
(false,
YieldOrReturn
((false, true), Const (Int32 1, (4,35--4,36)),
(4,28--4,36),
{ YieldOrReturnKeyword = (4,28--4,34) }),
(4,26--4,38)), (4,20--4,38)), [],
YieldOrReturn
((false, true), Ident res, (5,4--5,14),
{ YieldOrReturnKeyword = (5,4--5,10) }), (4,4--5,14),
{ LetOrUseBangKeyword = (4,4--4,8)
EqualsRange = Some (4,18--4,19) }), (3,6--6,1)),
(3,0--6,1)), (3,0--6,1))],
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None,
(1,0--6,1), { LeadingKeyword = Module (1,0--1,6) })], (true, true),
{ ConditionalDirectives = []
CodeComments = [] }, set []))
6 changes: 6 additions & 0 deletions tests/service/data/SyntaxTree/SynType/Typed LetBang 02.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Module

async {
let! (res: int) = async { return 1 }
return res
}
38 changes: 38 additions & 0 deletions tests/service/data/SyntaxTree/SynType/Typed LetBang 02.fs.bsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
ImplFile
(ParsedImplFileInput
("/root/SynType/Typed LetBang 02.fs", false, QualifiedNameOfFile Module, [],
[],
[SynModuleOrNamespace
([Module], false, NamedModule,
[Expr
(App
(NonAtomic, false, Ident async,
ComputationExpr
(false,
LetOrUseBang
(Yes (4,4--4,40), false, true,
Paren
(Typed
(Named
(SynIdent (res, None), false, None, (4,10--4,13)),
LongIdent (SynLongIdent ([int], [], [None])),
(4,10--4,18)), (4,9--4,19)),
App
(NonAtomic, false, Ident async,
ComputationExpr
(false,
YieldOrReturn
((false, true), Const (Int32 1, (4,37--4,38)),
(4,30--4,38),
{ YieldOrReturnKeyword = (4,30--4,36) }),
(4,28--4,40)), (4,22--4,40)), [],
YieldOrReturn
((false, true), Ident res, (5,4--5,14),
{ YieldOrReturnKeyword = (5,4--5,10) }), (4,4--5,14),
{ LetOrUseBangKeyword = (4,4--4,8)
EqualsRange = Some (4,20--4,21) }), (3,6--6,1)),
(3,0--6,1)), (3,0--6,1))],
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None,
(1,0--6,1), { LeadingKeyword = Module (1,0--1,6) })], (true, true),
{ ConditionalDirectives = []
CodeComments = [] }, set []))
7 changes: 7 additions & 0 deletions tests/service/data/SyntaxTree/SynType/Typed LetBang 03.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Module

async {
let (a: int, b: int) = 1, 3
let! (c: int, d: int) = async { return 1, 3 }
return a + b + c + d
}
125 changes: 125 additions & 0 deletions tests/service/data/SyntaxTree/SynType/Typed LetBang 03.fs.bsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
ImplFile
(ParsedImplFileInput
("/root/SynType/Typed LetBang 03.fs", false, QualifiedNameOfFile Module, [],
[],
[SynModuleOrNamespace
([Module], false, NamedModule,
[Expr
(App
(NonAtomic, false, Ident async,
ComputationExpr
(false,
LetOrUse
(false, false,
[SynBinding
(None, Normal, false, false, [],
PreXmlDoc ((4,4), FSharp.Compiler.Xml.XmlDocCollector),
SynValData
(None,
SynValInfo ([], SynArgInfo ([], false, None)),
None),
Paren
(Tuple
(false,
[Typed
(Named
(SynIdent (a, None), false, None,
(4,9--4,10)),
LongIdent
(SynLongIdent ([int], [], [None])),
(4,9--4,15));
Typed
(Named
(SynIdent (b, None), false, None,
(4,17--4,18)),
LongIdent
(SynLongIdent ([int], [], [None])),
(4,17--4,23))], [(4,15--4,16)], (4,9--4,23)),
(4,8--4,24)), None,
Tuple
(false,
[Const (Int32 1, (4,27--4,28));
Const (Int32 3, (4,30--4,31))], [(4,28--4,29)],
(4,27--4,31)), (4,8--4,24), Yes (4,4--4,31),
{ LeadingKeyword = Let (4,4--4,7)
InlineKeyword = None
EqualsRange = Some (4,25--4,26) })],
LetOrUseBang
(Yes (5,4--5,49), false, true,
Paren
(Tuple
(false,
[Typed
(Named
(SynIdent (c, None), false, None,
(5,10--5,11)),
LongIdent (SynLongIdent ([int], [], [None])),
(5,10--5,16));
Typed
(Named
(SynIdent (d, None), false, None,
(5,18--5,19)),
LongIdent (SynLongIdent ([int], [], [None])),
(5,18--5,24))], [(5,16--5,17)], (5,10--5,24)),
(5,9--5,25)),
App
(NonAtomic, false, Ident async,
ComputationExpr
(false,
YieldOrReturn
((false, true),
Tuple
(false,
[Const (Int32 1, (5,43--5,44));
Const (Int32 3, (5,46--5,47))],
[(5,44--5,45)], (5,43--5,47)),
(5,36--5,47),
{ YieldOrReturnKeyword = (5,36--5,42) }),
(5,34--5,49)), (5,28--5,49)), [],
YieldOrReturn
((false, true),
App
(NonAtomic, false,
App
(NonAtomic, true,
LongIdent
(false,
SynLongIdent
([op_Addition], [],
[Some (OriginalNotation "+")]), None,
(6,21--6,22)),
App
(NonAtomic, false,
App
(NonAtomic, true,
LongIdent
(false,
SynLongIdent
([op_Addition], [],
[Some (OriginalNotation "+")]),
None, (6,17--6,18)),
App
(NonAtomic, false,
App
(NonAtomic, true,
LongIdent
(false,
SynLongIdent
([op_Addition], [],
[Some
(OriginalNotation "+")]),
None, (6,13--6,14)), Ident a,
(6,11--6,14)), Ident b,
(6,11--6,16)), (6,11--6,18)),
Ident c, (6,11--6,20)), (6,11--6,22)),
Ident d, (6,11--6,24)), (6,4--6,24),
{ YieldOrReturnKeyword = (6,4--6,10) }),
(5,4--6,24), { LetOrUseBangKeyword = (5,4--5,8)
EqualsRange = Some (5,26--5,27) }),
(4,4--6,24), { LetOrUseKeyword = (4,4--4,7)
InKeyword = None }), (3,6--7,1)),
(3,0--7,1)), (3,0--7,1))],
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None,
(1,0--7,1), { LeadingKeyword = Module (1,0--1,6) })], (true, true),
{ ConditionalDirectives = []
CodeComments = [] }, set []))
7 changes: 7 additions & 0 deletions tests/service/data/SyntaxTree/SynType/Typed LetBang 04.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Module

async {
let a: int, b: int = 1, 3
let! c: int, d: int = async { return 1, 3 }
return a + b + c + d
}
51 changes: 51 additions & 0 deletions tests/service/data/SyntaxTree/SynType/Typed LetBang 04.fs.bsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
ImplFile
(ParsedImplFileInput
("/root/SynType/Typed LetBang 04.fs", false, QualifiedNameOfFile Module, [],
[],
[SynModuleOrNamespace
([Module], false, NamedModule,
[Expr
(App
(NonAtomic, false, Ident async,
ComputationExpr
(false,
Tuple
(false,
[LetOrUse
(false, false,
[SynBinding
(None, Normal, false, false, [],
PreXmlDoc ((4,4), FSharp.Compiler.Xml.XmlDocCollector),
SynValData
(None,
SynValInfo ([], SynArgInfo ([], false, None)),
None),
Named
(SynIdent (a, None), false, None, (4,8--4,9)),
Some
(SynBindingReturnInfo
(LongIdent
(SynLongIdent ([int], [], [None])),
(4,11--4,14), [],
{ ColonRange = Some (4,9--4,10) })),
Typed
(ArbitraryAfterError
("localBinding2", (4,14--4,14)),
LongIdent (SynLongIdent ([int], [], [None])),
(4,14--4,14)), (4,8--4,9), Yes (4,4--4,14),
{ LeadingKeyword = Let (4,4--4,7)
InlineKeyword = None
EqualsRange = None })],
ArbitraryAfterError ("declExpr3", (5,15--5,16)),
(4,4--5,16), { LetOrUseKeyword = (4,4--4,7)
InKeyword = None }); Ident d],
[(5,15--5,16)], (4,4--5,18)), (3,6--5,47)), (3,0--5,47)),
(3,0--5,47))],
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None,
(1,0--5,47), { LeadingKeyword = Module (1,0--1,6) })], (true, true),
{ ConditionalDirectives = []
CodeComments = [] }, set []))

(4,14)-(4,15) parse error Unexpected symbol ',' in binding. Expected '=' or other token.
(5,15)-(5,16) parse error Unexpected symbol ',' in expression. Expected '=' or other token.
(6,4)-(6,10) parse error Incomplete structured construct at or before this point in implementation file
3 changes: 3 additions & 0 deletions tests/service/data/SyntaxTree/SynType/Typed LetBang 05.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Module
let! x:int = async { return 1 }
let! (y:int) = async { return 2 }
Loading