tuplex/python/src/PythonContext.cc
// This function returns true if there is an Option type that both t1, t2 can be classified as
// If it returns true, it places the "super option" type into the parameter [super].
// For example, t1=int, t2=None -> super = Option[int]
// Similarly, t1=(int, none), t2=(none, int) -> super = (Option[int], Option[int])
This function returns true if there is an Option type that both t1, t2 can be classified as
If it returns true, it places the "super option" type into the parameter [super].
This function returns true if there is an Option type that both t1 t2 can be classified as If it returns true it places the " super option " type into the parameter [ super ] .
bool hasSuperOptionType(python::Type t1, python::Type t2, python::Type &super) {
        if(t1 == t2) {
            super = t1;
            return true;
        }
        if(t1.isOptionType() && (t1.getReturnType() == t2 || python::Type::NULLVALUE == t2)) {
            super = t1;
            return true;
        }
        if(t2.isOptionType() && (t2.getReturnType() == t1 || python::Type::NULLVALUE == t1)) {
            super = t2;
            return true;
        }
        if(t1 == python::Type::NULLVALUE) {
            super = python::Type::makeOptionType(t2);
            return true;
        }
        if(t2 == python::Type::NULLVALUE) {
            super = python::Type::makeOptionType(t1);
            return true;
        }
        if (t1.isTupleType() && t2.isTupleType() && t1.parameters().size() == t2.parameters().size()) {
            std::vector<python::Type> types(t1.parameters().size());
            for(int i=0; i<types.size(); i++) {
                if(!hasSuperOptionType(t1.parameters()[i], t2.parameters()[i], types[i])) return false;
            }
            super = python::Type::makeTupleType(types);
            return true;
        }
        return false;
    }
bool hasSuperOptionType ( python :: Type t1 , python :: Type t2 , python :: Type & super ) { if ( t1 == t2 ) { super = t1 ; return true ; } if ( t1 . isOptionType ( ) && ( t1 . getReturnType ( ) == t2 || python :: Type :: NULLVALUE == t2 ) ) { super = t1 ; return true ; } if ( t2 . isOptionType ( ) && ( t2 . getReturnType ( ) == t1 || python :: Type :: NULLVALUE == t1 ) ) { super = t2 ; return true ; } if ( t1 == python :: Type :: NULLVALUE ) { super = python :: Type :: makeOptionType ( t2 ) ; return true ; } if ( t2 == python :: Type :: NULLVALUE ) { super = python :: Type :: makeOptionType ( t1 ) ; return true ; } if ( t1 . isTupleType ( ) && t2 . isTupleType ( ) && t1 . parameters ( ) . size ( ) == t2 . parameters ( ) . size ( ) ) { std :: vector < python :: Type > types ( t1 . parameters ( ) . size ( ) ) ; for ( int i = 0 ; i < types . size ( ) ; i ++ ) { if ( ! hasSuperOptionType ( t1 . parameters ( ) [ i ] , t2 . parameters ( ) [ i ] , types [ i ] ) ) return false ; } super = python :: Type :: makeTupleType ( types ) ; return true ; } return false ; }
This function returns true if there is an Option type that both t1, t2 can be classified as
If it returns true, it places the "super option" type into the parameter [super].
This function returns true if there is an Option type that both t1 t2 can be classified as If it returns true it places the " super option " type into the parameter [ super ] .
// same type // one of them is null // both tuples, recurse