From aa8a4e5e8c2fc772550da6597d740c5b0c5a5a42 Mon Sep 17 00:00:00 2001 From: Cyril Sobierajewicz Date: Fri, 13 Mar 2020 19:10:34 +0100 Subject: [PATCH] Deprecate primes in identifiers exported from foreign modules --- CONTRIBUTORS.md | 1 + src/Language/PureScript/Errors.hs | 9 +++ src/Language/PureScript/Make/Actions.hs | 9 +++ tests/purs/passing/2172.purs | 10 ---- .../2172.js => warning/DeprecatedFFIPrime.js} | 0 tests/purs/warning/DeprecatedFFIPrime.out | 56 +++++++++++++++++++ tests/purs/warning/DeprecatedFFIPrime.purs | 10 ++++ 7 files changed, 85 insertions(+), 10 deletions(-) delete mode 100644 tests/purs/passing/2172.purs rename tests/purs/{passing/2172.js => warning/DeprecatedFFIPrime.js} (100%) create mode 100644 tests/purs/warning/DeprecatedFFIPrime.out create mode 100644 tests/purs/warning/DeprecatedFFIPrime.purs diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 34b9b2e768..7e8228b146 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -139,6 +139,7 @@ If you would prefer to use different terms, please use the section below instead | [@matthew-hilty](https://github.com/matthew-hilty) | Matthew Hilty | [MIT license](http://opensource.org/licenses/MIT) | | [@woody88](https://github.com/woody88) | Woodson Delhia | [MIT license](http://opensource.org/licenses/MIT) | | [@mhmdanas](https://github.com/mhmdanas) | Mohammed Anas | [MIT license](http://opensource.org/licenses/MIT) | +| [@kl0tl](https://github.com/kl0tl) | Cyril Sobierajewicz | [MIT license](http://opensource.org/licenses/MIT) | ### Contributors using Modified Terms diff --git a/src/Language/PureScript/Errors.hs b/src/Language/PureScript/Errors.hs index 5e6260d83b..90dfc43fdd 100644 --- a/src/Language/PureScript/Errors.hs +++ b/src/Language/PureScript/Errors.hs @@ -63,6 +63,7 @@ data SimpleErrorMessage | MissingFFIImplementations ModuleName [Ident] | UnusedFFIImplementations ModuleName [Ident] | InvalidFFIIdentifier ModuleName Text + | DeprecatedFFIPrime ModuleName Text | FileIOError Text IOError -- ^ A description of what we were trying to do, and the error which occurred | InfiniteType SourceType | InfiniteKind SourceType @@ -221,6 +222,7 @@ errorCode em = case unwrapErrorMessage em of MissingFFIImplementations{} -> "MissingFFIImplementations" UnusedFFIImplementations{} -> "UnusedFFIImplementations" InvalidFFIIdentifier{} -> "InvalidFFIIdentifier" + DeprecatedFFIPrime{} -> "DeprecatedFFIPrime" FileIOError{} -> "FileIOError" InfiniteType{} -> "InfiniteType" InfiniteKind{} -> "InfiniteKind" @@ -669,6 +671,13 @@ prettyPrintSingleError (PPEOptions codeColor full level showDocs relPath) e = fl , line "Note that exported identifiers in FFI modules must be valid PureScript identifiers." ] ] + renderSimpleErrorMessage (DeprecatedFFIPrime mn ident) = + paras [ line $ "In the FFI module for " <> markCode (runModuleName mn) <> ":" + , indent . paras $ + [ line $ "The identifier " <> markCode ident <> " contains a prime (" <> markCode "'" <> ")." + , line $ "Primes in identifiers exported from FFI modules are deprecated and won’t be supported in the future." + ] + ] renderSimpleErrorMessage InvalidDoBind = line "The last statement in a 'do' block must be an expression, but this block ends with a binder." renderSimpleErrorMessage InvalidDoLet = diff --git a/src/Language/PureScript/Make/Actions.hs b/src/Language/PureScript/Make/Actions.hs index c3a0d2fab5..9fbaf6f2c7 100644 --- a/src/Language/PureScript/Make/Actions.hs +++ b/src/Language/PureScript/Make/Actions.hs @@ -285,6 +285,11 @@ checkForeignDecls m path = do js <- either (errorParsingModule . Bundle.UnableToParseModule) pure $ JS.parse jsStr path foreignIdentsStrs <- either errorParsingModule pure $ getExps js + + let deprecatedFFI = filter (any (== '\'')) foreignIdentsStrs + unless (null deprecatedFFI) $ + warningDeprecatedForeignPrimes deprecatedFFI + foreignIdents <- either errorInvalidForeignIdentifiers (pure . S.fromList) @@ -315,6 +320,10 @@ checkForeignDecls m path = do errorInvalidForeignIdentifiers = throwError . mconcat . map (errorMessage . InvalidFFIIdentifier mname . T.pack) + warningDeprecatedForeignPrimes :: [String] -> Make () + warningDeprecatedForeignPrimes = + tell . mconcat . map (errorMessage' modSS . DeprecatedFFIPrime mname . T.pack) + parseIdents :: [String] -> Either [String] [Ident] parseIdents strs = case partitionEithers (map parseIdent strs) of diff --git a/tests/purs/passing/2172.purs b/tests/purs/passing/2172.purs deleted file mode 100644 index 34580ccd3d..0000000000 --- a/tests/purs/passing/2172.purs +++ /dev/null @@ -1,10 +0,0 @@ -module Main where - -import Effect.Console (log) - -foreign import a' :: Number -foreign import b' :: Number -foreign import c' :: Number -foreign import d' :: Number - -main = log "Done" diff --git a/tests/purs/passing/2172.js b/tests/purs/warning/DeprecatedFFIPrime.js similarity index 100% rename from tests/purs/passing/2172.js rename to tests/purs/warning/DeprecatedFFIPrime.js diff --git a/tests/purs/warning/DeprecatedFFIPrime.out b/tests/purs/warning/DeprecatedFFIPrime.out new file mode 100644 index 0000000000..893228ea45 --- /dev/null +++ b/tests/purs/warning/DeprecatedFFIPrime.out @@ -0,0 +1,56 @@ +Error 1 of 4: + + at tests/purs/warning/DeprecatedFFIPrime.purs:5:1 - 10:28 (line 5, column 1 - line 10, column 28) + + In the FFI module for Main: + + The identifier a' contains a prime ('). + Primes in identifiers exported from FFI modules are deprecated and won’t be supported in the future. + + + + See https://github.com/purescript/documentation/blob/master/errors/DeprecatedFFIPrime.md for more information, + or to contribute content related to this error. + +Error 2 of 4: + + at tests/purs/warning/DeprecatedFFIPrime.purs:5:1 - 10:28 (line 5, column 1 - line 10, column 28) + + In the FFI module for Main: + + The identifier b' contains a prime ('). + Primes in identifiers exported from FFI modules are deprecated and won’t be supported in the future. + + + + See https://github.com/purescript/documentation/blob/master/errors/DeprecatedFFIPrime.md for more information, + or to contribute content related to this error. + +Error 3 of 4: + + at tests/purs/warning/DeprecatedFFIPrime.purs:5:1 - 10:28 (line 5, column 1 - line 10, column 28) + + In the FFI module for Main: + + The identifier c' contains a prime ('). + Primes in identifiers exported from FFI modules are deprecated and won’t be supported in the future. + + + + See https://github.com/purescript/documentation/blob/master/errors/DeprecatedFFIPrime.md for more information, + or to contribute content related to this error. + +Error 4 of 4: + + at tests/purs/warning/DeprecatedFFIPrime.purs:5:1 - 10:28 (line 5, column 1 - line 10, column 28) + + In the FFI module for Main: + + The identifier d' contains a prime ('). + Primes in identifiers exported from FFI modules are deprecated and won’t be supported in the future. + + + + See https://github.com/purescript/documentation/blob/master/errors/DeprecatedFFIPrime.md for more information, + or to contribute content related to this error. + diff --git a/tests/purs/warning/DeprecatedFFIPrime.purs b/tests/purs/warning/DeprecatedFFIPrime.purs new file mode 100644 index 0000000000..3c57a19d92 --- /dev/null +++ b/tests/purs/warning/DeprecatedFFIPrime.purs @@ -0,0 +1,10 @@ +-- @shouldWarnWith DeprecatedFFIPrime +-- @shouldWarnWith DeprecatedFFIPrime +-- @shouldWarnWith DeprecatedFFIPrime +-- @shouldWarnWith DeprecatedFFIPrime +module Main where + +foreign import a' :: Number +foreign import b' :: Number +foreign import c' :: Number +foreign import d' :: Number