Skip to content

Commit 6247f6d

Browse files
Document GHC-19244 (#465)
* Document GHC-19244 * Update message-index/messages/GHC-19244/index.md Co-authored-by: David Thrane Christiansen <[email protected]> --------- Co-authored-by: David Thrane Christiansen <[email protected]>
1 parent 98e4c0b commit 6247f6d

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
title: Module is annotated as trustworthy, but is inferred as safe
3+
summary: The module is annotated to be trustworthy, but it could be annotated as safe
4+
severity: warning
5+
flag: -Wtrustworthy-safe
6+
introduced: 9.6.1
7+
---
8+
9+
GHC implements the `SafeHaskell` extension which allows programmers to restrict modules to a specific subset which is considered safe, and restricts access to "escape hatches" such as `unsafePerformIO`.
10+
Details about Safe Haskell are available in [the GHC User's Guide](https://downloads.haskell.org/ghc/latest/docs/users_guide/exts/safe_haskell.html).
11+
There are two levels of safety: Safe modules are checked by GHC and are guaranteed to be safe, whereas trustworthy modules are checked by
12+
the programmer who promises that the code cannot violate the guarantees of safe Haskell.
13+
If GHC sees a module which is annotated as trustworthy, but inferred as safe, it emits a warning that the stricter "safe" annotation should be used instead.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{-# LANGUAGE Haskell2010, Safe #-}
2+
{-# OPTIONS_GHC -fwarn-trustworthy-safe #-}
3+
module TrustworthySafe where
4+
5+
theAnswer :: Int
6+
theAnswer = 42
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{-# LANGUAGE Haskell2010, Trustworthy #-}
2+
{-# OPTIONS_GHC -fwarn-trustworthy-safe #-}
3+
module TrustworthySafe where
4+
5+
theAnswer :: Int
6+
theAnswer = 42
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
title: A module was annotated as trustworthy, but inferred as safe
3+
---
4+
5+
In this example the module was annotated as trustworthy, but GHC inferred that the module is also safe.
6+
Since "safe" is a stronger guarantee than "trustworthy", GHC warns that the module should be annotated as safe instead.
7+
The warning can therefore be fixed by changing the annotation from trustworthy to safe.
8+
9+
```
10+
messages/GHC-19244/trustworthy-safe/before/TrustworthySafe.hs:1:27: warning: [GHC-19244] [-Wtrustworthy-safe]
11+
‘TrustworthySafe’ is marked as Trustworthy but has been inferred as safe!
12+
|
13+
1 | {-# LANGUAGE Haskell2010, Trustworthy #-}
14+
|
15+
```

0 commit comments

Comments
 (0)