private TypeExpression InternalPromotion(UnionType from, object arg) { if (from.IsFreshVariable() && this.methodAnalyzed != null) { // * A constraint is added to the method analyzed PromotionConstraint constraint = new PromotionConstraint(from, this.to, this.op, this.location); this.methodAnalyzed.AddConstraint(constraint); return(this.to); } // * Static Behaviour: All the types in typeset must promote // * Dynamic Behaviour: One of the types in typeset must promote int aux = 0; UnionType dynamicUnionType = new UnionType(); dynamicUnionType.IsDynamic = true; foreach (TypeExpression subType in from.TypeSet) { if (from.IsDynamic) { // * Dynamic if (subType.IsFreshVariable()) { dynamicUnionType.AddType(subType); } else { aux = (int)subType.AcceptOperation(new PromotionLevelOperation(this.to), arg); if (aux != -1) { return(this.to); } } } else // * !from.IsDynamic, so it is static { aux = (int)subType.AcceptOperation(new PromotionLevelOperation(this.to), arg); if (aux == -1) { return((TypeExpression)ReportError(from)); } } } if (dynamicUnionType.Count != 0) // * If the union type is dynamic and no type in the type set promotes, then we generate a constraint with one promotion grouping the fresh types in the type set { PromotionConstraint constraint = new PromotionConstraint(dynamicUnionType, this.to, this.op, this.location); this.methodAnalyzed.AddConstraint(constraint); return(this.to); } if (from.IsDynamic && aux == -1) { // * No promotion at all return((TypeExpression)ReportError(from)); } return(this.to); }
public override object Exec(TypeVariable from, object arg) { if (from.Substitution != null) { DynVarOptions.Instance.AssignDynamism(from.Substitution, from.IsDynamic); return(from.Substitution.AcceptOperation(this, arg)); } if (methodAnalyzed != null) { // * A constraint is added to the method analyzed PromotionConstraint constraint = new PromotionConstraint(from, this.to, this.location); this.methodAnalyzed.AddConstraint(constraint); return(constraint.ReturnType); } return(ReportError(from)); }