未验证 提交 33edc2c9 编写于 作者: D Don Syme 提交者: GitHub

Fix analysis of conjunctive patterns for exhaustiveness (#13020)

* try to fix analysis of conjunctive patterns

* add test cases
Co-authored-by: NVlad Zarytovskii <vzaritovsky@hotmail.com>
上级 f3067242
......@@ -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)
......@@ -391,8 +387,6 @@ type Frontier = Frontier of ClauseNumber * Actives * ValMap<Expr>
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
......@@ -1624,7 +1618,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) ->
......
......@@ -2586,6 +2586,21 @@ module TypecheckTests =
peverify cfg "pos40.exe"
exec cfg ("." ++ "pos40.exe") ""
[<Test>]
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") ""
[<Test>]
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") ""
[<Test>]
let ``sigs pos23`` () =
let cfg = testConfig "typecheck/sigs"
......
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
module Pos40
let f = function
| [] -> 0
| (_ :: _) & _ -> 0
printfn "test completed"
exit 0
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册