Opened 2 years ago

Closed 2 years ago

#10806 closed bug (fixed)

Type error and type level (<=) together cause GHC to hang

Reported by: htebalaka Owned by:
Priority: normal Milestone: 8.0.1
Component: Compiler (Type checker) Version: 7.10.2
Keywords: Cc: goodingm@…
Operating System: MacOS X Architecture: Unknown/Multiple
Type of failure: Other Test Case: indexed-types/should_compile/T10806
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description (last modified by htebalaka)

The following incorrect arity triggers an infinite loop at compile time. The issue is somehow related to the use of (<=) in constraints of the Q data constructor; if I remove either of the constraints or add an (a <= c) constraint it works as you would expect.

{-# LANGUAGE GADTs, ExplicitNamespaces, TypeOperators, DataKinds  #-}

import GHC.TypeLits (Nat, type (<=))

data Q a where
    Q :: (a <= b, b <= c) => proxy a -> proxy b -> Q c

triggersLoop :: Q b -> Q b -> Bool
triggersLoop (Q _ _) (Q _ _) = print 'x' 'y'

Incorrect function definitions, like foo :: a -> a ; foo _ x = x also result in an infinite loop.

Change History (10)

comment:1 Changed 2 years ago by htebalaka

Description: modified (diff)

comment:2 Changed 2 years ago by htebalaka

Description: modified (diff)

comment:3 Changed 2 years ago by bgamari

Milestone: 7.12.1

Oh dear. This should certainly be addressed for 7.12 if possible.

comment:4 Changed 2 years ago by htebalaka

Just to be clear, function definitions with the wrong arity still needed triggersLoop (Q _ _) (Q _ _) = undefined to trigger the issue.

comment:5 Changed 2 years ago by htebalaka

Looking at this further, it seems like any type error in the file triggers the issue in the presence of triggersLoop.

comment:6 Changed 2 years ago by kanetw

Seems to work fine in GHC HEAD.

comment:7 Changed 2 years ago by thomie

htebalaka: your test case doesn't typecheck with ghc-7.10.2. Are you sure you were using 7.10.2? Can you please fix the description. Thanks.

comment:8 Changed 2 years ago by thoughtpolice


Milestone renamed

comment:9 Changed 2 years ago by Simon Peyton Jones <simonpj@…>

In 487c90ed/ghc:

Add a test for Trac #10806

comment:10 Changed 2 years ago by simonpj

Resolution: fixed
Status: newclosed
Test Case: indexed-types/should_compile/T10806

The test generates an error message (as it should) and does not make the compiler loop. So I'll close.

Note: See TracTickets for help on using tickets.