diff --git a/src/Compiler/Checking/Expressions/CheckComputationExpressions.fs b/src/Compiler/Checking/Expressions/CheckComputationExpressions.fs index 1f31414599d..e21bfee2640 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(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 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 = 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