Skip to content

Conversation

@l-epple
Copy link

@l-epple l-epple commented Aug 12, 2022

This PR builds on #32, adding support for aeson 2.0 as well as GHC >= 9.0, but fixes some mistakes, gets the Variant code to work again and adds support for GHC 9.2.

  • Support GHC >= 9.2 by using Type over *, also gets rid of the warnings for 9.0
  • Support GHC >= 9.2 by adding FlexibleContexts where necessary
  • Fix a long standing bug leading to a crash after a parse failure in the FromJSON for (tagged) Variants. This bug hinges on parseJSON x :: Parser () succeeding which is always the case for aeson >= 2.0, making this bug quite prevalent. See the commit message for further details.
  • Adapt to aeson 2.0 API changes via CPP
GHC aeson == 1.5.* aeson == 2.0.*
8.10.7 works ✅ works ✅
9.0.2 works ✅ works ✅
9.2.4 no cabal install plan for aeson-1.5.6.0 works ✅

l-epple and others added 4 commits August 12, 2022 16:55
Arguably, emptyVariant is more like Void than (), given that it is
actually not possible to obtain its value via fromVariant and if it
were, a program would explode due to undefined.

In JSON there is not really a way to have a void value, a JSON value is
always *something*, so it makes no sense to have a Variant '[] parser
that succeeds in any condition. More importantly, the FromJSON instance
for Variant (t ': ts) actually *requires* the instance for Variant '[]
to fail! If parseJSON is called for Variant '[] from that instance, it
means that the value didn't match any of the types the Variant accepts.

This causes the bug that, if parseJSON :: Parser () succeeds for a JSON
value, we can obtain an arbitrary Variant that would fail to evaluate,
as it'd be constructed via extendVariant emptyVariant. For aeson < 1.6
this is a pretty obscure bug, since FromJSON () only accepts the empty
array:

    >>> decode "[]" :: Maybe (Variant '[Int])
    Just *** Exception: Prelude.undefined

Since aeson 2.0, FromJSON () [accepts] all JSON values, meaning that any
failed parse to Variant results in a program crash!

Tagged Variants also exhibit this problem, of course. The bug is fixed
by making the FromJSON (Variant '[]) instance fail always via parseFail.

[accepts]: haskell/aeson@677daf0
This adds a bit more ifdef zoo to be compatible with the breaking
change in aeson. Tested manually against aeson 2.0.3.0 and 1.5.6.0.

Might want to update the CI as well, but I don’t have the time to
touch CircleCI yaml.

Co-authored-by: Lukas Epple <lukas.epple@possehl-analytics.com>
Support for * is disabled in GHC 9.2 by default and causes a lot of
annoying warnings in 9.0.

Tested against 8.10.7, 9.0.2 and 9.2.4. The base constraint seems to be
correct, as Data.Kind was added in base 4.9.

Co-authored-by: Lukas Epple <lukas.epple@possehl-analytics.com>
This seems to be required now to compile the Variant code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants