Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,396
    • Issues 4,396
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 378
    • Merge Requests 378
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #16377

Closed
Open
Opened Mar 01, 2019 by Iavor S. Diatchki@yavDeveloper

`TypeError` in a pattern should flag inaccessible code

When we pattern match, if the context ends up having a custom TypeError, we should probably report it, as we've essentially found some inaccessible code. At present this doesn't happen and the custom error is only triggered if the function is applied to an invalid argument. Here is an example to illustrate the issue:

{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE GADTs #-}

module Test where

import GHC.TypeLits
import Data.Kind(Constraint)

type family F a :: Constraint
type instance F Int  = ()
type instance F Char = TypeError ('Text "Nope")
type instance F Bool = (Int ~ Char)

data T where
  A :: F Int  => T
  B :: F Char => T
  C :: F Bool => T

exhaustive :: T -> ()
exhaustive A = ()
exhaustive B = ()   -- this is not flagged as inaccessible, but it should
-- exhaustive C = ()   -- this is flagged as inaccessible, as expected

If the match with constructor C is added to the program, GHC detects that this equation is inaccessible because Int will never match Char. I think that we'd like the same to happen in the second equation when we match on B, except we should report the custom type error, instead of GHC's message about unreachable code.

Trac metadata
Trac field Value
Version 8.6.3
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler (Type checker)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#16377