diff options
author | Aaron Allen <aaron@flipstone.com> | 2022-01-09 22:12:09 -0600 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2022-03-16 02:27:48 -0400 |
commit | c1fed9da095303591c37c53bad5f5559381048d7 (patch) | |
tree | ab5e40fa10263c1c1bf8f584da0f0396f7a9de15 | |
parent | 577135bf2251cf0aecf07ebb4966659d3fcc62b5 (diff) | |
download | haskell-c1fed9da095303591c37c53bad5f5559381048d7.tar.gz |
Suggest FFI extensions as hints (#20116)
- Use extension suggestion hints instead of suggesting extensions in the
error message body for several FFI errors.
- Adds a test case for `TcRnForeignImportPrimExtNotSet`
-rw-r--r-- | compiler/GHC/Tc/Errors/Ppr.hs | 8 | ||||
-rw-r--r-- | compiler/GHC/Tc/Errors/Types.hs | 2 | ||||
-rw-r--r-- | testsuite/tests/ffi/should_fail/T10461.stderr | 11 | ||||
-rw-r--r-- | testsuite/tests/ffi/should_fail/T20116.hs | 8 | ||||
-rw-r--r-- | testsuite/tests/ffi/should_fail/T20116.stderr | 6 | ||||
-rw-r--r-- | testsuite/tests/ffi/should_fail/all.T | 1 |
6 files changed, 26 insertions, 10 deletions
diff --git a/compiler/GHC/Tc/Errors/Ppr.hs b/compiler/GHC/Tc/Errors/Ppr.hs index 6cdfe963c7..29da277c8d 100644 --- a/compiler/GHC/Tc/Errors/Ppr.hs +++ b/compiler/GHC/Tc/Errors/Ppr.hs @@ -48,7 +48,6 @@ import {-# SOURCE #-} GHC.Tc.Types (getLclEnvLoc) import GHC.Tc.Types.Origin import GHC.Tc.Types.Rank (Rank(..)) import GHC.Tc.Utils.TcType -import GHC.Types.Basic (UnboxedTupleOrSum(..), unboxedTupleOrSumExtension) import GHC.Types.Error import GHC.Types.FieldLabel (flIsOverloaded) import GHC.Types.Hint.Ppr () -- Outputable GhcHint @@ -715,7 +714,7 @@ instance Diagnostic TcRnMessage where TcRnForeignImportPrimExtNotSet _decl -> mkSimpleDecorated $ - text "Use GHCForeignImportPrim to allow `foreign import prim'." + text "`foreign import prim' requires GHCForeignImportPrim." TcRnForeignImportPrimSafeAnn _decl -> mkSimpleDecorated $ @@ -771,7 +770,7 @@ instance Diagnostic TcRnMessage where text "because the data constructor for" <+> quotes (ppr tc) <+> text "is not in scope" UnliftedFFITypesNeeded -> - innerMsg $$ text "To marshal unlifted types, use UnliftedFFITypes" + innerMsg $$ text "UnliftedFFITypes is required to marshal unlifted types" NotABoxedMarshalableTyCon -> innerMsg ForeignLabelNotAPtr -> innerMsg $$ text "A foreign-imported address (via &foo) must have type (Ptr a) or (FunPtr a)" @@ -1298,7 +1297,7 @@ instance Diagnostic TcRnMessage where TcRnWarnDefaulting {} -> noHints TcRnForeignImportPrimExtNotSet{} - -> noHints + -> [suggestExtension LangExt.GHCForeignImportPrim] TcRnForeignImportPrimSafeAnn{} -> noHints TcRnForeignFunctionImportAsValue{} @@ -1313,6 +1312,7 @@ instance Diagnostic TcRnMessage where -> case reason of TypeCannotBeMarshaled _ why | NewtypeDataConNotInScope{} <- why -> [SuggestImportingDataCon] + | UnliftedFFITypesNeeded <- why -> [suggestExtension LangExt.UnliftedFFITypes] _ -> noHints TcRnInvalidCIdentifier{} -> noHints diff --git a/compiler/GHC/Tc/Errors/Types.hs b/compiler/GHC/Tc/Errors/Types.hs index 7a44ab08ef..78be225cf9 100644 --- a/compiler/GHC/Tc/Errors/Types.hs +++ b/compiler/GHC/Tc/Errors/Types.hs @@ -1701,7 +1701,7 @@ data TcRnMessage where Example(s): foreign import prim "foo" foo :: ByteArray# -> (# Int#, Int# #) - Test cases: None + Test cases: ffi/should_fail/T20116 -} TcRnForeignImportPrimExtNotSet :: ForeignImport -> TcRnMessage diff --git a/testsuite/tests/ffi/should_fail/T10461.stderr b/testsuite/tests/ffi/should_fail/T10461.stderr index 3421467715..47df47b97f 100644 --- a/testsuite/tests/ffi/should_fail/T10461.stderr +++ b/testsuite/tests/ffi/should_fail/T10461.stderr @@ -1,7 +1,8 @@ T10461.hs:6:1: error: - Unacceptable result type in foreign declaration: - ‘Word#’ cannot be marshalled in a foreign call - To marshal unlifted types, use UnliftedFFITypes - When checking declaration: - foreign import prim safe cheneycopy :: Any -> Word# + • Unacceptable result type in foreign declaration: + ‘Word#’ cannot be marshalled in a foreign call + UnliftedFFITypes is required to marshal unlifted types + • When checking declaration: + foreign import prim safe cheneycopy :: Any -> Word# + Suggested fix: Perhaps you intended to use UnliftedFFITypes diff --git a/testsuite/tests/ffi/should_fail/T20116.hs b/testsuite/tests/ffi/should_fail/T20116.hs new file mode 100644 index 0000000000..ca8c4fbbdf --- /dev/null +++ b/testsuite/tests/ffi/should_fail/T20116.hs @@ -0,0 +1,8 @@ +{-# LANGUAGE MagicHash #-} +{-# LANGUAGE ForeignFunctionInterface #-} + +module Foo where + +import GHC.Exts + +foreign import prim "test_lt" lt_s :: Int64# -> Int64# -> Int# diff --git a/testsuite/tests/ffi/should_fail/T20116.stderr b/testsuite/tests/ffi/should_fail/T20116.stderr new file mode 100644 index 0000000000..dbc06bf9a0 --- /dev/null +++ b/testsuite/tests/ffi/should_fail/T20116.stderr @@ -0,0 +1,6 @@ + +T20116.hs:8:1: error: + • `foreign import prim' requires GHCForeignImportPrim. + • When checking declaration: + foreign import prim safe "test_lt" lt_s :: Int64# -> Int64# -> Int# + Suggested fix: Perhaps you intended to use GHCForeignImportPrim diff --git a/testsuite/tests/ffi/should_fail/all.T b/testsuite/tests/ffi/should_fail/all.T index ce1c10534e..24210dcca6 100644 --- a/testsuite/tests/ffi/should_fail/all.T +++ b/testsuite/tests/ffi/should_fail/all.T @@ -16,6 +16,7 @@ test('T7506', normal, compile_fail, ['']) test('T7243', normal, compile_fail, ['']) test('T10461', normal, compile_fail, ['']) test('T16702', normal, compile_fail, ['']) +test('T20116', normal, compile_fail, ['']) # UnsafeReenter tests implementation of an undefined behavior (calling Haskell # from an unsafe foreign function) and only makes sense in non-threaded way |