@@ -1,6 +1,7 @@
1{-# OPTIONS_GHC -Wall #-}
1{-# OPTIONS_GHC -Wall #-}
2module Reporting.Error.Type where
2module Reporting.Error.Type where
4+import qualified Data.Map as Map
4import qualified Data.Maybe as Maybe
5import qualified Data.Maybe as Maybe
5import Text.PrettyPrint.ANSI.Leijen
6import Text.PrettyPrint.ANSI.Leijen
6 ( Doc, (<>), (<+>), colon, dullyellow, equals
7 ( Doc, (<>), (<+>), colon, dullyellow, equals
@@ -230,7 +231,7 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
230 ( cmpHint
231 ( cmpHint
231 (prettyName op ++ " is expecting the left argument to be a:")
232 (prettyName op ++ " is expecting the left argument to be a:")
232 "But the left argument is:"
233 "But the left argument is:"
233− []
234+ (binopHint op leftType rightType)
236 BinopRight op region ->
237 BinopRight op region ->
@@ -240,10 +241,13 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
240 ( cmpHint
241 ( cmpHint
241 (prettyName op ++ " is expecting the right argument to be a:")
242 (prettyName op ++ " is expecting the right argument to be a:")
242 "But the right argument is:"
243 "But the right argument is:"
244+ ( binopHint op leftType rightType
243− [ "I always figure out the type of the left argument first and if it is\
246+ [ "I always figure out the type of the left argument first and if it is\
244− \ acceptable on its own, I assume it is \"correct\" in subsequent checks.\
247+ \ acceptable on its own, I assume it is \"correct\" in subsequent checks.\
245− \ So the problem may actually be in how the left and right arguments interact."
248+ \ So the problem may actually be in how the left and right arguments interact."
249 Binop op ->
253 Binop op ->
@@ -446,6 +450,33 @@ comparisonHint localizer leftType rightType leftWords rightWords finalHints =
455+binopHint :: Var.Canonical -> Type.Canonical -> Type.Canonical -> [String]
456+binopHint op leftType rightType =
459+ show (RenderType.toDoc Map.empty leftType)
462+ show (RenderType.toDoc Map.empty rightType)
464+ if Var.is ["Basics"] "+" op && elem "String" [leftString, rightString] then
465+ [ "To append strings in Elm, you need to use the (++) operator, not (+). "
466+ ++ "<http://package.elm-lang.org/packages/elm-lang/core/latest/Basics#++>"
469+ else if Var.is ["Basics"] "/" op && elem "Int" [leftString, rightString] then
470+ [ "The (/) operator is specifically for floating point division, and (//) is\
471+ \ for integer division. You may need to do some conversions between ints and\
472+ \ floats to get both arguments matching the division operator you want."
449-- MISMATCH HELPERS
480-- MISMATCH HELPERS