Instances with equivalent heads from different imported modules are not reported
Consider the following modules M
, N
and O
:
module M where
instance Eq (a -> b) where
_ == _ = True
module N where
instance Eq (a -> b) where
_ == _ = False
module O where
import M
import N
testExp :: Bool
testExp = not == id
The instances defined in M
and N
have the same instance head and are both imported in O
, but when compiling the latter with PAKCS 3.2.0 (or 3.4.1-b6), no error is reported despite this. Instead, the instance from M
is "overwritten" by the one from N
and testExp
evaluates to False
.
This bug originates from the Imports
module, where all imported instances are entered into the instance environment without checking them. Here, instances with equivalent heads overwrite each other. To fix the bug, we either must report such instances in this module or use a different kind of instance environment (for example a list of InstEnv
s) during the first compilation steps and transform it to a regular InstEnv
while reporting such errors in the instance check.
Another option, which would allow such imports if the instances with equivalent heads are not used, would be to rework the InstEnv
data type such that multiple instances with equivalent heads from different modules can be stored in it. This seems to be the option used by the GHC, but it would require some changes in many modules working with instances to fully implement it in the Curry frontend.