presto-main/src/main/java/io/prestosql/metadata/SignatureBinder.java/SignatureBinder/canCast
class SignatureBinder:    private boolean canCast(Type fromType, Type toType)
    {
        if (toType instanceof UnknownType) {
            return true;
        }
        if (fromType instanceof RowType) {
            if (toType instanceof RowType) {
                List<Type> fromTypeParameters = fromType.getTypeParameters();
                List<Type> toTypeParameters = toType.getTypeParameters();
                if (fromTypeParameters.size() != toTypeParameters.size()) {
                    return false;
                }
                for (int fieldIndex = 0; fieldIndex < fromTypeParameters.size(); fieldIndex++) {
                    if (!canCast(fromTypeParameters.get(fieldIndex), toTypeParameters.get(fieldIndex))) {
                        return false;
                    }
                }
                return true;
            }
            else if (toType instanceof JsonType) {
                return fromType.getTypeParameters().stream()
                        .allMatch(fromTypeParameter -> canCast(fromTypeParameter, toType));
            }
            else {
                return false;
            }
        }
        if (fromType instanceof JsonType) {
            if (toType instanceof RowType) {
                return toType.getTypeParameters().stream()
                        .allMatch(toTypeParameter -> canCast(fromType, toTypeParameter));
            }
        }
        try {
            metadata.getCoercion(fromType, toType);
            return true;
        }
        catch (PrestoException e) {
            return false;
        }
    }