haskell-graphql / graphql-api

Write type-safe GraphQL services in Haskell
BSD 3-Clause "New" or "Revised" License
406 stars 35 forks source link

Fix overlapping errors and improve diagnostics #198

Open dminuoso opened 6 years ago

dminuoso commented 6 years ago

This fix is similar to: https://github.com/haskell-graphql/graphql-api/pull/178

The existing code has overlapping instances, namely for:

(l :+: r) and (C1 (...) :+: r)

The second instance is unnecessary, since the instance for C1 (...) (S1 sa sb) will produce a type error already.

Some code that triggers the overlapping instances error:

{-# LANGUAGE DeriveGeneric    #-}
{-# LANGUAGE TypeApplications #-}

import GraphQL.Internal.API.Enum (GraphQLEnum(..))
import GHC.Generics (from, to, Generic)

data Magic = Left Int | Right deriving (Eq, Show, Generic)

instance GraphQLEnum Magic

main = main

f = enumValues @Magic

Also an unary constructor is one that takes one argument, so I took the liberty to rename the diagnostics to nullary constructors.

A test case would be a bit more difficult because it still fails compilation.

teh commented 6 years ago

Looks good, thank you! To make the test pass can you adjust COVERAGE_TOLERANCE like in this diff?

dminuoso commented 6 years ago

@teh Done