Skip to content

Commit c25d2f8

Browse files
committed
Merge pull request purescript#1284 from mjgpy3/1272_reduce_false_positives_comp_sugg
Only make composition suggestion on `object . app function`
2 parents ef61dad + 9c61180 commit c25d2f8

File tree

5 files changed

+31
-5
lines changed

5 files changed

+31
-5
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module DoNotSuggestComposition where
2+
3+
import Prelude
4+
5+
x = { y: 3 }
6+
7+
foo :: String -> String
8+
foo y = y
9+
10+
bar = foo x
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module DoNotSuggestComposition2 where
2+
3+
foo = let x = { y: 3 } in x 2
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module SuggestComposition where
2+
3+
import Prelude
4+
5+
f = g . g where g = (+1)

src/Language/PureScript/Environment.hs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,17 @@ tyObject = primTy "Object"
214214
-- Check whether a type is an object
215215
--
216216
isObject :: Type -> Bool
217-
isObject = (==) tyObject . extract
218-
where extract (TypeApp t _) = t
219-
extract t = t
217+
isObject = isTypeOrApplied tyObject
218+
219+
-- |
220+
-- Check whether a type is a function
221+
--
222+
isFunction :: Type -> Bool
223+
isFunction = isTypeOrApplied tyFunction
224+
225+
isTypeOrApplied :: Type -> Type -> Bool
226+
isTypeOrApplied t1 (TypeApp t2 _) = t1 == t2
227+
isTypeOrApplied t1 t2 = t1 == t2
220228

221229
-- |
222230
-- Smart constructor for function types

src/Language/PureScript/Errors.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import Control.Monad.Trans.State.Lazy
3535
import Control.Arrow(first)
3636

3737
import Language.PureScript.AST
38-
import Language.PureScript.Environment (isObject)
38+
import Language.PureScript.Environment (isObject, isFunction)
3939
import Language.PureScript.Pretty
4040
import Language.PureScript.Types
4141
import Language.PureScript.Names
@@ -670,7 +670,7 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInError
670670
, indent . line $ "import " ++ show im ++ " hiding (" ++ nm ++ ")"
671671
]
672672
suggestions' (TypesDoNotUnify t1 t2)
673-
| any isObject [t1, t2] = [line "Note that function composition in PureScript is defined using (<<<)"]
673+
| isObject t1 && isFunction t2 = [line "Note that function composition in PureScript is defined using (<<<)"]
674674
| otherwise = []
675675
suggestions' _ = []
676676

0 commit comments

Comments
 (0)