Skip to content

Commit 31e054d

Browse files
auduchinokvzarytovskiipsfinaki
authored
Checker/patterns: recover on unresolved long identifiers (#16842)
* Checker/patterns: recover on unresolved long identifiers * Update test baselines * Release notes * try unskip the test --------- Co-authored-by: Vlad Zarytovskii <[email protected]> Co-authored-by: Petr <[email protected]>
1 parent e6fc70e commit 31e054d

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

docs/release-notes/.FSharp.Compiler.Service/8.0.300.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
* Symbols: Add GenericArguments to FSharpEntity ([PR #16470](https://github.com/dotnet/fsharp/pull/16470))
4141
* Parser: more 'as' pattern recovery ([PR #16837](https://github.com/dotnet/fsharp/pull/16837))
4242
* Add extended data for `DefinitionsInSigAndImplNotCompatibleAbbreviationsDiffer` (FS0318). ([PR #16811](https://github.com/dotnet/fsharp/pull/16811)))
43+
* Checker/patterns: recover on unresolved long identifiers ([PR #16842](https://github.com/dotnet/fsharp/pull/16842))
4344

4445
### Changed
4546

src/Compiler/Checking/CheckPatterns.fs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,11 @@ and TcPat warnOnUpper (cenv: cenv) env valReprInfo vFlags (patEnv: TcPatLinearEn
293293
TcPatAnds warnOnUpper cenv env vFlags patEnv ty pats m
294294

295295
| SynPat.LongIdent (longDotId=longDotId; typarDecls=tyargs; argPats=args; accessibility=vis; range=m) ->
296-
TcPatLongIdent warnOnUpper cenv env ad valReprInfo vFlags patEnv ty (longDotId, tyargs, args, vis, m)
296+
try
297+
TcPatLongIdent warnOnUpper cenv env ad valReprInfo vFlags patEnv ty (longDotId, tyargs, args, vis, m)
298+
with RecoverableException e ->
299+
errorRecovery e m
300+
(fun _ -> TPat_error m), patEnv
297301

298302
| SynPat.QuoteExpr(_, m) ->
299303
errorR (Error(FSComp.SR.tcInvalidPattern(), m))

tests/FSharp.Compiler.ComponentTests/Language/BooleanReturningAndReturnTypeDirectedPartialActivePatternTests.fs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,26 @@ but here has type
101101
(Error 39, Line 4, Col 7, Line 4, Col 13,
102102
"The value or constructor 'result' is not defined. Maybe you want one of the following:
103103
Result")
104+
(Warning 20, Line 3, Col 1, Line 5, Col 15,
105+
"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'.");
104106
(Error 1, Line 8, Col 3, Line 8, Col 13,
105107
"This expression was expected to have type
106108
'string -> bool'
107109
but here has type
108110
'bool' ")
109111
(Error 39, Line 8, Col 7, Line 8, Col 13,
110112
"The value or constructor 'result' is not defined. Maybe you want one of the following:
113+
Result");
114+
(Error 39, Line 8, Col 17, Line 8, Col 23,
115+
"The value or constructor 'result' is not defined. Maybe you want one of the following:
111116
Result")
117+
(Warning 20, Line 7, Col 1, Line 9, Col 15,
118+
"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'.");
112119
(Error 1, Line 12, Col 3, Line 12, Col 30,
113120
"This expression was expected to have type
114121
'string -> bool'
115122
but here has type
116123
'bool' ")
124+
(Warning 20, Line 11, Col 1, Line 13, Col 21,
125+
"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'.")
117126
]

tests/service/PatternMatchCompilationTests.fs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1260,4 +1260,17 @@ let f : obj -> _ =
12601260
assertHasSymbolUsages ["i"] checkResults
12611261
dumpDiagnostics checkResults |> shouldEqual [
12621262
"(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."
1263-
]
1263+
]
1264+
1265+
[<Test>]
1266+
let ``Unresolved name - Qualifier 01`` () =
1267+
let _, checkResults = getParseAndCheckResults """
1268+
match None with
1269+
| Foo.Bar -> let a = 1 in ignore a
1270+
| Some b -> ignore b
1271+
"""
1272+
assertHasSymbolUsages ["a"; "b"] checkResults
1273+
dumpDiagnostics checkResults |> shouldEqual [
1274+
"(3,2--3,5): The namespace or module 'Foo' is not defined."
1275+
"(2,6--2,10): Incomplete pattern matches on this expression."
1276+
]

0 commit comments

Comments
 (0)