Skip to content

Commit 7bfdd73

Browse files
authored
Improve active pattern error reporting (#17666)
* Improve active pattern error reporting * release notes.
1 parent 20e794d commit 7bfdd73

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
* Better error reporting for unions with duplicated fields. ([PR #17521](https://github.com/dotnet/fsharp/pull/17521))
4646
* Better error reporting for let bindings. ([PR #17601](https://github.com/dotnet/fsharp/pull/17601))
4747
* Optimize ILTypeDef interface impls reading from metadata. ([PR #17382](https://github.com/dotnet/fsharp/pull/17382))
48+
* Better error reporting for active patterns. ([PR #17666](https://github.com/dotnet/fsharp/pull/17666))
4849

4950

5051
### Breaking Changes

src/Compiler/Checking/Expressions/CheckExpressions.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8674,14 +8674,14 @@ and TcUnionCaseOrExnCaseOrActivePatternResultItemThen (cenv: cenv) overallTy env
86748674
let ucaseAppTy = NewInferenceType g
86758675
let mkConstrApp, argTys, argNames =
86768676
match item with
8677-
| Item.ActivePatternResult(apinfo, _apOverallTy, n, _) ->
8677+
| Item.ActivePatternResult(apinfo, _apOverallTy, n, m) ->
86788678
let aparity = apinfo.ActiveTags.Length
86798679
match aparity with
86808680
| 0 | 1 ->
86818681
let mkConstrApp _mArgs = function [arg] -> arg | _ -> error(InternalError("ApplyUnionCaseOrExn", mItem))
86828682
mkConstrApp, [ucaseAppTy], [ for s, m in apinfo.ActiveTagsWithRanges -> mkSynId m s ]
86838683
| _ ->
8684-
let ucref = mkChoiceCaseRef g mItem aparity n
8684+
let ucref = mkChoiceCaseRef g m aparity n
86858685
let _, _, tinst, _ = FreshenTyconRef2 g mItem ucref.TyconRef
86868686
let ucinfo = UnionCaseInfo (tinst, ucref)
86878687
ApplyUnionCaseOrExnTypes mItem cenv env ucaseAppTy (Item.UnionCase(ucinfo, false))
@@ -11059,7 +11059,7 @@ and TcNormalizedBinding declKind (cenv: cenv) env tpenv overallTy safeThisValOpt
1105911059
else rhsExprChecked
1106011060

1106111061
match apinfoOpt with
11062-
| Some (apinfo, apOverallTy, _) ->
11062+
| Some (apinfo, apOverallTy, m) ->
1106311063
let activePatResTys = NewInferenceTypes g apinfo.ActiveTags
1106411064
let _, apReturnTy = stripFunTy g apOverallTy
1106511065
let apRetTy =
@@ -11080,7 +11080,7 @@ and TcNormalizedBinding declKind (cenv: cenv) env tpenv overallTy safeThisValOpt
1108011080
checkLanguageFeatureError g.langVersion LanguageFeature.StructActivePattern mBinding
1108111081
| ActivePatternReturnKind.RefTypeWrapper -> ()
1108211082

11083-
UnifyTypes cenv env mBinding (apinfo.ResultType g rhsExpr.Range activePatResTys apRetTy) apReturnTy
11083+
UnifyTypes cenv env mBinding (apinfo.ResultType g m activePatResTys apRetTy) apReturnTy
1108411084

1108511085
| None ->
1108611086
if isStructRetTy then

tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Named/E_LargeActivePat01.fs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,14 @@
55

66
let (|One|Two|Three|Four|Five|Six|Seven|Eight|) x = One
77

8+
let (|A|B|C|D|E|F|G|H|) x =
9+
match x with
10+
| 0 -> A
11+
| 1 -> B
12+
| 2 -> C
13+
| 3 -> D
14+
| 4 -> E
15+
| 5 -> F
16+
| 6 -> G
17+
| _ -> H
18+

tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Named/Named.fs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,10 @@ but here has type
470470
|> withOptions ["--test:ErrorRanges"]
471471
|> typecheck
472472
|> shouldFail
473-
|> withSingleDiagnostic (Error 265, Line 6, Col 53, Line 6, Col 56, "Active patterns cannot return more than 7 possibilities")
474-
473+
|> withDiagnostics [
474+
(Error 265, Line 6, Col 6, Line 6, Col 47, "Active patterns cannot return more than 7 possibilities")
475+
(Error 265, Line 8, Col 6, Line 8, Col 23, "Active patterns cannot return more than 7 possibilities")
476+
]
475477

476478
// This test was automatically generated (moved from FSharpQA suite - Conformance/PatternMatching/Named)
477479
[<Theory; Directory(__SOURCE_DIRECTORY__, Includes=[|"E_MulticasePartialNotAllowed01.fs"|])>]

0 commit comments

Comments
 (0)