{-# OPTIONS_GHC -Wall -fwarn-tabs #-}
{-# OPTIONS_HADDOCK hide #-}
{-# LANGUAGE CPP #-}
#if __GLASGOW_HASKELL__ >= 701
{-# LANGUAGE Safe #-}
#endif
----------------------------------------------------------------
--                                                  ~ 2021.12.14
-- |
-- Module      :  Data.Trie.Internal.Errors
-- Copyright   :  2008--2021 wren romano
-- License     :  BSD-3-Clause
-- Maintainer  :  wren@cpan.org
-- Stability   :  internal
-- Portability :  portable
--
-- Internal convenience functions for giving error messages.
----------------------------------------------------------------

module Data.Trie.Internal.Errors (impossible) where

----------------------------------------------------------------
----------------------------------------------------------------

-- | The impossible happened. Use this instead of 'undefined'
-- whenever there's an unreachable case, an argument that shouldn't
-- ever get touched, etc.
impossible :: String -> a
impossible :: String -> a
impossible String
fn = String -> a
forall a. HasCallStack => String -> a
error (String -> String
formatMessage String
fn)
{-# INLINE impossible #-}
-- Inline the 'error' call itself, just not the string literals in the message.

formatMessage :: String -> String
formatMessage :: String -> String
formatMessage String
fn
    = String
"Data.Trie." String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
fn String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
": The impossible happened."
    String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"\nThis is a bug, please report it to the maintainer.\n"
{-# NOINLINE formatMessage #-}

-- N.B., at some point GHC adjusted 'error' to throw a
-- 'GHC.Exception.ErrorCall' which contains both the original message
-- and the location info.  So we shouldn't have to resort to tricks
-- like *loch* or *placeholders* use in order to get the exact
-- location of the errors.
--
-- For older versions of GHC, see this post for how
-- 'Control.Exception.assert' gets turned into
-- 'GHC.IO.Exception.assertError': <https://stackoverflow.com/a/22997767>

----------------------------------------------------------------
----------------------------------------------------------- fin.