diff --git a/docs/release-notes/.FSharp.Compiler.Service/8.0.300.md b/docs/release-notes/.FSharp.Compiler.Service/8.0.300.md index 045a18b0d75..fc3b1013815 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/8.0.300.md +++ b/docs/release-notes/.FSharp.Compiler.Service/8.0.300.md @@ -40,6 +40,7 @@ * Symbols: Add GenericArguments to FSharpEntity ([PR #16470](https://github.com/dotnet/fsharp/pull/16470)) * Parser: more 'as' pattern recovery ([PR #16837](https://github.com/dotnet/fsharp/pull/16837)) * Add extended data for `DefinitionsInSigAndImplNotCompatibleAbbreviationsDiffer` (FS0318). ([PR #16811](https://github.com/dotnet/fsharp/pull/16811))) +* Checker/patterns: recover on unresolved long identifiers ([PR #16842](https://github.com/dotnet/fsharp/pull/16842)) ### Changed diff --git a/src/Compiler/Checking/CheckPatterns.fs b/src/Compiler/Checking/CheckPatterns.fs index 896df82f844..79758a01327 100644 --- a/src/Compiler/Checking/CheckPatterns.fs +++ b/src/Compiler/Checking/CheckPatterns.fs @@ -293,7 +293,11 @@ and TcPat warnOnUpper (cenv: cenv) env valReprInfo vFlags (patEnv: TcPatLinearEn TcPatAnds warnOnUpper cenv env vFlags patEnv ty pats m | SynPat.LongIdent (longDotId=longDotId; typarDecls=tyargs; argPats=args; accessibility=vis; range=m) -> - TcPatLongIdent warnOnUpper cenv env ad valReprInfo vFlags patEnv ty (longDotId, tyargs, args, vis, m) + try + TcPatLongIdent warnOnUpper cenv env ad valReprInfo vFlags patEnv ty (longDotId, tyargs, args, vis, m) + with RecoverableException e -> + errorRecovery e m + (fun _ -> TPat_error m), patEnv | SynPat.QuoteExpr(_, m) -> errorR (Error(FSComp.SR.tcInvalidPattern(), m)) diff --git a/tests/FSharp.Compiler.ComponentTests/Language/BooleanReturningAndReturnTypeDirectedPartialActivePatternTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/BooleanReturningAndReturnTypeDirectedPartialActivePatternTests.fs index ce630714e64..26461598a5b 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/BooleanReturningAndReturnTypeDirectedPartialActivePatternTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/BooleanReturningAndReturnTypeDirectedPartialActivePatternTests.fs @@ -101,6 +101,8 @@ but here has type (Error 39, Line 4, Col 7, Line 4, Col 13, "The value or constructor 'result' is not defined. Maybe you want one of the following: Result") + (Warning 20, Line 3, Col 1, Line 5, Col 15, + "The result of this expression has type 'string' and is implicitly ignored. Consider using 'ignore' to discard this value explicitly, e.g. 'expr |> ignore', or 'let' to bind the result to a name, e.g. 'let result = expr'."); (Error 1, Line 8, Col 3, Line 8, Col 13, "This expression was expected to have type 'string -> bool' @@ -108,10 +110,17 @@ but here has type 'bool' ") (Error 39, Line 8, Col 7, Line 8, Col 13, "The value or constructor 'result' is not defined. Maybe you want one of the following: + Result"); + (Error 39, Line 8, Col 17, Line 8, Col 23, + "The value or constructor 'result' is not defined. Maybe you want one of the following: Result") + (Warning 20, Line 7, Col 1, Line 9, Col 15, + "The result of this expression has type 'string' and is implicitly ignored. Consider using 'ignore' to discard this value explicitly, e.g. 'expr |> ignore', or 'let' to bind the result to a name, e.g. 'let result = expr'."); (Error 1, Line 12, Col 3, Line 12, Col 30, "This expression was expected to have type 'string -> bool' but here has type 'bool' ") + (Warning 20, Line 11, Col 1, Line 13, Col 21, + "The result of this expression has type 'string' and is implicitly ignored. Consider using 'ignore' to discard this value explicitly, e.g. 'expr |> ignore', or 'let' to bind the result to a name, e.g. 'let result = expr'.") ] diff --git a/tests/service/PatternMatchCompilationTests.fs b/tests/service/PatternMatchCompilationTests.fs index c75225aae0c..9b7fe1ff127 100644 --- a/tests/service/PatternMatchCompilationTests.fs +++ b/tests/service/PatternMatchCompilationTests.fs @@ -1260,4 +1260,17 @@ let f : obj -> _ = assertHasSymbolUsages ["i"] checkResults dumpDiagnostics checkResults |> shouldEqual [ "(5,6--5,18): Feature 'non-variable patterns to the right of 'as' patterns' is not available in F# 5.0. Please use language version 6.0 or greater." - ] \ No newline at end of file + ] + +[] +let ``Unresolved name - Qualifier 01`` () = + let _, checkResults = getParseAndCheckResults """ +match None with +| Foo.Bar -> let a = 1 in ignore a +| Some b -> ignore b +""" + assertHasSymbolUsages ["a"; "b"] checkResults + dumpDiagnostics checkResults |> shouldEqual [ + "(3,2--3,5): The namespace or module 'Foo' is not defined." + "(2,6--2,10): Incomplete pattern matches on this expression." + ]