From b8791a4ef8424376c992bcee8d79ce54c4cae912 Mon Sep 17 00:00:00 2001 From: Eugene Auduchinok Date: Fri, 8 Mar 2024 12:31:54 -0400 Subject: [PATCH 1/4] Checker/patterns: recover on unresolved long identifiers --- src/Compiler/Checking/CheckPatterns.fs | 6 +++++- tests/service/PatternMatchCompilationTests.fs | 18 +++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) 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/service/PatternMatchCompilationTests.fs b/tests/service/PatternMatchCompilationTests.fs index c75225aae0c..5cf54cae9b6 100644 --- a/tests/service/PatternMatchCompilationTests.fs +++ b/tests/service/PatternMatchCompilationTests.fs @@ -1260,4 +1260,20 @@ 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 + ] + +[] +#if !NETCOREAPP +[] +#endif +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." + ] From 7b5436d05adeab6089f4ba66bb4a74f100c086de Mon Sep 17 00:00:00 2001 From: Eugene Auduchinok Date: Fri, 8 Mar 2024 14:38:24 -0400 Subject: [PATCH 2/4] Update test baselines --- ...ningAndReturnTypeDirectedPartialActivePatternTests.fs | 9 +++++++++ 1 file changed, 9 insertions(+) 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'.") ] From 06a3d4cf53891dc8a95f9d9ad85459b78b937c77 Mon Sep 17 00:00:00 2001 From: Eugene Auduchinok Date: Wed, 13 Mar 2024 18:46:33 +0100 Subject: [PATCH 3/4] Release notes --- docs/release-notes/.FSharp.Compiler.Service/8.0.300.md | 1 + 1 file changed, 1 insertion(+) 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 f14715ddf7c..e37a97d1975 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/8.0.300.md +++ b/docs/release-notes/.FSharp.Compiler.Service/8.0.300.md @@ -27,6 +27,7 @@ * Allow returning bool instead of unit option for partial active patterns. ([Language suggestion #1041](https://github.com/fsharp/fslang-suggestions/issues/1041), [PR #16473](https://github.com/dotnet/fsharp/pull/16473)) * Symbols: Add GenericArguments to FSharpEntity ([PR #16470](https://github.com/dotnet/fsharp/pull/16470)) * 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 From 4944b5e21461995b732396db67658fba720d04bf Mon Sep 17 00:00:00 2001 From: Petr Date: Fri, 22 Mar 2024 16:00:17 +0100 Subject: [PATCH 4/4] try unskip the test --- tests/service/PatternMatchCompilationTests.fs | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/service/PatternMatchCompilationTests.fs b/tests/service/PatternMatchCompilationTests.fs index 5cf54cae9b6..9b7fe1ff127 100644 --- a/tests/service/PatternMatchCompilationTests.fs +++ b/tests/service/PatternMatchCompilationTests.fs @@ -1263,9 +1263,6 @@ let f : obj -> _ = ] [] -#if !NETCOREAPP -[] -#endif let ``Unresolved name - Qualifier 01`` () = let _, checkResults = getParseAndCheckResults """ match None with