Opened 4 years ago

Closed 4 years ago

Last modified 2 years ago

#11396 closed bug (fixed)

deriving Ix with custom ifThenElse causes "Bad call to tagToEnum#"

Reported by: Lemming Owned by: bgamari
Priority: highest Milestone: 8.0.1
Component: Compiler Version: 8.0.1-rc1
Keywords: deriving Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D1797
Wiki Page:


$ cat IfThenElseIx.hs
{-# LANGUAGE RebindableSyntax #-}
module IfThenElseIx where

import Data.Ix (Ix, )

import Prelude

ifThenElse :: Bool -> a -> a -> a
ifThenElse True x _ = x
ifThenElse False _ x = x

data T = A | B deriving (Eq, Ord, Ix)

$ ghci- IfThenElseIx.hs
GHCi, version  :? for help
[1 of 1] Compiling IfThenElseIx     ( IfThenElseIx.hs, interpreted )

IfThenElseIx.hs:13:35: error:
    • Bad call to tagToEnum# at type a_a2ky
        Specify the type by giving a type signature
        e.g. (tagToEnum# x) :: Bool
    • In the second argument of ‘ifThenElse’, namely
        ‘(GHC.Prim.tagToEnum# (c# GHC.Prim.<=# b#))’
      In the expression:
        if (GHC.Prim.tagToEnum# (c# GHC.Prim.>=# a#)) then
            (GHC.Prim.tagToEnum# (c# GHC.Prim.<=# b#))
      In a case alternative:
            -> if (GHC.Prim.tagToEnum# (c# GHC.Prim.>=# a#)) then
                   (GHC.Prim.tagToEnum# (c# GHC.Prim.<=# b#))
      When typechecking the code for ‘GHC.Arr.inRange’
        in a derived instance for ‘Ix T’:
        To see the code I am typechecking, use -ddump-deriv
Failed, modules loaded: none.

Change History (7)

comment:1 Changed 4 years ago by thomie

Milestone: 8.0.1
Priority: normalhighest

Regression. Reproducible with HEAD.

comment:2 Changed 4 years ago by bgamari

This is a regression relative to 7.10.3.

comment:3 Changed 4 years ago by simonpj

Owner: set to bgamari

This comes from the inRange case generated for Ix. We decided to use guards instead.

comment:4 Changed 4 years ago by bgamari

Differential Rev(s): Phab:D1797
Status: newpatch

comment:5 Changed 4 years ago by Ben Gamari <ben@…>

In 5cce0954/ghc:

Use (&&) instead of `if` in Ix derivation

We were previously using `if` in the derivation of `Ix` instances. This
interacts badly with RebindableSyntax as the typechecker doesn't infer
the type of the argument we give to `tagToEnum#`.

Previously we produced, `if (ch >= ah) then (ch <= bh) else False`.

We now produce `(ch >= ah) && (ch <= bh)`

Fixes #11396.

Test Plan: Validate

Reviewers: austin, simonpj

Reviewed By: simonpj

Subscribers: thomie

Differential Revision:

GHC Trac Issues: #11396

comment:6 Changed 4 years ago by bgamari

Resolution: fixed
Status: patchclosed

comment:7 Changed 2 years ago by RyanGlScott

Keywords: deriving added
Note: See TracTickets for help on using tickets.