diff options
author | Joachim Breitner <mail@joachim-breitner.de> | 2021-01-20 20:33:30 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-02-13 21:28:49 -0500 |
commit | f1362008daabb518b6fcd8079fb89683fb642597 (patch) | |
tree | 171d08636f12373e4a721ed2449f0fe4c60f3d0f | |
parent | 448fd22d84a6d8100448861633f7918584bf97e8 (diff) | |
download | haskell-f1362008daabb518b6fcd8079fb89683fb642597.tar.gz |
Always set `safeInferred`, not only when it turns `False`
previously, `safeFlagCheck` would be happy to switch the `safeFlag` to
`False`, but not the other way around. This meant that after
:set -XGeneralizedNewtypeDeriving
:set -XNoGeneralizedNewtypeDeriving
in GHCi all loaded files would be still be infered as unsafe.
This fixes #19243.
This is a corner case, but somewhat relevant once ghci by default starts
with `GeneralizedNewtypeDeriving` on (due to GHC2021).
-rw-r--r-- | compiler/GHC/Driver/Session.hs | 7 | ||||
-rw-r--r-- | testsuite/tests/safeHaskell/ghci/T19243.hs | 4 | ||||
-rw-r--r-- | testsuite/tests/safeHaskell/ghci/T19243.script | 5 | ||||
-rw-r--r-- | testsuite/tests/safeHaskell/ghci/T19243.stdout | 4 | ||||
-rw-r--r-- | testsuite/tests/safeHaskell/ghci/all.T | 1 |
5 files changed, 17 insertions, 4 deletions
diff --git a/compiler/GHC/Driver/Session.hs b/compiler/GHC/Driver/Session.hs index 7d32e7ad8a..479223af9c 100644 --- a/compiler/GHC/Driver/Session.hs +++ b/compiler/GHC/Driver/Session.hs @@ -1862,10 +1862,9 @@ safeFlagCheck _ dflags | safeLanguageOn dflags = (dflagsUnset, warns) ++ str] safeFlagCheck cmdl dflags = - case (safeInferOn dflags) of - True | safeFlags -> (dflags', warn) - True -> (dflags' { safeInferred = False }, warn) - False -> (dflags', warn) + case safeInferOn dflags of + True -> (dflags' { safeInferred = safeFlags }, warn) + False -> (dflags', warn) where -- dynflags and warn for when -fpackage-trust by itself with no safe diff --git a/testsuite/tests/safeHaskell/ghci/T19243.hs b/testsuite/tests/safeHaskell/ghci/T19243.hs new file mode 100644 index 0000000000..b32102030e --- /dev/null +++ b/testsuite/tests/safeHaskell/ghci/T19243.hs @@ -0,0 +1,4 @@ +{-# LANGUAGE Haskell2010 #-} +module T19234 where +class A a +instance A Int diff --git a/testsuite/tests/safeHaskell/ghci/T19243.script b/testsuite/tests/safeHaskell/ghci/T19243.script new file mode 100644 index 0000000000..ad2fc64777 --- /dev/null +++ b/testsuite/tests/safeHaskell/ghci/T19243.script @@ -0,0 +1,5 @@ +:set -XGeneralizedNewtypeDeriving +:set -XNoGeneralizedNewtypeDeriving +:load T19243 +-- The following should report safe +:info A diff --git a/testsuite/tests/safeHaskell/ghci/T19243.stdout b/testsuite/tests/safeHaskell/ghci/T19243.stdout new file mode 100644 index 0000000000..93828deb9b --- /dev/null +++ b/testsuite/tests/safeHaskell/ghci/T19243.stdout @@ -0,0 +1,4 @@ +type A :: * -> Constraint +class A a + -- Defined at T19243.hs:3:1 +instance [safe] A Int -- Defined at T19243.hs:4:10 diff --git a/testsuite/tests/safeHaskell/ghci/all.T b/testsuite/tests/safeHaskell/ghci/all.T index 040cc288f9..26f72d20b8 100644 --- a/testsuite/tests/safeHaskell/ghci/all.T +++ b/testsuite/tests/safeHaskell/ghci/all.T @@ -19,4 +19,5 @@ test('p17', normalise_version("bytestring"), ghci_script, ['p17.script']) # 7172 test('p18', normalise_version("bytestring"), ghci_script, ['p18.script']) test('T12509', [extra_hc_opts('-XSafe')], ghci_script, ['T12509.script']) +test('T19243', normal, ghci_script, ['T19243.script']) |