[GHC] #14692: Deriving Show with -XEmptyDataDeriving cases on the wrong argument
#14692: Deriving Show with -XEmptyDataDeriving cases on the wrong argument -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: new Priority: high | Milestone: 8.4.1 Component: Compiler | Version: 8.4.1-alpha1 Keywords: deriving | Operating System: Unknown/Multiple Architecture: | Type of failure: Incorrect result Unknown/Multiple | at runtime Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Running this program in GHC 8.4.1-alpha: {{{#!hs {-# LANGUAGE EmptyDataDeriving #-} {-# OPTIONS_GHC -ddump-deriv #-} module Main (main) where data Empty deriving Show loop :: Empty loop = let x = x in x main :: IO () main = print loop }}} One would expect this to loop infinitely at runtime, but in practice, that is not the case: {{{ $ /opt/ghc/8.4.1/bin/runghc Bug.hs ==================== Derived instances ==================== Derived class instances: instance GHC.Show.Show Main.Empty where GHC.Show.showsPrec z_a1Iu = case z_a1Iu of Derived type family instances: ==================== Filling in method body ==================== GHC.Show.Show [Main.Empty] GHC.Show.show = GHC.Show.$dmshow @(Main.Empty) ==================== Filling in method body ==================== GHC.Show.Show [Main.Empty] GHC.Show.showList = GHC.Show.$dmshowList @(Main.Empty) Bug.hs: Bug.hs:5:21-24: Non-exhaustive patterns in case }}} The `-ddump-deriv` output reveals why: the `showsPrec` implementation for `Empty` is casing on the //precedence// argument, not the actual value of type `Empty`! This results in the non-exhaustive patterns error. This is my fault, so I'll prepare a fix :) -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14692> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14692: Deriving Show with -XEmptyDataDeriving cases on the wrong argument -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: patch Priority: high | Milestone: 8.4.1 Component: Compiler | Version: 8.4.1-alpha1 Resolution: | Keywords: deriving Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D4328 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * status: new => patch * differential: => Phab:D4328 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14692#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14692: Deriving Show with -XEmptyDataDeriving cases on the wrong argument -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: patch Priority: high | Milestone: 8.4.1 Component: Compiler | Version: 8.4.1-alpha1 Resolution: | Keywords: deriving Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D4328 Wiki Page: | -------------------------------------+------------------------------------- Comment (by Ben Gamari <ben@…>): In [changeset:"0074a08ea9dfd1416aa57a9504be73dcdf7a1e2b/ghc" 0074a08e/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="0074a08ea9dfd1416aa57a9504be73dcdf7a1e2b" Fix #14692 by correcting an off-by-one error in TcGenDeriv A silly mistake in `gen_Show_binds` was causing derived `Show` instances for empty data types to case on the precedence argument instead of the actual value being showed. Test Plan: make test TEST=drv-empty-data Reviewers: bgamari Reviewed By: bgamari Subscribers: rwbarton, thomie, carter GHC Trac Issues: #14692 Differential Revision: https://phabricator.haskell.org/D4328 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14692#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14692: Deriving Show with -XEmptyDataDeriving cases on the wrong argument -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: closed Priority: high | Milestone: 8.4.1 Component: Compiler | Version: 8.4.1-alpha1 Resolution: fixed | Keywords: deriving Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D4328 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: patch => closed * resolution: => fixed Comment: Merged with 1d05e0c74ad861946e4deb4f27a77b181cab3089. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14692#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC