diff --git a/src/Compiler/Checking/Expressions/CheckComputationExpressions.fs b/src/Compiler/Checking/Expressions/CheckComputationExpressions.fs index 1f31414599d..699d37a4290 100644 --- a/src/Compiler/Checking/Expressions/CheckComputationExpressions.fs +++ b/src/Compiler/Checking/Expressions/CheckComputationExpressions.fs @@ -1894,6 +1894,20 @@ let rec TryTranslateComputationExpression | _ -> error (Error(FSComp.SR.tcInvalidUseBangBinding (), pat.Range)) let ident, pat = extractIdentifierFromPattern pat + // Validate the pattern's type annotation by invoking TcPat (for its type-checking side effects) + let patEnvValidate = TcPatLinearEnv(ceenv.tpenv, NameMap.empty, Set.empty) + let patTyValidate = NewInferenceType cenv.g + + let _ = + cenv.TcPat + AllIdsOK + cenv + ceenv.env + None + (TcPatValFlags(ValInline.Optional, permitInferTypars, noArgOrRetAttribs, false, None, false)) + patEnvValidate + patTyValidate + pat let bindExpr = let consumeExpr = diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/UseBindings/E_UseBang01.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/UseBindings/E_UseBang01.fs new file mode 100644 index 00000000000..ae7b23dcfc2 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/UseBindings/E_UseBang01.fs @@ -0,0 +1,10 @@ +async { + use x: askjdhaskjd = failwith "" + use! x: askjdhaskjd = failwith "" + + use! (x: askjdhaskjd) = failwith "" + use! _: askjdhaskjd = failwith "" + use! (_: askjdhaskjd) = failwith "" + return 5 +} +|> ignore diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/UseBindings/UseBangBindings.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/UseBindings/UseBangBindings.fs index 79fd3535db9..bade2ca39c5 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/UseBindings/UseBangBindings.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/UseBindings/UseBangBindings.fs @@ -104,5 +104,20 @@ module UseBangBindingsPreview = |> withLangVersion10 |> compileAndRun |> shouldSucceed + + [] + let ``UseBangBindings - E_UseBang01_fs - Preview LangVersion`` compilation = + compilation + |> asExe + |> withLangVersion10 + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 39, Line 2, Col 12, Line 2, Col 23, "The type 'askjdhaskjd' is not defined.") + (Error 39, Line 3, Col 13, Line 3, Col 24, "The type 'askjdhaskjd' is not defined.") + (Error 39, Line 5, Col 14, Line 5, Col 25, "The type 'askjdhaskjd' is not defined.") + (Error 39, Line 6, Col 13, Line 6, Col 24, "The type 'askjdhaskjd' is not defined.") + (Error 39, Line 7, Col 14, Line 7, Col 25, "The type 'askjdhaskjd' is not defined.") + ]