//============================================================================================================//
/** {@inheritDoc} */
@Override public Expr resolve(Type p, Collection<ErrorWarning> warns) {
if (errors.size()>0) return this;
ErrorWarning w1=null, w2=null;
Type s=p;
switch(op) {
case NOT:
s=Type.FORMULA;
break;
case TRANSPOSE: case RCLOSURE: case CLOSURE:
if (warns!=null && op!=Op.TRANSPOSE && type.join(type).hasNoTuple())
w1=new ErrorWarning(pos, this+" is redundant since its domain and range are disjoint: "+sub.type.extract(2));
s = (op!=Op.TRANSPOSE) ? resolveClosure(p, sub.type) : sub.type.transpose().intersect(p).transpose() ;
if (warns!=null && s==EMPTY && p.hasTuple())
w2=new ErrorWarning(sub.span(),
"The value of this expression does not contribute to the value of the parent.\nParent's relevant type = "
+p+"\nThis expression's type = "+sub.type.extract(2));
break;
case CARDINALITY: case NO: case ONE: case SOME: case LONE:
s=Type.removesBoolAndInt(sub.type);
break;
case CAST2SIGINT:
s=Type.INT;
break;
case CAST2INT:
s=sub.type.intersect(SIGINT.type);
if (warns!=null && s.hasNoTuple())
w1=new ErrorWarning(sub.span(),
"This expression should contain Int atoms.\nInstead, its possible type(s) are:\n"+sub.type.extract(1));
break;
}
Expr sub = this.sub.resolve(s, warns);
if (w1!=null) warns.add(w1);