Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,868
    • Issues 4,868
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 456
    • Merge requests 456
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #18823
Closed
Open
Created Oct 09, 2020 by Sebastian Graf@sgraf812Developer

PmCheck: Long-distance info and where clause "refactorings" are strange

Consider the following two programs:

{-# OPTIONS_GHC -Wincomplete-patterns -fforce-recomp #-}

module Lib where

f :: Maybe Int -> Int -> Int
f x y = case x of
  Nothing -> 1
  _       -> g y
  where
    g y = case x of
      Just n -> n + y
{-# OPTIONS_GHC -Wincomplete-patterns -fforce-recomp #-}

module Lib where

f :: Maybe Int -> Int -> Int
f x y = case x of
  Nothing -> 1
  _       -> g y
    where
      g y = case x of
        Just n -> n + y

The first warns that the case match within g is incomplete with GHC HEAD, the second doesn't.

It's a really delicate interaction between where clause syntax and very accurate long-distance information, maybe even too accurate for its own good: The first program syntactically associates the where clause with the FunDef of f (I think), while the second one associates the where clause with the _ case alt. In the latter case, we know that x can't be Nothing, but not so in the former case. Indeed, it's not unreasonable to call g from the Nothing case in the first program:

module Lib where

f :: Maybe Int -> Int -> Int
f x y = case x of
  Nothing -> g 1
  _       -> g y
  where
    g y = case x of
      Just n -> n + y

And hence it's correct to warn there. I know Haskell is indentation-sensitive, but this kind of interaction was very surprising to me. I'll just open this issue for future reference, as I'm sure that I won't be the last person stumbling over this.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking