Skip to content

Commit 98e4c0b

Browse files
Document GHC-44360 (#464)
* Document GHC-44360 * Apply suggestions from code review Co-authored-by: David Thrane Christiansen <[email protected]> --------- Co-authored-by: David Thrane Christiansen <[email protected]>
1 parent 64c1837 commit 98e4c0b

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: Cannot import unsafe modules in Safe Haskell
3+
summary: Only safe modules can be imported in modules which are declared safe
4+
severity: error
5+
introduced: 9.6.1
6+
---
7+
8+
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`. More details are available in [the GHC User's Guide](https://downloads.haskell.org/ghc/latest/docs/users_guide/exts/safe_haskell.html).
9+
In order to uphold the guarantees of Safe Haskell, GHC does not allow modules which are declared safe to import unsafe modules.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
module UnsafeImport where
3+
4+
import Unsafe.Coerce
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{-# LANGUAGE Safe #-}
2+
module UnsafeImport where
3+
4+
import Unsafe.Coerce
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
title: Safe module tries to import Unsafe.Coerce
3+
---
4+
5+
This module tries to import the module `Unsafe.Coerce`, even though the module is declared to be safe.
6+
In order to use an unsafe module such as `Unsafe.Coerce`, the annotation which declares the module to be safe has to be removed.
7+
8+
```
9+
messages/GHC-44360/unsafe-import/before/UnsafeImport.hs:4:1: error: [GHC-44360]
10+
Unsafe.Coerce: Can't be safely imported!
11+
The module itself isn't safe.
12+
|
13+
4 | import Unsafe.Coerce
14+
| ^^^^^^^^^^^^^^^^^^^^
15+
```

0 commit comments

Comments
 (0)