From a90452142e1e4d28a4ea5701747382f98f3e245e Mon Sep 17 00:00:00 2001 From: Don Syme Date: Wed, 20 Apr 2022 15:56:40 +1000 Subject: [PATCH 1/2] try to fix analysis of conjunctive patterns --- src/fsharp/PatternMatchCompilation.fs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/fsharp/PatternMatchCompilation.fs b/src/fsharp/PatternMatchCompilation.fs index 94d930751f6..387b39c8cf9 100644 --- a/src/fsharp/PatternMatchCompilation.fs +++ b/src/fsharp/PatternMatchCompilation.fs @@ -143,7 +143,6 @@ let GetSubExprOfInput g (gtps, tyargs, tinst) (SubExpr(accessf, (ve2, v2))) = // The ints record which choices taken, e.g. tuple/record fields. type Path = | PathQuery of Path * Unique - | PathConj of Path * int | PathTuple of Path * TypeInst * int | PathRecd of Path * TyconRef * TypeInst * int | PathUnionConstr of Path * UnionCaseRef * TypeInst * int @@ -154,7 +153,6 @@ type Path = let rec pathEq p1 p2 = match p1, p2 with | PathQuery(p1, n1), PathQuery(p2, n2) -> (n1 = n2) && pathEq p1 p2 - | PathConj(p1, n1), PathConj(p2, n2) -> (n1 = n2) && pathEq p1 p2 | PathTuple(p1, _, n1), PathTuple(p2, _, n2) -> (n1 = n2) && pathEq p1 p2 | PathRecd(p1, _, _, n1), PathRecd(p2, _, _, n2) -> (n1 = n2) && pathEq p1 p2 | PathUnionConstr(p1, _, _, n1), PathUnionConstr(p2, _, _, n2) -> (n1 = n2) && pathEq p1 p2 @@ -203,8 +201,6 @@ let RefuteDiscrimSet g m path discrims = let rec go path tm = match path with | PathQuery _ -> raise CannotRefute - | PathConj (p, _j) -> - go p tm | PathTuple (p, tys, j) -> let k, eCoversVals = mkOneKnown tm j tys go p (fun _ -> mkRefTupled g m k tys, eCoversVals) @@ -393,8 +389,6 @@ type Frontier = Frontier of ClauseNumber * Actives * ValMap type InvestigationPoint = Investigation of ClauseNumber * DecisionTreeTest * Path // Note: actives must be a SortedDictionary -// REVIEW: improve these data structures, though surprisingly these functions don't tend to show up -// on profiling runs let rec isMemOfActives p1 actives = match actives with | [] -> false @@ -1611,7 +1605,7 @@ let CompilePatternBasic subPats |> List.collect (fun subPat -> BindProjectionPattern (Active(inpPath, inpExpr, subPat)) activeState) | TPat_conjs(subPats, _m) -> - let newActives = List.mapi (mkSubActive (fun path j -> PathConj(path, j)) (fun _j -> inpAccess)) subPats + let newActives = List.mapi (mkSubActive (fun path _j -> path) (fun _j -> inpAccess)) subPats BindProjectionPatterns newActives activeState | TPat_range (c1, c2, m) -> From 27c38ca36fbcea8b6613b6e08069ab184225faf3 Mon Sep 17 00:00:00 2001 From: Don Syme Date: Thu, 22 Sep 2022 15:54:52 +0100 Subject: [PATCH 2/2] add test cases --- tests/fsharp/tests.fs | 15 +++++++++++++++ tests/fsharp/typecheck/sigs/pos1281.fs | 17 +++++++++++++++++ tests/fsharp/typecheck/sigs/pos3294.fs | 8 ++++++++ 3 files changed, 40 insertions(+) create mode 100644 tests/fsharp/typecheck/sigs/pos1281.fs create mode 100644 tests/fsharp/typecheck/sigs/pos3294.fs diff --git a/tests/fsharp/tests.fs b/tests/fsharp/tests.fs index c40d9f756e6..97575c2f6b5 100644 --- a/tests/fsharp/tests.fs +++ b/tests/fsharp/tests.fs @@ -2583,6 +2583,21 @@ module TypecheckTests = peverify cfg "pos40.exe" exec cfg ("." ++ "pos40.exe") "" + [] + let ``sigs pos1281`` () = + let cfg = testConfig "typecheck/sigs" + // This checks that warning 25 "incomplete matches" is not triggered + fsc cfg "%s --target:exe -o:pos1281.exe --warnaserror --nowarn:26" cfg.fsc_flags ["pos1281.fs"] + peverify cfg "pos1281.exe" + exec cfg ("." ++ "pos1281.exe") "" + + [] + let ``sigs pos3294`` () = + let cfg = testConfig "typecheck/sigs" + fsc cfg "%s --target:exe -o:pos3294.exe --warnaserror" cfg.fsc_flags ["pos3294.fs"] + peverify cfg "pos3294.exe" + exec cfg ("." ++ "pos3294.exe") "" + [] let ``sigs pos23`` () = let cfg = testConfig "typecheck/sigs" diff --git a/tests/fsharp/typecheck/sigs/pos1281.fs b/tests/fsharp/typecheck/sigs/pos1281.fs new file mode 100644 index 00000000000..f2a73c07c3d --- /dev/null +++ b/tests/fsharp/typecheck/sigs/pos1281.fs @@ -0,0 +1,17 @@ +module Pos1281 + +type Cond = Foo | Bar | Baz +let (|SetV|) x _ = x + +let c = Cond.Foo + +match c with +| Baz -> + printfn "Baz" +| Foo & SetV "and" kwd +| Bar & SetV "or" kwd -> + printfn "Keyword: %s" kwd +| Baz -> failwith "wat" + +printfn "test completed" +exit 0 diff --git a/tests/fsharp/typecheck/sigs/pos3294.fs b/tests/fsharp/typecheck/sigs/pos3294.fs new file mode 100644 index 00000000000..55fc5f2631b --- /dev/null +++ b/tests/fsharp/typecheck/sigs/pos3294.fs @@ -0,0 +1,8 @@ +module Pos40 + +let f = function + | [] -> 0 + | (_ :: _) & _ -> 0 + +printfn "test completed" +exit 0