diff --git a/common/Types.hs b/common/Types.hs index 74a0bbb..f813fa5 100644 --- a/common/Types.hs +++ b/common/Types.hs @@ -20,7 +20,7 @@ with this program. If not, see . module Types ( specTypeOfName, abbrevModeOfName, typeOfName, typeOfExpression, typeOfVariable, underlyingType, stripArrayType, abbrevModeOfVariable, abbrevModeOfSpec - , isRealType, isIntegerType, isCaseableType, resolveUserType, isSafeConversion, isPreciseConversion + , isRealType, isIntegerType, isCaseableType, resolveUserType, isSafeConversion, isPreciseConversion, isImplicitConversionRain , returnTypesOfFunction , BytesInResult(..), bytesInType, sizeOfReplicator, sizeOfStructured @@ -328,6 +328,16 @@ findMeta e = if null metaList then emptyMeta else head metaList findMeta' :: Meta -> Meta findMeta' m = m +-- | Checks whether a given conversion can be done implicitly in Rain +-- Parameters are src dest +isImplicitConversionRain :: A.Type -> A.Type -> Bool +isImplicitConversionRain x y + = if (x == y) + then True + else if (x == A.Bool || y == A.Bool) + then False + else isSafeConversion x y + -- | Is a conversion between two types precise (i.e. do you need to specify -- ROUND or TRUNC when doing it)? isPreciseConversion :: A.Type -> A.Type -> Bool diff --git a/frontends/RainPasses.hs b/frontends/RainPasses.hs index b184bd2..0e537ac 100644 --- a/frontends/RainPasses.hs +++ b/frontends/RainPasses.hs @@ -198,7 +198,7 @@ matchParamPass = everywhereM ((mkM matchParamPassProc) `extM` matchParamPassFunc --Adds a cast between two types if it is safe to do so, otherwise gives an error doCast :: Int -> A.Type -> A.Type -> A.Expression -> PassM A.Expression doCast index to from item - = if isSafeConversion from to + = if isImplicitConversionRain from to then return $ A.Conversion (findMeta item) A.DefaultConversion to item else dieP (findMeta item) $ "Could not perform implicit cast from supplied type: " ++ (show from) ++ " to expected type: " ++ (show to) ++ " for parameter (zero-based): " ++ (show index)