Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent export of default data constructor for
NonEmptyMap
.
This change adds a test to check that the default data constructor for `NonEmptyMap` is not exported. The default data constructor for 'NonEmptyMap' is not exported, by design, as the internal data structure has an invariant that must be preserved across all operations. Exporting the default constructor would make it possible for functions in other modules to break the invariant, opening the door to subtle regressions.
- Loading branch information
1 parent
4ca6909
commit b31fa45
Showing
4 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
lib/core/test/unit/Data/Map/NonEmpty/StrictSpec/TypeErrorSpec.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{-# OPTIONS_GHC -fdefer-type-errors #-} | ||
{-# OPTIONS_GHC -fno-warn-deferred-out-of-scope-variables #-} | ||
{-# OPTIONS_GHC -fno-warn-deferred-type-errors #-} | ||
{-# OPTIONS_GHC -fno-warn-dodgy-imports #-} | ||
{-# OPTIONS_GHC -fno-warn-unused-imports #-} | ||
|
||
module Data.Map.NonEmpty.StrictSpec.TypeErrorSpec | ||
( spec | ||
) where | ||
|
||
import Prelude | ||
|
||
import Data.Map.NonEmpty.Strict.Internal | ||
( NonEmptyMap (..) ) | ||
import Test.Hspec | ||
( Expectation, Spec, describe, it ) | ||
import Test.ShouldNotTypecheck | ||
( shouldNotTypecheck ) | ||
|
||
spec :: Spec | ||
spec = describe "Strict non-empty map type error tests" $ | ||
|
||
it "Default data constructor is not exported" $ | ||
testDefaultDataConstructorNotExported | ||
|
||
-- Test that the default data constructor for 'NonEmptyMap' is not exported. | ||
-- | ||
-- The default data constructor for 'NonEmptyMap' is not exported, by design, | ||
-- as the internal data structure has an invariant that must be preserved | ||
-- across all operations. | ||
-- | ||
-- Exporting the default data constructor would make it possible for functions | ||
-- in external modules to break the invariant, opening the door to subtle | ||
-- regressions. | ||
-- | ||
-- See the definition of 'NonEmptyMap' for more details of the invariant. | ||
-- | ||
testDefaultDataConstructorNotExported :: Expectation | ||
testDefaultDataConstructorNotExported = | ||
shouldNotTypecheck $ NonEmptyMap ((), ()) mempty |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.