Skip to content

Commit

Permalink
Fix a warning when there are only enums, no messages. (#370)
Browse files Browse the repository at this point in the history
Previously we got:

```
...../build/enum_test/autogen/Proto/EnumOnly.hs:72:1: error: [-Wunused-top-binds, -Werror=unused-top-binds]
    Defined but not used: ‘packedFileDescriptor’
   |
72 | packedFileDescriptor
   | ^^^^^^^^^^^^^^^^^^^^
```

The check for whether the file had any messages was incorrect, since it didn't account for enums which are tracked in the same map.
  • Loading branch information
judah authored Dec 6, 2019
1 parent 712ef40 commit 7bb31dc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion proto-lens-protoc/app/Data/ProtoLens/Compiler/Generate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ generateModule modName fdesc imports publicImports definitions importedEnv servi
-- messages, it's omitted since it's only used inside of Message
-- instances.
packedFileDescriptorProto
| null definitions = []
| null [m | Message m <- Map.elems definitions] = []
| otherwise = [
typeSig "packedFileDescriptor" $ var "Data.ByteString.ByteString",
valBind "packedFileDescriptor" $ string packedFDesc
Expand Down
1 change: 1 addition & 0 deletions proto-lens-tests/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ tests:
generated-other-modules:
- Proto.Enum
- Proto.Enum_Fields
- Proto.EnumOnly

names_test:
main: names_test.hs
Expand Down
10 changes: 10 additions & 0 deletions proto-lens-tests/tests/enum_only.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// A file that only contains an enum, not a message.
// Checks that we're not generating unused top-level definitions.

syntax = "proto2";

package enums;

enum Lone {
LONE = 0;
}
8 changes: 7 additions & 1 deletion proto-lens-tests/tests/enum_test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Proto.Enum
, Alias(..)
, ManyCasesProto
)
import Proto.EnumOnly (Lone(..))
import Proto.Enum_Fields
import Data.Function (on)
import Data.ProtoLens
Expand Down Expand Up @@ -46,12 +47,13 @@ main = testMain
, testMonotonicFromEnum
, testAliases
, testManyCases
, testLone
]

testExternalEnum, testNestedEnum, testDefaults, testBadEnumValues,
testNamedEnumValues, testRoundTrip, testBounded, testMaybeSuccAndPred,
testEnumFromThenTo, testMonotonicFromEnum, testAliases,
testManyCases :: TestTree
testManyCases, testLone :: TestTree

testExternalEnum = testGroup "external"
[ serializeTo (show e1)
Expand Down Expand Up @@ -163,3 +165,7 @@ testAliases = testCase "alias" $ do

testManyCases =
runTypedTest (roundTripTest "many cases" :: TypedTest ManyCasesProto)

-- A trivial test to check that the module Lone came from was compiled
-- successfully.
testLone = testCase "no messages" $ LONE @?= LONE

0 comments on commit 7bb31dc

Please sign in to comment.