Skip to content

Commit 64c1837

Browse files
authored
Document GHC-58656 (#463)
* Document GHC-58656 * Apply suggestion from code review * Change -fwarn-safe to -Wsafe
1 parent 9b2afdf commit 64c1837

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
title: Module is inferred to be safe
3+
summary: If a module is inferred as safe, then it should be annotated as safe
4+
severity: warning
5+
flag: -Wsafe
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 does not contain loopholes such as `unsafePerformIO`.
10+
More details are available in [the GHC User's Guide](https://downloads.haskell.org/ghc/latest/docs/users_guide/exts/safe_haskell.html).
11+
The compiler can automatically infer whether a given module is safe or not.
12+
GHC can emit a warning if a module is inferred to be safe, but not annotated as safe.
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 -Wsafe #-}
3+
module InferredSafe 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 #-}
2+
{-# OPTIONS_GHC -Wsafe #-}
3+
module InferredSafe where
4+
5+
theAnswer :: Int
6+
theAnswer = 42
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
title: A module is inferred as safe but not annotated as safe
3+
---
4+
5+
In this example the module has been inferred to be safe, but not annotated as such.
6+
If the module is annotated, the warning disappears.
7+
8+
```
9+
messages/GHC-58656/inferred-safe/before/InferredSafe.hs:2:17: warning: [GHC-58656] [-Wsafe]
10+
‘InferredSafe’ has been inferred as safe!
11+
|
12+
2 | {-# OPTIONS_GHC -fwarn-safe #-}
13+
|
14+
```

0 commit comments

Comments
 (0)