Opened 23 months ago

Last modified 4 months ago

#14851 new bug

"Pattern match has inaccessible right hand side" with TypeRep

Reported by: goldfire Owned by:
Priority: normal Milestone:
Component: Compiler Version: 8.5
Keywords: PatternMatchWarnings, PatternSynonyms Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

When I say

{-# LANGUAGE PatternSynonyms, ViewPatterns #-}

module Bug where

import Type.Reflection

pattern X arg <- (checkFun -> arg)

checkFun :: TypeRep fun -> a
checkFun = undefined

f x = case (x, True) of
          (X _, _) -> 5
          _        -> 6

g x = case x of
          (X _) -> 5
          _     -> 6

I get

Bug.hs:13:11: warning: [-Woverlapping-patterns]
    Pattern match has inaccessible right hand side
    In a case alternative: (X _, _) -> ...
   |
13 |           (X _, _) -> 5
   |           ^^^^^^^^^^^^^

I'm troubled by two things:

  1. There's nothing inaccessible about my right-hand side.
  2. This happens only for f, not g. If there's no tuple, there's no problem.

Note that this problems requires TypeRep. Even another polykinded tycon (like Proxy) didn't trigger the problem.

Change History (2)

comment:1 Changed 23 months ago by RyanGlScott

Keywords: PatternMatchWarnings PatternSynonyms added

comment:2 Changed 4 months ago by Marge Bot <ben+marge-bot@…>

In 7915afc/ghc:

Encode shape information in `PmOracle`

Previously, we had an elaborate mechanism for selecting the warnings to
generate in the presence of different `COMPLETE` matching groups that,
albeit finely-tuned, produced wrong results from an end user's
perspective in some cases (#13363).

The underlying issue is that at the point where the `ConVar` case has to
commit to a particular `COMPLETE` group, there's not enough information
to do so and the status quo was to just enumerate all possible complete
sets nondeterministically.  The `getResult` function would then pick the
outcome according to metrics defined in accordance to the user's guide.
But crucially, it lacked knowledge about the order in which affected
clauses appear, leading to the surprising behavior in #13363.

In !1010 we taught the term oracle to reason about literal values a
variable can certainly not take on. This MR extends that idea to
`ConLike`s and thereby fixes #13363: Instead of committing to a
particular `COMPLETE` group in the `ConVar` case, we now split off the
matching constructor incrementally and record the newly covered case as
a refutable shape in the oracle. Whenever the set of refutable shapes
covers any `COMPLETE` set, the oracle recognises vacuosity of the
uncovered set.

This patch goes a step further: Since at this point the information
in value abstractions is merely a cut down representation of what the
oracle knows, value abstractions degenerate to a single `Id`, the
semantics of which is determined by the oracle state `Delta`.
Value vectors become lists of `[Id]` given meaning to by a single
`Delta`, value set abstractions (of which the uncovered set is an
instance) correspond to a union of `Delta`s which instantiate the
same `[Id]` (akin to models of formula).

Fixes #11528 #13021, #13363, #13965, #14059, #14253, #14851, #15753, #17096, #17149

-------------------------
Metric Decrease:
    ManyAlternatives
    T11195
-------------------------
Note: See TracTickets for help on using tickets.