src/AstTypeAnalysis.cpp
TypeConstraint isSupertypeOf(const TypeVar& a, const Type& b) {
    struct C : public Constraint<TypeVar> {
        TypeVar a;
        const Type& b;
        mutable bool repeat;

        C(TypeVar a, const Type& b) : a(std::move(a)), b(b), repeat(true) {}

        bool update(Assignment<TypeVar>& ass) const override {
            // don't continually update super type constraints
            if (!repeat) {
                return false;
            }
            repeat = false;

            // get current value of variable a
            TypeSet& s = ass[a];

            // remove all types that are not super-types of b
            if (s.isAll()) {
                s = TypeSet(b);
                return true;
            }

            TypeSet res;
            for (const Type& t : s) {
                res.insert(getLeastCommonSupertypes(t, b));
            }

            // check whether there was a change
            if (res == s) {
                return false;
            }
            s = res;
            return true;
        }

        void print(std::ostream& out) const override {
            out << a << " >: " << b.getName();
        }
    };

    return std::make_shared<C>(a, b);
}
/**
 * A constraint factory ensuring that all the types associated to the variable
 * a are subtypes of type b.
 */
A constraint factory ensuring that all the types associated to the variable
a are subtypes of type b.
A constraint factory ensuring that all the types associated to the variable a are subtypes of type b .
TypeConstraint isSupertypeOf(const TypeVar& a, const Type& b) {
    struct C : public Constraint<TypeVar> {
        TypeVar a;
        const Type& b;
        mutable bool repeat;
        C(TypeVar a, const Type& b) : a(std::move(a)), b(b), repeat(true) {}
        bool update(Assignment<TypeVar>& ass) const override {
            if (!repeat) {
                return false;
            }
            repeat = false;
            TypeSet& s = ass[a];
            if (s.isAll()) {
                s = TypeSet(b);
                return true;
            }
            TypeSet res;
            for (const Type& t : s) {
                res.insert(getLeastCommonSupertypes(t, b));
            }
            if (res == s) {
                return false;
            }
            s = res;
            return true;
        }
        void print(std::ostream& out) const override {
            out << a << " >: " << b.getName();
        }
    };
    return std::make_shared<C>(a, b);
}
TypeConstraint isSupertypeOf ( const TypeVar & a , const Type & b ) { struct C : public Constraint < TypeVar > { TypeVar a ; const Type & b ; mutable bool repeat ; C ( TypeVar a , const Type & b ) : a ( std :: move ( a ) ) , b ( b ) , repeat ( true ) { } bool update ( Assignment < TypeVar > & ass ) const override { if ( ! repeat ) { return false ; } repeat = false ; TypeSet & s = ass [ a ] ; if ( s . isAll ( ) ) { s = TypeSet ( b ) ; return true ; } TypeSet res ; for ( const Type & t : s ) { res . insert ( getLeastCommonSupertypes ( t , b ) ) ; } if ( res == s ) { return false ; } s = res ; return true ; } void print ( std :: ostream & out ) const override { out << a << " " << b . getName ( ) ; } } ; return std :: make_shared < C > ( a , b ) ; }
A constraint factory ensuring that all the types associated to the variable
 a are subtypes of type b.
A constraint factory ensuring that all the types associated to the variable a are subtypes of type b .
// don't continually update super type constraints // get current value of variable a // remove all types that are not super-types of b // check whether there was a change