diff --git a/src/Compiler/Checking/PatternMatchCompilation.fs b/src/Compiler/Checking/PatternMatchCompilation.fs index 2d3963b941e..a030f0a327a 100644 --- a/src/Compiler/Checking/PatternMatchCompilation.fs +++ b/src/Compiler/Checking/PatternMatchCompilation.fs @@ -965,6 +965,24 @@ let rec erasePartialPatterns inpPat = and erasePartials inps = List.map erasePartialPatterns inps + +let ReportUnusedTargets (clauses: MatchClause list) dtree = + let used = HashSet<_>(accTargetsOfDecisionTree dtree [], HashIdentity.Structural) + clauses |> List.iteri (fun i c -> + let m = + match c.BoundVals, c.GuardExpr with + | [], Some guard -> guard.Range + | [ bound ], None -> bound.Id.idRange + | [ _ ], Some guard -> guard.Range + | rest, None -> + match rest with + | [ head ] -> head.Id.idRange + | _ -> c.Pattern.Range + | _, Some guard -> guard.Range + + let m = withStartEnd c.Range.Start m.End m + + if not (used.Contains i) then warning (RuleNeverMatched m)) let rec isPatternDisjunctive inpPat = match inpPat with @@ -1656,22 +1674,13 @@ let CompilePatternBasic @ mkFrontiers [([], ValMap<_>.Empty)] nClauses) - let dtree = - InvestigateFrontiers - [] - frontiers - - let targets = matchBuilder.CloseTargets() - + let dtree = InvestigateFrontiers [] frontiers // Report unused targets if warnOnUnused then - let used = HashSet<_>(accTargetsOfDecisionTree dtree [], HashIdentity.Structural) - - clauses |> List.iteri (fun i c -> - if not (used.Contains i) then warning (RuleNeverMatched c.Range)) + ReportUnusedTargets clauses dtree - dtree, targets + dtree, matchBuilder.CloseTargets() // Three pattern constructs can cause significant code expansion in various combinations // - Partial active patterns diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/DynamicTypeTest/DynamicTypeTest.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/DynamicTypeTest/DynamicTypeTest.fs index c2999b14ad9..358471ba5e5 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/DynamicTypeTest/DynamicTypeTest.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/DynamicTypeTest/DynamicTypeTest.fs @@ -34,8 +34,8 @@ module DynamicTypeTest = |> typecheck |> shouldFail |> withDiagnostics [ - (Warning 26, Line 31, Col 7, Line 31, Col 22, "This rule will never be matched") - (Warning 26, Line 32, Col 7, Line 32, Col 22, "This rule will never be matched") + (Warning 26, Line 31, Col 7, Line 31, Col 17, "This rule will never be matched") + (Warning 26, Line 32, Col 7, Line 32, Col 16, "This rule will never be matched") ] // This test was automatically generated (moved from FSharpQA suite - Conformance/PatternMatching/DynamicTypeTest) @@ -135,8 +135,8 @@ involves an indeterminate type based on information prior to this program point. |> typecheck |> shouldFail |> withDiagnostics [ - (Warning 26, Line 12, Col 7, Line 12, Col 22, "This rule will never be matched") - (Warning 26, Line 18, Col 7, Line 18, Col 22, "This rule will never be matched") + (Warning 26, Line 12, Col 7, Line 12, Col 16, "This rule will never be matched") + (Warning 26, Line 18, Col 7, Line 18, Col 16, "This rule will never be matched") ] // This test was automatically generated (moved from FSharpQA suite - Conformance/PatternMatching/DynamicTypeTest) @@ -147,4 +147,38 @@ involves an indeterminate type based on information prior to this program point. |> withOptions ["--test:ErrorRanges"] |> typecheck |> shouldFail - |> withSingleDiagnostic (Warning 67, Line 13, Col 7, Line 13, Col 13, "This type test or downcast will always hold") \ No newline at end of file + |> withSingleDiagnostic (Warning 67, Line 13, Col 7, Line 13, Col 13, "This type test or downcast will always hold")// This test was automatically generated (moved from FSharpQA suite - Conformance/PatternMatching/DynamicTypeTest) + + [] + let ``DynamicTypeTest - E_DynamicTest01_fs - --test:ErrorRanges`` compilation = + compilation + |> asFs + |> withOptions ["--test:ErrorRanges"] + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Warning 26, Line 3, Col 3, Line 3, Col 54, "This rule will never be matched") + ] + + [] + let ``DynamicTypeTest - E_DynamicTest02_fs - --test:ErrorRanges`` compilation = + compilation + |> asFs + |> withOptions ["--test:ErrorRanges"] + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Warning 26, Line 4, Col 7, Line 4, Col 11, "This rule will never be matched") + ] + + [] + let ``DynamicTypeTest - E_DynamicTest03_fs - --test:ErrorRanges`` compilation = + compilation + |> asFs + |> withOptions ["--test:ErrorRanges"] + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Warning 26, Line 8, Col 7, Line 8, Col 12, "This rule will never be matched") + ] + \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/DynamicTypeTest/E_DynamicTest01.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/DynamicTypeTest/E_DynamicTest01.fs new file mode 100644 index 00000000000..50c5e1d4a6a --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/DynamicTypeTest/E_DynamicTest01.fs @@ -0,0 +1,4 @@ +match Unchecked.defaultof with +| :? System.Enum as (a & b) -> let c = a = b in () +| :? System.Enum as (:? System.ConsoleKey as (d & e)) -> let f = d + e + enum 1 in () +| g -> () \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/DynamicTypeTest/E_DynamicTest02.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/DynamicTypeTest/E_DynamicTest02.fs new file mode 100644 index 00000000000..86ace4b28d4 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/DynamicTypeTest/E_DynamicTest02.fs @@ -0,0 +1,5 @@ +let stuff(x: obj) = + match x with + | :? option -> 0x200 + | null -> 0x100 + | _ -> 0x500 \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/DynamicTypeTest/E_DynamicTest03.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/DynamicTypeTest/E_DynamicTest03.fs new file mode 100644 index 00000000000..1099c5b6045 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/DynamicTypeTest/E_DynamicTest03.fs @@ -0,0 +1,9 @@ +type A() = class end +type B1() = + inherit A() + +let stuff(x: obj) = + match x with + | :? A -> 1 + | :? B1 -> 2 + | _ -> 3 \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Named/Named.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Named/Named.fs index 66157b9837a..1b181272a08 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Named/Named.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Named/Named.fs @@ -360,8 +360,8 @@ but here has type (Error 72, Line 21, Col 20, Line 21, Col 31, "Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved.") (Warning 49, Line 22, Col 7, Line 22, Col 17, "Uppercase variable identifiers should not generally be used in patterns, and may indicate a missing open declaration or a misspelt pattern name.") (Error 39, Line 23, Col 7, Line 23, Col 18, "The pattern discriminator 'Punctuation' is not defined.") - (Warning 26, Line 23, Col 7, Line 23, Col 26, "This rule will never be matched") - (Warning 26, Line 24, Col 7, Line 24, Col 40, "This rule will never be matched") + (Warning 26, Line 23, Col 7, Line 23, Col 20, "This rule will never be matched") + (Warning 26, Line 24, Col 7, Line 24, Col 8, "This rule will never be matched") ] // This test was automatically generated (moved from FSharpQA suite - Conformance/PatternMatching/Named) diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Simple/Simple.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Simple/Simple.fs index 7a6f40b4c6a..7ddf43cf235 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Simple/Simple.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Simple/Simple.fs @@ -31,8 +31,8 @@ module Simple = |> withDiagnostics [ (Warning 25, Line 14, Col 15, Line 14, Col 16, "Incomplete pattern matches on this expression. For example, the value '0' may indicate a case not covered by the pattern(s).") (Warning 25, Line 21, Col 31, Line 21, Col 39, "Incomplete pattern matches on this expression. For example, the value '0' may indicate a case not covered by the pattern(s).") - (Warning 26, Line 31, Col 11, Line 31, Col 18, "This rule will never be matched") - (Warning 26, Line 32, Col 11, Line 32, Col 19, "This rule will never be matched") + (Warning 26, Line 31, Col 11, Line 31, Col 12, "This rule will never be matched") + (Warning 26, Line 32, Col 11, Line 32, Col 13, "This rule will never be matched") ] // This test was automatically generated (moved from FSharpQA suite - Conformance/PatternMatching/Simple) @@ -216,7 +216,7 @@ module Simple = |> withOptions ["--test:ErrorRanges"] |> compile |> shouldFail - |> withSingleDiagnostic (Warning 26, Line 10, Col 7, Line 10, Col 13, "This rule will never be matched") + |> withSingleDiagnostic (Warning 26, Line 10, Col 7, Line 10, Col 8, "This rule will never be matched") // This test was automatically generated (moved from FSharpQA suite - Conformance/PatternMatching/Simple) [] diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/SimpleConstant/SimpleConstant.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/SimpleConstant/SimpleConstant.fs index be57aa8eb9b..b2e120d025c 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/SimpleConstant/SimpleConstant.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/SimpleConstant/SimpleConstant.fs @@ -108,11 +108,11 @@ module SimpleConstant = |> shouldFail |> withDiagnostics [ (Warning 3190, Line 13, Col 7, Line 13, Col 17, "Lowercase literal 'intLiteral' is being shadowed by a new pattern with the same name. Only uppercase and module-prefixed literals can be used as named patterns.") - (Warning 26, Line 14, Col 7, Line 14, Col 26, "This rule will never be matched") + (Warning 26, Line 14, Col 7, Line 14, Col 8, "This rule will never be matched") (Warning 3190, Line 20, Col 7, Line 20, Col 17, "Lowercase literal 'strLiteral' is being shadowed by a new pattern with the same name. Only uppercase and module-prefixed literals can be used as named patterns.") - (Warning 26, Line 21, Col 7, Line 21, Col 26, "This rule will never be matched") + (Warning 26, Line 21, Col 7, Line 21, Col 8, "This rule will never be matched") (Warning 3190, Line 27, Col 7, Line 27, Col 18, "Lowercase literal 'boolLiteral' is being shadowed by a new pattern with the same name. Only uppercase and module-prefixed literals can be used as named patterns.") - (Warning 26, Line 28, Col 7, Line 28, Col 27, "This rule will never be matched") + (Warning 26, Line 28, Col 7, Line 28, Col 11, "This rule will never be matched") ] // This test was automatically generated (moved from FSharpQA suite - Conformance/PatternMatching/SimpleConstant) @@ -125,8 +125,8 @@ module SimpleConstant = |> shouldFail |> withDiagnostics [ (Warning 25, Line 8, Col 11, Line 8, Col 16, "Incomplete pattern matches on this expression. For example, the value '``some-other-subtype``' may indicate a case not covered by the pattern(s).") - (Warning 26, Line 14, Col 7, Line 14, Col 57, "This rule will never be matched") - (Warning 26, Line 20, Col 7, Line 20, Col 57, "This rule will never be matched") + (Warning 26, Line 14, Col 7, Line 14, Col 24, "This rule will never be matched") + (Warning 26, Line 20, Col 7, Line 20, Col 24, "This rule will never be matched") ] // This test was automatically generated (moved from FSharpQA suite - Conformance/PatternMatching/SimpleConstant) @@ -146,7 +146,7 @@ module SimpleConstant = |> withOptions ["--test:ErrorRanges"] |> typecheck |> shouldFail - |> withSingleDiagnostic (Warning 26, Line 10, Col 7, Line 10, Col 28, "This rule will never be matched") + |> withSingleDiagnostic (Warning 26, Line 10, Col 7, Line 10, Col 8, "This rule will never be matched") // This test was automatically generated (moved from FSharpQA suite - Conformance/PatternMatching/SimpleConstant) [] @@ -246,7 +246,7 @@ module SimpleConstant = |> withOptions ["--test:ErrorRanges"] |> typecheck |> shouldFail - |> withSingleDiagnostic (Warning 26, Line 10, Col 7, Line 10, Col 26, "This rule will never be matched") + |> withSingleDiagnostic (Warning 26, Line 10, Col 7, Line 10, Col 17, "This rule will never be matched") // This test was automatically generated (moved from FSharpQA suite - Conformance/PatternMatching/SimpleConstant) [] @@ -292,4 +292,4 @@ module SimpleConstant = |> withOptions ["--test:ErrorRanges"] |> typecheck |> shouldFail - |> withSingleDiagnostic (Warning 26, Line 9, Col 7, Line 9, Col 17, "This rule will never be matched") \ No newline at end of file + |> withSingleDiagnostic (Warning 26, Line 9, Col 7, Line 9, Col 8, "This rule will never be matched") \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Tuple/Tuple.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Tuple/Tuple.fs index 03398abebe6..d7286f04e3b 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Tuple/Tuple.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Tuple/Tuple.fs @@ -43,7 +43,7 @@ module Tuple = |> withOptions ["--test:ErrorRanges"] |> typecheck |> shouldFail - |> withSingleDiagnostic (Warning 26, Line 11, Col 7, Line 12, Col 16, "This rule will never be matched") + |> withSingleDiagnostic (Warning 26, Line 11, Col 7, Line 11, Col 14, "This rule will never be matched") // This test was automatically generated (moved from FSharpQA suite - Conformance/PatternMatching/Tuple) [] @@ -53,5 +53,5 @@ module Tuple = |> withOptions ["--test:ErrorRanges"] |> typecheck |> shouldFail - |> withSingleDiagnostic (Warning 26, Line 12, Col 28, Line 12, Col 50, "This rule will never be matched") + |> withSingleDiagnostic (Warning 26, Line 12, Col 28, Line 12, Col 29, "This rule will never be matched") \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Union/E_UnionPattern01.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Union/E_UnionPattern01.fs new file mode 100644 index 00000000000..6e5b267299b --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Union/E_UnionPattern01.fs @@ -0,0 +1,9 @@ +type Stuff = + | A of string * int + | B of string * int + | C +let x v = + match v with + | A(a, b) -> () + | B(a, b) -> () + | A(a, b) | B(a, b) -> () diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Union/E_UnionPattern02.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Union/E_UnionPattern02.fs new file mode 100644 index 00000000000..93f7ecca66b --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Union/E_UnionPattern02.fs @@ -0,0 +1,9 @@ +type Stuff = + | A of string * int + | B of string * int + | C +let x v = + match v with + | A(a, b) -> () + | B(a, b) -> () + | A(a, b) | B(a, b) as f -> () \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Union/E_UnionPattern03.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Union/E_UnionPattern03.fs new file mode 100644 index 00000000000..4290c4dbfa4 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Union/E_UnionPattern03.fs @@ -0,0 +1,10 @@ +type Stuff = + | A + | B + | C + +let x v = + match v with + | A -> "" + | A -> false + | C -> "" \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Union/E_UnionPattern04.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Union/E_UnionPattern04.fs new file mode 100644 index 00000000000..6dc430875d5 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Union/E_UnionPattern04.fs @@ -0,0 +1,5 @@ +let v = + match None with + | Some x -> "" + | Some _ -> "" + | None -> "" \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Union/E_UnionPattern05.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Union/E_UnionPattern05.fs new file mode 100644 index 00000000000..0df48c4bcf6 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Union/E_UnionPattern05.fs @@ -0,0 +1,9 @@ +type Stuff = + | A + | B + | C +let x v = + match v with + | A -> "" + | A as foo as foo1 -> "" + | _ -> "" \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Union/E_UnionPattern06.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Union/E_UnionPattern06.fs new file mode 100644 index 00000000000..7896556863d --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Union/E_UnionPattern06.fs @@ -0,0 +1,9 @@ +type Stuff = + | A + | B + | C +let x v = + match v with + | A -> "" + | A as foo -> "" + | C -> "" \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Union/E_UnionPattern07.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Union/E_UnionPattern07.fs new file mode 100644 index 00000000000..6c9f4aeb32e --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Union/E_UnionPattern07.fs @@ -0,0 +1,9 @@ +type Stuff = + | A + | B + | C +let x v z = + match v with + | A -> "" + | A as foo when z > 5 -> "" + | C -> "" \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Union/E_UnionPattern08.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Union/E_UnionPattern08.fs new file mode 100644 index 00000000000..72cba557bca --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Union/E_UnionPattern08.fs @@ -0,0 +1,9 @@ +type Stuff = + | A + | B + | C +let x v = + match v with + | A -> "" + | A -> "" + | C -> "" \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Union/E_UnionPattern09.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Union/E_UnionPattern09.fs new file mode 100644 index 00000000000..fa9218c1bb8 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Union/E_UnionPattern09.fs @@ -0,0 +1,9 @@ +type Stuff = + | A + | B + | C +let x v = + match v with + | A -> "" + | A as foo as foo1 as foo3 as foo4 -> "" + | _ -> "" \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Union/E_UnionPattern10.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Union/E_UnionPattern10.fs new file mode 100644 index 00000000000..7ba47234c3d --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Union/E_UnionPattern10.fs @@ -0,0 +1,9 @@ +type Stuff = + | A + | B + | C +let x v = + match v with + | A -> "" + | A as foo as foo1 as foo3 as foo4 when foo = A -> "" + | _ -> "" \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Union/E_UnionPattern11.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Union/E_UnionPattern11.fs new file mode 100644 index 00000000000..1b701b4ae96 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Union/E_UnionPattern11.fs @@ -0,0 +1,9 @@ +type Stuff = + | A of a: string * b: int + | B + | C +let x v = + match v with + | A(s, i) -> "" + | A(b=i) as foo as foo1 as foo3 as foo4 when i = 0 -> "" + | _ -> "" \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Union/Union.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Union/Union.fs index 24f4fcbb8c9..b7330c0acfa 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Union/Union.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/Union/Union.fs @@ -70,8 +70,8 @@ but here has type |> typecheck |> shouldFail |> withDiagnostics [ - (Warning 26, Line 12, Col 7, Line 12, Col 17, "This rule will never be matched") - (Warning 26, Line 21, Col 7, Line 21, Col 17, "This rule will never be matched") + (Warning 26, Line 12, Col 7, Line 12, Col 12, "This rule will never be matched") + (Warning 26, Line 21, Col 7, Line 21, Col 12, "This rule will never be matched") ] // This test was automatically generated (moved from FSharpQA suite - Conformance/PatternMatching/Union) @@ -81,4 +81,132 @@ but here has type |> asFs |> withOptions ["--test:ErrorRanges"] |> typecheck - |> shouldSucceed \ No newline at end of file + |> shouldSucceed + + [] + let ``Union - E_UnionPattern1_fs - --test:ErrorRanges`` compilation = + compilation + |> asFs + |> withOptions ["--test:ErrorRanges"] + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Warning 25, Line 6, Col 9, Line 6, Col 10, "Incomplete pattern matches on this expression. For example, the value 'C' may indicate a case not covered by the pattern(s).") + (Warning 26, Line 9, Col 5, Line 9, Col 22, "This rule will never be matched") + ] + + [] + let ``Union - E_UnionPattern2_fs - --test:ErrorRanges`` compilation = + compilation + |> asFs + |> withOptions ["--test:ErrorRanges"] + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Warning 25, Line 6, Col 9, Line 6, Col 10, "Incomplete pattern matches on this expression. For example, the value 'C' may indicate a case not covered by the pattern(s).") + (Warning 26, Line 9, Col 5, Line 9, Col 27, "This rule will never be matched") + ] + + [] + let ``Union - E_UnionPattern3_fs - --test:ErrorRanges`` compilation = + compilation + |> asFs + |> withOptions ["--test:ErrorRanges"] + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 1, Line 9, Col 12, Line 9, Col 17, "All branches of a pattern match expression must return values implicitly convertible to the type of the first branch, which here is 'string'. This branch returns a value of type 'bool'.") + (Warning 25, Line 7, Col 11, Line 7, Col 12, "Incomplete pattern matches on this expression. For example, the value 'B' may indicate a case not covered by the pattern(s).") + (Warning 26, Line 9, Col 7, Line 9, Col 8, "This rule will never be matched") + ] + + [] + let ``Union - E_UnionPattern4_fs - --test:ErrorRanges`` compilation = + compilation + |> asFs + |> withOptions ["--test:ErrorRanges"] + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Warning 26, Line 4, Col 7, Line 4, Col 13, "This rule will never be matched") + ] + + [] + let ``Union - E_UnionPattern5_fs - --test:ErrorRanges`` compilation = + compilation + |> asFs + |> withOptions ["--test:ErrorRanges"] + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Warning 26, Line 8, Col 7, Line 8, Col 23, "This rule will never be matched") + ] + + [] + let ``Union - E_UnionPattern6_fs - --test:ErrorRanges`` compilation = + compilation + |> asFs + |> withOptions ["--test:ErrorRanges"] + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Warning 25, Line 6, Col 11, Line 6, Col 12, "Incomplete pattern matches on this expression. For example, the value 'B' may indicate a case not covered by the pattern(s).") + (Warning 26, Line 8, Col 7, Line 8, Col 15, "This rule will never be matched") + ] + + [] + let ``Union - E_UnionPattern7_fs - --test:ErrorRanges`` compilation = + compilation + |> asFs + |> withOptions ["--test:ErrorRanges"] + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Warning 25, Line 6, Col 11, Line 6, Col 12, "Incomplete pattern matches on this expression. For example, the value 'B' may indicate a case not covered by the pattern(s).") + (Warning 26, Line 8, Col 7, Line 8, Col 26, "This rule will never be matched") + ] + + [] + let ``Union - E_UnionPattern8_fs - --test:ErrorRanges`` compilation = + compilation + |> asFs + |> withOptions ["--test:ErrorRanges"] + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Warning 25, Line 6, Col 11, Line 6, Col 12, "Incomplete pattern matches on this expression. For example, the value 'B' may indicate a case not covered by the pattern(s).") + (Warning 26, Line 8, Col 7, Line 8, Col 8, "This rule will never be matched") + ] + + [] + let ``Union - E_UnionPattern9_fs - --test:ErrorRanges`` compilation = + compilation + |> asFs + |> withOptions ["--test:ErrorRanges"] + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Warning 26, Line 8, Col 7, Line 8, Col 39, "This rule will never be matched") + ] + + [] + let ``Union - E_UnionPattern10_fs - --test:ErrorRanges`` compilation = + compilation + |> asFs + |> withOptions ["--test:ErrorRanges"] + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Warning 26, Line 8, Col 7, Line 8, Col 52, "This rule will never be matched") + ] + + [] + let ``Union - E_UnionPattern11_fs - --test:ErrorRanges`` compilation = + compilation + |> asFs + |> withOptions ["--test:ErrorRanges"] + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Warning 26, Line 8, Col 7, Line 8, Col 55, "This rule will never be matched") + ] \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/Types/UnionTypes/UnionTypes.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/Types/UnionTypes/UnionTypes.fs index e70d07239d1..bc5f4e9d8c8 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/Types/UnionTypes/UnionTypes.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/Types/UnionTypes/UnionTypes.fs @@ -259,7 +259,7 @@ module UnionTypes = |> withDiagnostics [ (Error 3174, Line 10, Col 18, Line 10, Col 20, "The union case 'Case1' does not have a field named 'V3'.") (Error 3174, Line 14, Col 9, Line 14, Col 11, "The union case 'Case1' does not have a field named 'V3'.") - (Warning 26, Line 15, Col 3, Line 15, Col 10, "This rule will never be matched") + (Warning 26, Line 15, Col 3, Line 15, Col 4, "This rule will never be matched") (Error 3174, Line 17, Col 12, Line 17, Col 14, "The union case 'Case1' does not have a field named 'V4'.") (Error 3174, Line 19, Col 25, Line 19, Col 26, "The union case 'Some' does not have a field named 'a'.") ] diff --git a/tests/fsharp/typecheck/sigs/neg03.bsl b/tests/fsharp/typecheck/sigs/neg03.bsl index dd2b916f62f..0963be5a7b1 100644 --- a/tests/fsharp/typecheck/sigs/neg03.bsl +++ b/tests/fsharp/typecheck/sigs/neg03.bsl @@ -13,7 +13,7 @@ neg03.fs(14,5,14,8): typecheck error FS0025: Incomplete pattern matches on this neg03.fs(16,8,16,11): typecheck error FS0025: Incomplete pattern matches on this expression. For example, the value '[_;_]' may indicate a case not covered by the pattern(s). -neg03.fs(22,39,22,47): typecheck error FS0026: This rule will never be matched +neg03.fs(22,39,22,42): typecheck error FS0026: This rule will never be matched neg03.fs(25,9,25,13): typecheck error FS0001: The type 'bool' does not support the operator '<<<' @@ -92,9 +92,9 @@ neg03.fs(86,9,86,13): typecheck error FS0025: Incomplete pattern matches on this neg03.fs(87,19,87,26): typecheck error FS0025: Incomplete pattern matches on this expression. For example, the value '``some-other-subtype``' may indicate a case not covered by the pattern(s). -neg03.fs(91,11,91,26): typecheck error FS0026: This rule will never be matched +neg03.fs(91,11,91,20): typecheck error FS0026: This rule will never be matched -neg03.fs(97,11,97,26): typecheck error FS0026: This rule will never be matched +neg03.fs(97,11,97,20): typecheck error FS0026: This rule will never be matched neg03.fs(100,9,100,12): typecheck error FS0025: Incomplete pattern matches on this expression. For example, the value '[_]' may indicate a case not covered by the pattern(s). diff --git a/tests/fsharp/typecheck/sigs/neg07.bsl b/tests/fsharp/typecheck/sigs/neg07.bsl index 618ebb131d0..5b28d3e7afb 100644 --- a/tests/fsharp/typecheck/sigs/neg07.bsl +++ b/tests/fsharp/typecheck/sigs/neg07.bsl @@ -10,7 +10,7 @@ neg07.fs(27,11,27,21): typecheck error FS0049: Uppercase variable identifiers sh neg07.fs(28,11,28,21): typecheck error FS0049: Uppercase variable identifiers should not generally be used in patterns, and may indicate a missing open declaration or a misspelt pattern name. -neg07.fs(28,11,28,26): typecheck error FS0026: This rule will never be matched +neg07.fs(28,11,28,21): typecheck error FS0026: This rule will never be matched neg07.fs(31,18,31,28): typecheck error FS0039: The value or constructor 'UnionCase1' is not defined. Maybe you want one of the following: X.UnionCase1 @@ -19,7 +19,7 @@ neg07.fs(35,11,35,21): typecheck error FS0049: Uppercase variable identifiers sh neg07.fs(36,11,36,21): typecheck error FS0049: Uppercase variable identifiers should not generally be used in patterns, and may indicate a missing open declaration or a misspelt pattern name. -neg07.fs(36,11,36,27): typecheck error FS0026: This rule will never be matched +neg07.fs(36,11,36,21): typecheck error FS0026: This rule will never be matched neg07.fs(46,15,46,27): typecheck error FS0039: The record label 'RecordLabel1' is not defined. Maybe you want one of the following: R.RecordLabel1 diff --git a/tests/fsharp/typecheck/sigs/neg133.bsl b/tests/fsharp/typecheck/sigs/neg133.bsl index aa3f1bdf3d6..23bf916f031 100644 --- a/tests/fsharp/typecheck/sigs/neg133.bsl +++ b/tests/fsharp/typecheck/sigs/neg133.bsl @@ -3,21 +3,21 @@ neg133.fs(4,19,4,22): typecheck error FS3521: Invalid member declaration. The na neg133.fs(7,19,7,27): typecheck error FS3521: Invalid member declaration. The name of the member is missing or has parentheses. -neg133.fs(28,7,28,17): typecheck error FS0026: This rule will never be matched +neg133.fs(28,7,28,12): typecheck error FS0026: This rule will never be matched -neg133.fs(34,7,34,17): typecheck error FS0026: This rule will never be matched +neg133.fs(34,7,34,12): typecheck error FS0026: This rule will never be matched -neg133.fs(40,7,40,17): typecheck error FS0026: This rule will never be matched +neg133.fs(40,7,40,12): typecheck error FS0026: This rule will never be matched -neg133.fs(46,7,46,20): typecheck error FS0026: This rule will never be matched +neg133.fs(46,7,46,11): typecheck error FS0026: This rule will never be matched -neg133.fs(52,7,52,37): typecheck error FS0026: This rule will never be matched +neg133.fs(52,7,52,32): typecheck error FS0026: This rule will never be matched -neg133.fs(57,7,57,19): typecheck error FS0026: This rule will never be matched +neg133.fs(57,7,57,14): typecheck error FS0026: This rule will never be matched -neg133.fs(63,7,63,19): typecheck error FS0026: This rule will never be matched +neg133.fs(63,7,63,14): typecheck error FS0026: This rule will never be matched -neg133.fs(69,7,69,21): typecheck error FS0026: This rule will never be matched +neg133.fs(69,7,69,16): typecheck error FS0026: This rule will never be matched neg133.fs(76,10,76,11): typecheck error FS0957: One or more of the declared type parameters for this type extension have a missing or wrong type constraint not matching the original type constraints on 'A<_,_,_>' diff --git a/tests/fsharpqa/Source/Diagnostics/General/W_LowercaseLiteralNotIgnored.fs b/tests/fsharpqa/Source/Diagnostics/General/W_LowercaseLiteralNotIgnored.fs index 7e77c8228be..6e45e9cff04 100644 --- a/tests/fsharpqa/Source/Diagnostics/General/W_LowercaseLiteralNotIgnored.fs +++ b/tests/fsharpqa/Source/Diagnostics/General/W_LowercaseLiteralNotIgnored.fs @@ -1,5 +1,5 @@ // #Regression #Diagnostics -//This rule will never be matched$ +//This rule will never be matched$ module M0 module m1 = diff --git a/tests/service/PatternMatchCompilationTests.fs b/tests/service/PatternMatchCompilationTests.fs index 78ab60e8d04..de62e4d3377 100644 --- a/tests/service/PatternMatchCompilationTests.fs +++ b/tests/service/PatternMatchCompilationTests.fs @@ -377,7 +377,7 @@ match Unchecked.defaultof with """ assertHasSymbolUsages ["a"; "b"; "c"; "d"; "e"; "f"; "g"] checkResults dumpDiagnostics checkResults |> shouldEqual [ - "(4,2--4,85): This rule will never be matched" + "(4,2--4,53): This rule will never be matched" ] []