diff options
Diffstat (limited to 'libraries')
-rw-r--r-- | libraries/base/Data/Maybe.hs | 5 | ||||
-rw-r--r-- | libraries/base/tests/fromJust.hs | 10 | ||||
-rw-r--r-- | libraries/base/tests/fromJust.stderr | 4 |
3 files changed, 17 insertions, 2 deletions
diff --git a/libraries/base/Data/Maybe.hs b/libraries/base/Data/Maybe.hs index d41ae92672..2a3e0efe7f 100644 --- a/libraries/base/Data/Maybe.hs +++ b/libraries/base/Data/Maybe.hs @@ -32,6 +32,7 @@ module Data.Maybe ) where import GHC.Base +import GHC.Stack.Types ( HasCallStack ) -- $setup -- Allow the use of some Prelude functions in doctests. @@ -143,8 +144,8 @@ isNothing _ = False -- >>> 2 * (fromJust Nothing) -- *** Exception: Maybe.fromJust: Nothing -- -fromJust :: Maybe a -> a -fromJust Nothing = errorWithoutStackTrace "Maybe.fromJust: Nothing" -- yuck +fromJust :: HasCallStack => Maybe a -> a +fromJust Nothing = error "Maybe.fromJust: Nothing" -- yuck fromJust (Just x) = x -- | The 'fromMaybe' function takes a default value and and 'Maybe' diff --git a/libraries/base/tests/fromJust.hs b/libraries/base/tests/fromJust.hs new file mode 100644 index 0000000000..2da524ffed --- /dev/null +++ b/libraries/base/tests/fromJust.hs @@ -0,0 +1,10 @@ +module Main where + +-- Trac #15559: Add HasCallStack to fromJust + +import Data.Maybe ( fromJust ) + +main :: IO () +main = do + _ <- fromJust Nothing `seq` return () + putStrLn "Should see a stacktrace instead of this" diff --git a/libraries/base/tests/fromJust.stderr b/libraries/base/tests/fromJust.stderr new file mode 100644 index 0000000000..9b3a63885f --- /dev/null +++ b/libraries/base/tests/fromJust.stderr @@ -0,0 +1,4 @@ +fromJust.hs: Maybe.fromJust: Nothing +CallStack (from HasCallStack): + error, called at libraries/base/Data/Maybe.hs:148:21 in base:Data.Maybe + fromJust, called at fromJust.hs:9:8 in main:Main |