[GHC] #15554: COMPLETE pragmas make overlapping-patterns warnings behave oddly

#15554: COMPLETE pragmas make overlapping-patterns warnings behave oddly -------------------------------------+------------------------------------- Reporter: staffehn | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- I can’t really quantify what’s wrong and what’s intended here, here’s a test file comparing different contrasting examples of similar functions which generate no or strange warnings in the cases that use a datatype with COMPLETE pragmas on pattern synonyms. {{{#!hs {- 1 -} {-# LANGUAGE PatternSynonyms, ViewPatterns #-} {- 2 -} {- 3 -} module M where {- 4 -} {- 5 -} data T = A | B | C {- 6 -} {- 7 -} isBC :: T -> Bool {- 8 -} isBC A = False {- 9 -} isBC B = True {- 10 -} isBC C = True {- 11 -} {- 12 -} pattern BC :: T {- 13 -} pattern BC <- (isBC -> True) {- 14 -} {-# COMPLETE A, BC #-} {- 15 -} {- 16 -} g1 :: T -> Int {- 17 -} g1 A = 1 {- 18 -} g1 BC = 2 {- 19 -} g1 _ = 3 {- 20 -} {- 21 -} -- M.hs:18:1: warning: [-Woverlapping-patterns] {- 22 -} -- Pattern match is redundant {- 23 -} -- In an equation for `g1': g1 BC = ... {- 24 -} -- | {- 25 -} -- 18 | {- 18 -} g1 BC = 2 {- 26 -} -- | ^^^^^^^^^ {- 27 -} {- 28 -} g2 :: T -> Int {- 29 -} g2 BC = 2 {- 30 -} g2 A = 1 {- 31 -} g2 _ = 3 {- 32 -} {- 33 -} -- g2: no warnings {- 34 -} {- 35 -} g3 :: T -> Int {- 36 -} g3 BC = 2 {- 37 -} g3 _ = 1 {- 38 -} g3 A = 3 {- 39 -} g3 A = 4 {- 40 -} g3 B = 4 {- 41 -} g3 B = 4 {- 42 -} g3 C = 4 {- 43 -} g3 C = 4 {- 44 -} g3 _ = 4 {- 45 -} g3 _ = 4 {- 46 -} {- 47 -} -- g3: no warnings {- 48 -} {- 49 -} data T' = A' | B' | C' {- 50 -} {- 51 -} isBC' :: T' -> Bool {- 52 -} isBC' A' = False {- 53 -} isBC' B' = True {- 54 -} isBC' C' = True {- 55 -} {- 56 -} pattern BC' :: T' {- 57 -} pattern BC' <- (isBC' -> True) {- 58 -} -- no COMPLETE pragma {- 59 -} {- 60 -} g3' :: T' -> Int {- 61 -} g3' BC' = 2 {- 62 -} g3' _ = 1 {- 63 -} g3' A' = 3 {- 64 -} g3' A' = 4 {- 65 -} g3' B' = 4 {- 66 -} g3' B' = 4 {- 67 -} g3' C' = 4 {- 68 -} g3' C' = 4 {- 69 -} g3' _ = 4 {- 70 -} g3' _ = 4 {- 71 -} {- 72 -} -- M.hs:63:1: warning: [-Woverlapping-patterns] {- 73 -} -- Pattern match is redundant {- 74 -} -- In an equation for g3': g3' A' = ... {- 75 -} -- | {- 76 -} -- 63 | {- 63 -} g3' A' = 3 {- 77 -} -- | ^^^^^^^^^^ {- 78 -} -- {- 79 -} -- M.hs:64:1: warning: [-Woverlapping-patterns] {- 80 -} -- Pattern match is redundant {- 81 -} -- In an equation for g3': g3' A' = ... {- 82 -} -- | {- 83 -} -- 64 | {- 64 -} g3' A' = 4 {- 84 -} -- | ^^^^^^^^^^ {- 85 -} -- {- 86 -} -- M.hs:65:1: warning: [-Woverlapping-patterns] {- 87 -} -- Pattern match is redundant {- 88 -} -- In an equation for g3': g3' B' = ... {- 89 -} -- | {- 90 -} -- 65 | {- 65 -} g3' B' = 4 {- 91 -} -- | ^^^^^^^^^^ {- 92 -} -- {- 93 -} -- M.hs:66:1: warning: [-Woverlapping-patterns] {- 94 -} -- Pattern match is redundant {- 95 -} -- In an equation for g3': g3' B' = ... {- 96 -} -- | {- 97 -} -- 66 | {- 66 -} g3' B' = 4 {- 98 -} -- | ^^^^^^^^^^ {- 99 -} -- {- 100 -} -- M.hs:67:1: warning: [-Woverlapping-patterns] {- 101 -} -- Pattern match is redundant {- 102 -} -- In an equation for g3': g3' C' = ... {- 103 -} -- | {- 104 -} -- 67 | {- 67 -} g3' C' = 4 {- 105 -} -- | ^^^^^^^^^^ {- 106 -} -- {- 107 -} -- M.hs:68:1: warning: [-Woverlapping-patterns] {- 108 -} -- Pattern match is redundant {- 109 -} -- In an equation for g3': g3' C' = ... {- 110 -} -- | {- 111 -} -- 68 | {- 68 -} g3' C' = 4 {- 112 -} -- | ^^^^^^^^^^ {- 113 -} -- {- 114 -} -- M.hs:69:1: warning: [-Woverlapping-patterns] {- 115 -} -- Pattern match is redundant {- 116 -} -- In an equation for g3': g3' _ = ... {- 117 -} -- | {- 118 -} -- 69 | {- 69 -} g3' _ = 4 {- 119 -} -- | ^^^^^^^^^ {- 120 -} -- {- 121 -} -- M.hs:70:1: warning: [-Woverlapping-patterns] {- 122 -} -- Pattern match is redundant {- 123 -} -- In an equation for g3': g3' _ = ... {- 124 -} -- | {- 125 -} -- 70 | {- 70 -} g3' _ = 4 {- 126 -} -- | ^^^^^^^^^ {- 127 -} {- 128 -} {- 129 -} data S = X {- 130 -} {- 131 -} pattern Y :: S {- 132 -} pattern Y = X {- 133 -} {-# COMPLETE Y #-} {- 134 -} {- 135 -} f1 :: S -> Int {- 136 -} f1 Y = 1 {- 137 -} f1 _ = 2 {- 138 -} {- 139 -} -- f1: no warnings {- 140 -} {- 141 -} f2 :: S -> Int {- 142 -} f2 X = 1 {- 143 -} f2 _ = 2 {- 144 -} {- 145 -} -- M.hs:143:1: warning: [-Woverlapping-patterns] {- 146 -} -- Pattern match is redundant {- 147 -} -- In an equation for `f2': f2 _ = ... {- 148 -} -- | {- 149 -} -- 143 | {- 143 -} f2 _ = 2 {- 150 -} -- | ^^^^^^^^ {- 151 -} {- 152 -} f3 :: S -> Int {- 153 -} f3 Y = 0 {- 154 -} f3 X = 1 {- 155 -} f3 _ = 2 {- 156 -} {- 157 -} -- f3: no warnings {- 158 -} {- 159 -} data S' = X' {- 160 -} {- 161 -} pattern Y' :: S' {- 162 -} pattern Y' = X' {- 163 -} -- no COMPLETE pragma {- 164 -} {- 165 -} f3' :: S' -> Int {- 166 -} f3' Y' = 1 {- 167 -} f3' X' = 0 {- 168 -} f3' _ = 2 {- 169 -} {- 170 -} -- M.hs:168:1: warning: [-Woverlapping-patterns] {- 171 -} -- Pattern match is redundant {- 172 -} -- In an equation for f3': f3' _ = ... {- 173 -} -- | {- 174 -} -- 168 | {- 168 -} f3' _ = 2 {- 175 -} -- | ^^^^^^^^^ }}} In particular: the warning for line 18 should probably be a warning for line 19, and there should be a similar warning for line 31. `g3` extends `g2` in a ridiculous way still without generating any warnings. `g3'` demonstrates the warnings one should expect. The `f` functions are perhaps a bit redundant, but I wanted to include a smaller datatype. I’m not sure if this is easily fixable, since I’m having doubts, that COMPLETE pragmas give enough information for generating good overlapping- patterns warnings. I didn’t think this matter through in detail, but, well, maybe it’s not that important to have this all that sophisticated anyways, since for example guards won’t give overlapping-patterns warnings either. But at least (IMO) it’d be nice to keep the warnings about the normal constructor’s patterns even when they’re mixed with pattern synonyms that have a COMPLETE pragma. Even further, I would always expect overlapping-patterns warnings when a pattern is simply duplicated and probably always if any additional pattern follows a complete listing of everything in a COMPLETE group. And there’s probably lots of cases one could consider naturally suggesting a warning; maybe someone can find a good principle/algorithm to use here. Going further, to prevent COMPLETE pragma setting that always give an overlapping-patterns or incomplete-patterns warnings, one could even consider warning directly at a COMPLETE pragma when it’s a strict subset of an existing COMPLETE group. By the way, my actual goal while finding this bug was to describe another (maybe) bug, which is that the incomplete-patterns warnings can suggest missing pattern synonyms that are not even in scope, which seems not very neat in some cases. In case someone really wants to rework all these warnings, I can make a separate ticket or give details on such a non-neat case that here. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15554 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15554: COMPLETE pragmas make overlapping-patterns warnings behave oddly -------------------------------------+------------------------------------- Reporter: staffehn | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 Resolution: | Keywords: | PatternMatchWarnings, | PatternSynonyms Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * keywords: => PatternMatchWarnings, PatternSynonyms Comment: I think this is essentially the same bug as #13363. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15554#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15554: COMPLETE pragmas make overlapping-patterns warnings behave oddly -------------------------------------+------------------------------------- Reporter: staffehn | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 Resolution: | Keywords: | PatternMatchWarnings, | PatternSynonyms Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #13363 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * related: => #13363 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15554#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC