Skip to content

Commit 7ecdd21

Browse files
authored
Pass correct SafeHaskell information to mkIfaceTc (#489)
Seems like this was never implemented the first time, woops! Fixes #424
1 parent 8ba58cc commit 7ecdd21

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

src/Development/IDE/Core/Compile.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,11 @@ mkTcModuleResult
234234
-> m TcModuleResult
235235
mkTcModuleResult tcm = do
236236
session <- getSession
237+
let sf = modInfoSafe (tm_checked_module_info tcm)
237238
#if MIN_GHC_API_VERSION(8,10,0)
238-
iface <- liftIO $ mkIfaceTc session Sf_None details tcGblEnv
239+
iface <- liftIO $ mkIfaceTc session sf details tcGblEnv
239240
#else
240-
(iface, _) <- liftIO $ mkIfaceTc session Nothing Sf_None details tcGblEnv
241+
(iface, _) <- liftIO $ mkIfaceTc session Nothing sf details tcGblEnv
241242
#endif
242243
let mod_info = HomeModInfo iface details Nothing
243244
return $ TcModuleResult tcm mod_info

test/exe/Main.hs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ main = defaultMainWithRerun $ testGroup "HIE"
6363
, pluginTests
6464
, preprocessorTests
6565
, thTests
66+
, safeTests
6667
, unitTests
6768
, haddockTests
6869
, positionMappingTests
@@ -1485,6 +1486,36 @@ preprocessorTests = testSessionWait "preprocessor" $ do
14851486
)
14861487
]
14871488

1489+
1490+
safeTests :: TestTree
1491+
safeTests =
1492+
testGroup
1493+
"SafeHaskell"
1494+
[ -- Test for https://github.com/digital-asset/ghcide/issues/424
1495+
testSessionWait "load" $ do
1496+
let sourceA =
1497+
T.unlines
1498+
["{-# LANGUAGE Trustworthy #-}"
1499+
,"module A where"
1500+
,"import System.IO.Unsafe"
1501+
,"import System.IO"
1502+
,"trustWorthyId :: a -> a"
1503+
,"trustWorthyId i = unsafePerformIO $ do"
1504+
," putStrLn \"I'm safe\""
1505+
," return i"]
1506+
sourceB =
1507+
T.unlines
1508+
["{-# LANGUAGE Safe #-}"
1509+
,"module B where"
1510+
,"import A"
1511+
,"safeId :: a -> a"
1512+
,"safeId = trustWorthyId"
1513+
]
1514+
1515+
_ <- openDoc' "A.hs" "haskell" sourceA
1516+
_ <- openDoc' "B.hs" "haskell" sourceB
1517+
expectNoMoreDiagnostics 1 ]
1518+
14881519
thTests :: TestTree
14891520
thTests =
14901521
testGroup

0 commit comments

Comments
 (0)