Skip to content

Checker/patterns: recover on unresolved long identifiers #16842

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Compiler.Service/8.0.300.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 5 additions & 1 deletion src/Compiler/Checking/CheckPatterns.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,26 @@ 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'
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'.")
]
15 changes: 14 additions & 1 deletion tests/service/PatternMatchCompilationTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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."
]
]

[<Test>]
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."
]