#1735: unused binding changes program behaviour
-------------------------------------------+--------------------------------
Reporter: igloo | Owner: simonpj
Type: bug | Status: closed
Priority: normal | Milestone: 6.12 branch
Component: Compiler | Version: 6.8
Severity: normal | Resolution: fixed
Keywords: | Difficulty: Unknown
Testcase: typecheck/should_run/T1735 | Os: Unknown/Multiple
Architecture: Unknown/Multiple |
-------------------------------------------+--------------------------------
Changes (by simonpj):
* testcase: => typecheck/should_run/T1735
* status: new => closed
* resolution: => fixed
Comment:
This one has been in my to-do list for a long time, and I've finally
gotten around to looking at it again. The key declarations
in `Xml.hs` read thus:
{{{
class (Data XmlD a) => Xml a where ...
instance Xml String where ...
-- The Xml [a] context is a bit scary, but if we don't
-- have it then GHC complains about overlapping instances
instance (Xml a, Xml [a]) => Xml [a] where ....
}}}
Wihtout the "scary" `Xml [a]` in the context, GHC 6.8 rejected the latter
instance thus
{{{
Xml.hs:128:0:
Overlapping instances for Xml [a]
arising from the superclasses of an instance declaration
at Xml.hs:128:0
Matching instances:
instance [overlap ok] (Xml a) => Xml [a]
-- Defined at Xml.hs:(128,0)-(136,68)
instance [overlap ok] Xml String
-- Defined at Xml.hs:(138,0)-(142,26)
}}}
But that got fixed when I fixed #1470; see `Note [Recursive superclasses]`
in `TcInstDcls`.
So now the program works fine without the scary bit, and with or without
`-DFOO`.
If you have the scary bit, then it's unsurprising that things go badly
wrong. The details are:
* The superclass for the `Xml [a]` dictionary being constructed
is gotten by superclass-selection from the `Xml [a]` dictionary
passed in.
{{{
$fXml dx dxs = MkD ($p2 dxs) ...
}}}
* When the instance declaration is used, you get a recursive dictionary,
thus
{{{
d :: Xml [YesOrNo]
d = $fXml[] d' d
}}}
* So every `Xml [a]` dictionary has a superclass that is exactly bottom.
The odd behaviour of the unused definition arises thus:
* It just so happens that the unused binding gives rise to the need for
an XML [YesOrNo] dictionary. It isn't used, but when the contraints
simplifier needs a `Data XMLD [YesOrNo]` dictionary, it can get it
from
the (bogus) dictionary it has lying around.
If you write instance declarations like that, wierd stuff is going to
happen to you. Closing this ticket!
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/1735#comment:9>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs