Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix overlapping errors and improve diagnostics #198

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions scripts/hpc-ratchet
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ Each item represents the number of "things" we are OK with not being covered.
COVERAGE_TOLERANCE = {
ALTERNATIVES: 161,
BOOLEANS: 8,
EXPRESSIONS: 1416,
EXPRESSIONS: 1413,
LOCAL_DECLS: 14,
TOP_LEVEL_DECLS: 669,
TOP_LEVEL_DECLS: 666,
}


Expand Down
16 changes: 4 additions & 12 deletions src/GraphQL/Internal/API/Enum.hs
Original file line number Diff line number Diff line change
Expand Up @@ -86,24 +86,16 @@ instance forall conName p b. (KnownSymbol conName) => GenericEnumValues (C1 ('Me

-- TODO(tom): better type errors using `n`. Also type errors for other
-- invalid constructors.
instance forall conName p b sa sb.
( TypeError ('Text "Constructor not unary: " ':<>: 'Text conName)
instance forall conName f s sa sb.
( TypeError ('Text "Constructor not nullary: " ':<>: 'Text conName)
, KnownSymbol conName
) => GenericEnumValues (C1 ('MetaCons conName p b) (S1 sa sb)) where
genericEnumValues = nonUnaryConstructorError
genericEnumFromValue = nonUnaryConstructorError
genericEnumToValue = nonUnaryConstructorError

instance forall conName p b sa sb f.
( TypeError ('Text "Constructor not unary: " ':<>: 'Text conName)
, KnownSymbol conName
) => GenericEnumValues (C1 ('MetaCons conName p b) (S1 sa sb) :+: f) where
) => GenericEnumValues (C1 ('MetaCons conName f s) (S1 sa sb)) where
genericEnumValues = nonUnaryConstructorError
genericEnumFromValue = nonUnaryConstructorError
genericEnumToValue = nonUnaryConstructorError

nonUnaryConstructorError :: a
nonUnaryConstructorError = panic "Tried to construct enum with non-unary constructor. Should get a compile-time error instead of this."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also rename this function to nonNullaryConstructorError. We don't have to worry about backwards compatibility as it is not exported and in Internal anyway.

nonUnaryConstructorError = panic "Tried to construct enum with non-nullary constructor. Should get a compile-time error instead of this."

-- | For each enum type we need 1) a list of all possible values 2) a
-- way to serialise and 3) deserialise.
Expand Down