hslua / hslua-aeson

Instances to push and receive Aeson's Value type to and from the Lua stack. Code moved to folder hslua-aeson in repo https://github.com/hslua/hslua.
MIT License
5 stars 2 forks source link

hslua-aeson 1.0.2 fails to build with hslua 1.1.1 (despite the package bounds in the .cabal file stating it will) #2

Closed phlummox closed 4 years ago

phlummox commented 4 years ago

The bounds for compatible versions of hslua are stated as being

hslua                >= 1.0     && < 1.2

but this is not correct - in fact, hslua-aeson 1.0.2 fails to build with hslua 1.1.1.

Reproducing

Expected result

The package should build without error.

Actual result

The build fails with the following error:

[1 of 1] Compiling Foreign.Lua.Aeson ( src/Foreign/Lua/Aeson.hs, /mnt/data/dev/uwa-marking-scripts/hs-marker-database-hint/XXX/hslua-aeson-1.0.2/dist-newstyle/build/x86_64-linux/ghc-8.6.5/hslua-aeson-1.0.2/build/Foreign/Lua/Aeson.o )

src/Foreign/Lua/Aeson.hs:131:3: error:
    • Couldn't match expected type ‘Lua a1’
                  with actual type ‘[a0] -> Lua ()’
    • In a stmt of a 'do' block: pushList . toList $ v
      In the expression:
        do pushList . toList $ v
           push (fromIntegral (Vector.length v) :: Lua.Integer)
           rawseti (- 2) 0
      In an equation for ‘pushvector’:
          pushvector v
            = do pushList . toList $ v
                 push (fromIntegral (Vector.length v) :: Lua.Integer)
                 rawseti (- 2) 0
    |
131 |   pushList . toList $ v
    |   ^^^^^^^^^^^^^^^^^^^^^

src/Foreign/Lua/Aeson.hs:131:14: error:
    • Couldn't match type ‘[a]’ with ‘a0 -> Lua ()’
      Expected type: Vector a -> Foreign.Lua.Push.Pusher a0
        Actual type: Vector a -> [a]
    • In the second argument of ‘(.)’, namely ‘toList’
      In the expression: pushList . toList
      In a stmt of a 'do' block: pushList . toList $ v
    • Relevant bindings include
        v :: Vector a (bound at src/Foreign/Lua/Aeson.hs:130:12)
        pushvector :: Vector a -> Lua ()
          (bound at src/Foreign/Lua/Aeson.hs:130:1)
    |
131 |   pushList . toList $ v
    |              ^^^^^^

Gist of the failing build is here.

Cause

This is because hslua 1.1.1 introduces breaking changes - the signature of Foreign.Lua.pushList has changed (see https://github.com/hslua/hslua/issues/83).

A fix is to apply the following patch:

diff a/src/Foreign/Lua/Aeson.hs b/src/Foreign/Lua/Aeson.hs
--- a/src/Foreign/Lua/Aeson.hs
+++ b/src/Foreign/Lua/Aeson.hs
@@ -1,5 +1,7 @@
 {-# OPTIONS_GHC -fno-warn-orphans #-}
 {-# LANGUAGE LambdaCase #-}
+{-# LANGUAGE CPP #-}
+
 {-|
 Module      :  Foreign.Lua.Aeson
 Copyright   :  © 2017–2020 Albert Krewinkel
@@ -128,7 +130,11 @@ isNull idx = do
 -- | Push a vector unto the stack.
 pushvector :: Pushable a => Vector a -> Lua ()
 pushvector v = do
+#if MIN_VERSION_hslua(1,1,1)
+  pushList push $ toList v
+#else
   pushList . toList $ v
+#endif
   push (fromIntegral (Vector.length v) :: Lua.Integer)
   rawseti (-2) 0

If you like, I can submit a pull request of the change from here.

tarleb commented 4 years ago

Thanks, embarrassing mistake. This is fixed by doing a hackage revision, excluding hslua 1.1.1 in the version constraints.