typeLinkingExpr db imps su (CastC castnm _ expr _) = if null tps || null typeExpr || null casting then typeLinkingFailure $ "CastC: cannot type linking the expression" ++ (show expr) ++ (show tps) else [targetType]
        where
            tps = case typeLinkingName db imps su castnm of
                    [] -> typeLinkingFailure "CastC no match"
                    [TypeClass tp] -> [Object tp]
                    [tp] -> [tp]
                    tpss -> typeLinkingFailure $ "CastC multi match: " ++ (show tpss)
            typeExpr = typeLinkingExpr db imps su expr
            targetType = Array (head tps) -- BUG?
            casting = castConversion db (head typeExpr) targetType
typeLinkingExpr db imps su (CastC castnm _ expr _) = if null tps || null typeExpr || null casting then typeLinkingFailure $ "CastC: cannot type linking the expression" ++ (show expr) ++ (show tps) else [targetType]
        where
            tps = case typeLinkingName db imps su castnm of
                    [] -> typeLinkingFailure "CastC no match"
                    [TypeClass tp] -> [Object tp]
                    [tp] -> [tp]
                    tpss -> typeLinkingFailure $ "CastC multi match: " ++ (show tpss)
            typeExpr = typeLinkingExpr db imps su expr
            targetType = Array (head tps) -- BUG?
            casting = castConversion db (head typeExpr) targetType
typeLinkingExpr db imps su (CastC castnm _ expr _) = if null tps || null typeExpr || null casting then typeLinkingFailure $ "CastC: cannot type linking the expression" ++ (show expr) ++ (show tps) else [targetType]
        where
            tps = case typeLinkingName db imps su castnm of
                    [] -> typeLinkingFailure "CastC no match"
                    [TypeClass tp] -> [Object tp]
                    [tp] -> [tp]
                    tpss -> typeLinkingFailure $ "CastC multi match: " ++ (show tpss)
            typeExpr = typeLinkingExpr db imps su expr
            targetType = Array (head tps) -- BUG?
            casting = castConversion db (head typeExpr) targetType