From b1213d33e0f99ba568b8deed0818a813b6b70a21 Mon Sep 17 00:00:00 2001 From: "Alexey.Berezhnykh" Date: Wed, 22 Oct 2025 22:11:49 +0300 Subject: [PATCH 1/6] wip --- .../CheckComputationExpressions.fs | 4 +- .../Language/ComputationExpressionTests.fs | 44 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/Compiler/Checking/Expressions/CheckComputationExpressions.fs b/src/Compiler/Checking/Expressions/CheckComputationExpressions.fs index 1f31414599d..80de06353e6 100644 --- a/src/Compiler/Checking/Expressions/CheckComputationExpressions.fs +++ b/src/Compiler/Checking/Expressions/CheckComputationExpressions.fs @@ -1885,7 +1885,9 @@ let rec TryTranslateComputationExpression match pat with | SynPat.Named(ident = SynIdent(id, _); isThisVal = false) -> id, pat | SynPat.LongIdent(longDotId = SynLongIdent(id = [ id ])) -> id, pat - | SynPat.Typed(pat = pat) when supportsTypedLetOrUseBang -> extractIdentifierFromPattern pat + | SynPat.Typed(pat = innerPat) when supportsTypedLetOrUseBang -> + let ident, _ = extractIdentifierFromPattern innerPat + ident, pat | SynPat.Wild(m) when supportsUseBangBindingValueDiscard -> // To properly call the Using(disposable) CE member, we need to convert the wildcard to a SynPat.Named let tmpIdent = mkSynId m "_" diff --git a/tests/FSharp.Compiler.ComponentTests/Language/ComputationExpressionTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/ComputationExpressionTests.fs index 16403bda783..e4da01a33ec 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/ComputationExpressionTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/ComputationExpressionTests.fs @@ -2031,6 +2031,50 @@ match test() with |> compileAndRun |> shouldSucceed + [] + let ``Preview: use! unresolved return type`` () = + FSharp """ +module Test + +open System.IO +open System.Threading.Tasks + +task { + use! x: IDisposable = Task.FromResult(new StreamReader("")) + () +} +|> ignore + """ + |> withLangVersionPreview + |> typecheck + |> shouldFail + |> withDiagnostics [ + Error 39, Line 8, Col 13, Line 8, Col 24, "The type 'IDisposable' is not defined." + ] + + [] + let ``Preview: use! return type mismatch error 01`` () = + FSharp """ +module Test + +open System + +task { + use! (x: int): IDisposable = failwith "" + () +} +|> ignore + """ + |> withLangVersionPreview + |> typecheck + |> shouldFail + |> withDiagnostics [ + Error 1, Line 7, Col 11, Line 7, Col 17, "This expression was expected to have type +'IDisposable' +but here has type +'int' " + ] + [] let ``tail call methods work`` compilation = compilation From 56c442d72d3cee06097152a4a67af5527aa061f2 Mon Sep 17 00:00:00 2001 From: "Alexey.Berezhnykh" Date: Wed, 22 Oct 2025 22:16:02 +0300 Subject: [PATCH 2/6] release notes --- docs/release-notes/.FSharp.Compiler.Service/11.0.0.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/release-notes/.FSharp.Compiler.Service/11.0.0.md b/docs/release-notes/.FSharp.Compiler.Service/11.0.0.md index 655ad02ad2a..03733989fb3 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/11.0.0.md +++ b/docs/release-notes/.FSharp.Compiler.Service/11.0.0.md @@ -5,7 +5,8 @@ * Checking: Fix checking nested fields for records and anonymous ([PR #18964](https://github.com/dotnet/fsharp/pull/18964)) * Fix name is bound multiple times is not reported in 'as' pattern ([PR #18984](https://github.com/dotnet/fsharp/pull/18984)) * Fix: warn FS0049 on upper union case label. ([PR #19003](https://github.com/dotnet/fsharp/pull/19003)) -* Type relations cache: handle potentially "infinite" types ([PR #19010](https://github.com/dotnet/fsharp/pull/19010)) +* Type relations cache: handle potentially "infinite" types ([PR #19010](https://github.com/dotnet/fsharp/pull/19010)) +* Check return type info in use! bindings ([PR #19024](https://github.com/dotnet/fsharp/pull/19024)) ### Added From 602b69035caed4f682201bb8e7aced619ba0e5a7 Mon Sep 17 00:00:00 2001 From: "Alexey.Berezhnykh" Date: Wed, 22 Oct 2025 23:15:54 +0300 Subject: [PATCH 3/6] fix --- .../Expressions/CheckComputationExpressions.fs | 6 +++--- .../BasicGrammarElements/UseBindings/UseBang05.fs | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Compiler/Checking/Expressions/CheckComputationExpressions.fs b/src/Compiler/Checking/Expressions/CheckComputationExpressions.fs index 80de06353e6..e21bfee2640 100644 --- a/src/Compiler/Checking/Expressions/CheckComputationExpressions.fs +++ b/src/Compiler/Checking/Expressions/CheckComputationExpressions.fs @@ -1885,9 +1885,9 @@ let rec TryTranslateComputationExpression match pat with | SynPat.Named(ident = SynIdent(id, _); isThisVal = false) -> id, pat | SynPat.LongIdent(longDotId = SynLongIdent(id = [ id ])) -> id, pat - | SynPat.Typed(pat = innerPat) when supportsTypedLetOrUseBang -> - let ident, _ = extractIdentifierFromPattern innerPat - ident, pat + | SynPat.Typed(innerPat, targetType, range) when supportsTypedLetOrUseBang -> + let ident, pat = extractIdentifierFromPattern innerPat + ident, SynPat.Typed(pat, targetType, unionRanges pat.Range range) | SynPat.Wild(m) when supportsUseBangBindingValueDiscard -> // To properly call the Using(disposable) CE member, we need to convert the wildcard to a SynPat.Named let tmpIdent = mkSynId m "_" diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/UseBindings/UseBang05.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/UseBindings/UseBang05.fs index 7bd2b4cd827..d71b7290d19 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/UseBindings/UseBang05.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/UseBindings/UseBang05.fs @@ -37,11 +37,11 @@ let testBindingPatterns() = Disposable.Reset() counterDisposable { - use! res:IDisposable = new Disposable(1) - use! __:IDisposable = new Disposable(2) - use! (res1: IDisposable) = new Disposable(3) - use! _: IDisposable = new Disposable(4) - use! (_: IDisposable) = new Disposable(5) + use! res:Disposable = new Disposable(1) + use! __:Disposable = new Disposable(2) + use! (res1: Disposable) = new Disposable(3) + use! _: Disposable = new Disposable(4) + use! (_: Disposable) = new Disposable(5) return () } |> Async.RunSynchronously From 193ba3829c39426be7fb0582b38a23b16a74bc30 Mon Sep 17 00:00:00 2001 From: "Alexey.Berezhnykh" Date: Wed, 22 Oct 2025 23:50:53 +0300 Subject: [PATCH 4/6] update gold --- .../BasicGrammarElements/UseBindings/UseBangBindings.fs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/UseBindings/UseBangBindings.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/UseBindings/UseBangBindings.fs index 79fd3535db9..94ce5a3c03c 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/UseBindings/UseBangBindings.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/UseBindings/UseBangBindings.fs @@ -59,9 +59,9 @@ module UseBangBindingsVersion9 = |> typecheck |> shouldFail |> withDiagnostics [ - (Error 3350, Line 40, Col 18, Line 40, Col 29, "Feature 'Allow let! and use! type annotations without requiring parentheses' is not available in F# 9.0. Please use language version 10.0 or greater.") - (Error 3350, Line 41, Col 17, Line 41, Col 28, "Feature 'Allow let! and use! type annotations without requiring parentheses' is not available in F# 9.0. Please use language version 10.0 or greater.") - (Error 3350, Line 43, Col 17, Line 43, Col 28, "Feature 'Allow let! and use! type annotations without requiring parentheses' is not available in F# 9.0. Please use language version 10.0 or greater.") + (Error 3350, Line 40, Col 18, Line 40, Col 28, "Feature 'Allow let! and use! type annotations without requiring parentheses' is not available in F# 9.0. Please use language version 10.0 or greater.") + (Error 3350, Line 41, Col 17, Line 41, Col 27, "Feature 'Allow let! and use! type annotations without requiring parentheses' is not available in F# 9.0. Please use language version 10.0 or greater.") + (Error 3350, Line 43, Col 17, Line 43, Col 27, "Feature 'Allow let! and use! type annotations without requiring parentheses' is not available in F# 9.0. Please use language version 10.0 or greater.") ] module UseBangBindingsPreview = From 581d62b7107940b466076dfff84bbc0bffb5a244 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Thu, 23 Oct 2025 15:06:59 +0200 Subject: [PATCH 5/6] Apply suggestion from @T-Gro --- docs/release-notes/.FSharp.Compiler.Service/11.0.0.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/release-notes/.FSharp.Compiler.Service/11.0.0.md b/docs/release-notes/.FSharp.Compiler.Service/11.0.0.md index 03733989fb3..42ff2f655bd 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/11.0.0.md +++ b/docs/release-notes/.FSharp.Compiler.Service/11.0.0.md @@ -6,7 +6,6 @@ * Fix name is bound multiple times is not reported in 'as' pattern ([PR #18984](https://github.com/dotnet/fsharp/pull/18984)) * Fix: warn FS0049 on upper union case label. ([PR #19003](https://github.com/dotnet/fsharp/pull/19003)) * Type relations cache: handle potentially "infinite" types ([PR #19010](https://github.com/dotnet/fsharp/pull/19010)) -* Check return type info in use! bindings ([PR #19024](https://github.com/dotnet/fsharp/pull/19024)) ### Added From 0f688b6835b3a17e77515b6b9dcac2ef8673102e Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Thu, 23 Oct 2025 15:07:23 +0200 Subject: [PATCH 6/6] Apply suggestion from @T-Gro --- docs/release-notes/.FSharp.Compiler.Service/11.0.0.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/release-notes/.FSharp.Compiler.Service/11.0.0.md b/docs/release-notes/.FSharp.Compiler.Service/11.0.0.md index 42ff2f655bd..655ad02ad2a 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/11.0.0.md +++ b/docs/release-notes/.FSharp.Compiler.Service/11.0.0.md @@ -5,7 +5,7 @@ * Checking: Fix checking nested fields for records and anonymous ([PR #18964](https://github.com/dotnet/fsharp/pull/18964)) * Fix name is bound multiple times is not reported in 'as' pattern ([PR #18984](https://github.com/dotnet/fsharp/pull/18984)) * Fix: warn FS0049 on upper union case label. ([PR #19003](https://github.com/dotnet/fsharp/pull/19003)) -* Type relations cache: handle potentially "infinite" types ([PR #19010](https://github.com/dotnet/fsharp/pull/19010)) +* Type relations cache: handle potentially "infinite" types ([PR #19010](https://github.com/dotnet/fsharp/pull/19010)) ### Added