awakesecurity / proto3-wire

https://hackage.haskell.org/package/proto3-wire
Other
23 stars 30 forks source link

build error with the commit 23b6ed40288e36b5849d74c86a5cd0fa7548f043 #38

Open mut0u opened 6 years ago

mut0u commented 6 years ago

I use the recently commit to build grpc demo and failed. the error is

    [ 1 of 13] Compiling Proto3.Suite.DotProto.AST ( src/Proto3/Suite/DotProto/AST.hs, .stack-work/dist/x86_64-linux-tinfo6/Cabal-2.0.1.0/build/Proto3/Suite/DotProto/AST.o )

   program/.stack-work/downloaded/XJwrjlKl8Cc8/src/Proto3/Suite/DotProto/AST.hs:391:22: error:
        • No instance for (Arbitrary Natural)
            arising from a use of ‘arbitrary’
        • In a stmt of a 'do' block: natural <- arbitrary
          In the expression:
            do natural <- arbitrary
               return (fromIntegral (natural :: Natural))
          In an equation for ‘arbitraryFieldNumber’:
              arbitraryFieldNumber
                = do natural <- arbitrary
                     return (fromIntegral (natural :: Natural))
        |
    391 |           natural <- arbitrary
        |                      ^^^^^^^^^
Gabriella439 commented 6 years ago

Sorry for the delay! What build tool are you using? stack, cabal, or Nix?

patrickmn commented 6 years ago

I think I might be running into the same thing. I'm using GHCJS 8.4.1 and Stack with the most recent (4560541) ghcjs-base

Stack config:

compiler: ghcjs-0.2.0.9011009_ghc-8.4.1
compiler-check: match-exact
resolver: nightly-2018-06-17
...
packages:
    - "."
    - location: "vendor/ghcjs-base"
      extra-dep: true
    - location: "vendor/proto3-wire"
      extra-dep: true
    - location: "vendor/proto3-suite"
      extra-dep: true
extra-deps: []
...
setup-info:
    ghcjs:
        source:
            ghcjs-0.2.0.9011009_ghc-8.4.1:
                url: https://github.com/alexanderkjeldaas/ghcjs/releases/download/fghcjs-8.4.1/ghcjs.tar.gz
                sha1: 9e9d68ae01aca1b02fcbb03e5b891a7e2118a9db

Building yields errors like:

    /home/patrick/.../proto3-suite/src/Proto3/Suite/Types.hs:102:45: error:
        • Could not deduce (Semigroup (Nested a))
            arising from the 'deriving' clause of a data type declaration
          from the context: Semigroup a
            bound by the deriving clause for ‘Monoid (Nested a)’
            at src/Proto3/Suite/Types.hs:102:45-50
          Possible fix:
            use a standalone 'deriving instance' declaration,
              so you can specify the instance context yourself
        • When deriving the instance for (Monoid (Nested a))
        |
    102 |   deriving (Show, Eq, Ord, Generic, NFData, Monoid, Arbitrary, Functor, Foldable,
        |                                             ^^^^^^

Fixed proto3-wire build (missing semigroup) with:

diff --git a/src/Proto3/Wire/Encode.hs b/src/Proto3/Wire/Encode.hs
index 659c91f..26a0a87 100644
--- a/src/Proto3/Wire/Encode.hs
+++ b/src/Proto3/Wire/Encode.hs
@@ -108,7 +108,7 @@ import           Proto3.Wire.Types
 --
 -- Use `toLazyByteString` when you're done assembling the `MessageBuilder`
 newtype MessageBuilder = MessageBuilder { unMessageBuilder :: WB.Builder }
-  deriving Monoid
+  deriving (Monoid, Semigroup)

 instance Show MessageBuilder where
   showsPrec prec builder =

Fixed proto3-suite (missing semigroup, <> conflict, and missing Arbitrary Natural) build with:

diff --git a/src/Proto3/Suite/DotProto/AST.hs b/src/Proto3/Suite/DotProto/AST.hs
index 82aabeb..e2fb82b 100644
--- a/src/Proto3/Suite/DotProto/AST.hs
+++ b/src/Proto3/Suite/DotProto/AST.hs
@@ -389,6 +389,8 @@ data DotProtoReservedField
   | ReservedIdentifier String
   deriving (Show, Eq)

+instance Arbitrary Natural
+
 instance Arbitrary DotProtoReservedField where
   arbitrary =
     oneof [arbitrarySingleField, arbitraryFieldRange]
diff --git a/src/Proto3/Suite/DotProto/Rendering.hs b/src/Proto3/Suite/DotProto/Rendering.hs
index c1f05ec..583ce3b 100644
--- a/src/Proto3/Suite/DotProto/Rendering.hs
+++ b/src/Proto3/Suite/DotProto/Rendering.hs
@@ -17,6 +17,7 @@ module Proto3.Suite.DotProto.Rendering
   , RenderingOptions(..)
   ) where

