@@ -47,9 +47,9 @@ deriveInstances (Module coms mn ds exts) = Module coms mn <$> mapM (deriveInstan
4747-- | Takes a declaration, and if the declaration is a deriving TypeInstanceDeclaration,
4848-- elaborates that into an instance declaration via code generation.
4949deriveInstance :: (Functor m, MonadError MultipleErrors m, MonadSupply m) => ModuleName -> [Declaration] -> Declaration -> m Declaration
50−deriveInstance mn ds (TypeInstanceDeclaration nm deps className tys@[TypeConstructor tyName] Nothing)
50+deriveInstance mn ds (TypeInstanceDeclaration nm deps className tys@[ty] Nothing)
5151 | className == Qualified (Just dataGeneric) (ProperName C.generic)
52− , Qualified mn' tyCon <- tyName
52+ , Just (Qualified mn' tyCon) <- unwrapTypeConstructor ty
5353 , mn == fromMaybe mn mn'
5454 = TypeInstanceDeclaration nm deps className tys . Just <$> deriveGeneric mn ds tyCon
5555deriveInstance _ _ (TypeInstanceDeclaration _ _ className tys Nothing)
@@ -57,6 +57,11 @@ deriveInstance _ _ (TypeInstanceDeclaration _ _ className tys Nothing)
5757deriveInstance mn ds (PositionedDeclaration pos com d) = PositionedDeclaration pos com <$> deriveInstance mn ds d
5858deriveInstance _ _ e = return e
5959
60+unwrapTypeConstructor :: Type -> Maybe (Qualified ProperName)
61+unwrapTypeConstructor (TypeConstructor tyCon) = Just tyCon
62+unwrapTypeConstructor (TypeApp ty (TypeVar _)) = unwrapTypeConstructor ty
63+unwrapTypeConstructor _ = Nothing
64+
6065dataGeneric :: ModuleName
6166dataGeneric = ModuleName [ ProperName "Data", ProperName "Generic" ]
6267