+import Prelude hiding ((<>))
 import           Data.Char
 import qualified Data.Text                       as T
 import           Filesystem.Path.CurrentOS       (toText)
diff --git a/src/Proto3/Suite/Types.hs b/src/Proto3/Suite/Types.hs
index c97db88..9269515 100644
--- a/src/Proto3/Suite/Types.hs
+++ b/src/Proto3/Suite/Types.hs
@@ -62,7 +62,7 @@ instance (Bounded a, Enum a) => Arbitrary (Enumerated a) where
 -- the wire format.
 newtype PackedVec a = PackedVec { packedvec :: V.Vector a }
   deriving (Show, Eq, Functor, Foldable, Traversable, Ord, NFData, Applicative,
-            Alternative, Monoid)
+            Alternative, Monoid, Semigroup)

 instance IsList (PackedVec a) where
   type Item (PackedVec a) = a
@@ -74,7 +74,7 @@ instance Arbitrary a => Arbitrary (PackedVec a) where

 newtype UnpackedVec a = UnpackedVec {unpackedvec :: V.Vector a }
   deriving (Show, Eq, Functor, Foldable, Traversable, Ord, NFData, Applicative,
-            Alternative, Monoid)
+            Alternative, Monoid, Semigroup)

 instance IsList (UnpackedVec a) where
   type Item (UnpackedVec a) = a
@@ -87,7 +87,7 @@ instance Arbitrary a => Arbitrary (UnpackedVec a) where
 newtype NestedVec a =
   NestedVec { nestedvec :: V.Vector a }
   deriving (Show, Eq, Functor, Foldable, Traversable, Ord, NFData, Applicative,
-            Alternative, Monoid)
+            Alternative, Monoid, Semigroup)

 instance IsList (NestedVec a) where
   type Item (NestedVec a) = a
@@ -99,19 +99,20 @@ instance Arbitrary a => Arbitrary (NestedVec a) where

 -- | 'Nested' provides a way to nest protobuf messages within protobuf messages.
 newtype Nested a = Nested { nested :: Maybe a }
-  deriving (Show, Eq, Ord, Generic, NFData, Monoid, Arbitrary, Functor, Foldable,
-            Traversable, Applicative, Alternative, Monad)
+  deriving (Show, Eq, Ord, Generic, NFData, Monoid, Semigroup, Arbitrary, Functor,
+            Foldable, Traversable, Applicative, Alternative, Monad)

 -- | 'ForceEmit' provides a way to force emission of field values, even when
 -- default-value semantics states otherwise. Used when serializing oneof
 -- subfields.
 newtype ForceEmit a = ForceEmit{ forceEmit :: a }
-  deriving (Show, Eq, Ord, Generic, NFData, Monoid, Arbitrary, Functor, Foldable,
-            Traversable)
+  deriving (Show, Eq, Ord, Generic, NFData, Monoid, Semigroup, Arbitrary, Functor,
+            Foldable, Traversable)

 -- | 'Commented' provides a way to add comments to generated @.proto@ files.
 newtype Commented (comment :: Symbol) a = Commented { unCommented :: a }
-  deriving (Show, Eq, Ord, Generic, NFData, Monoid, Arbitrary, Functor, Foldable, Traversable)
+  deriving (Show, Eq, Ord, Generic, NFData, Monoid, Semigroup, Arbitrary, Functor,
+            Foldable, Traversable)

 -- | A type operator synonym for 'Commented', so that we can write C-style
 -- comments on fields.

Also, FWIW, these upper bounds can probably be raised:

WARNING: Ignoring out of range dependency (allow-newer enabled): aeson-1.3.1.1. proto3-suite requires: >=1.1.1.0 && <1.2
WARNING: Ignoring out of range dependency (allow-newer enabled): pretty-show-1.7. proto3-suite requires: >=1.6.12 && <1.7
WARNING: Ignoring out of range dependency (allow-newer enabled): swagger2-2.2.2. proto3-suite requires: ==2.1.6