public static bool Apply(TypeParameterName typeParam, ResolvedType typeParamRes) { var walker = new CheckForConstriction(typeParam); walker.OnType(typeParamRes); return(walker.SharedState.IsConstrictive); }
/// <summary> /// Walks the given ResolvedType, typeParamRes, and returns true if there is a reference /// to a different type parameter of the same callable as the given type parameter, typeParam, /// or the same type parameter but in a nested type. /// Otherwise returns false. /// </summary> public static bool IsConstrictiveResolution(TypeParameterName typeParam, ResolvedType typeParamRes) { if (typeParamRes.Resolution is ResolvedTypeKind.TypeParameter tp && tp.Item.Origin.Equals(typeParam.Item1)) { // If given a type parameter whose origin matches the callable, // the only valid resolution is a direct self-resolution return(!tp.Item.TypeName.Equals(typeParam.Item2)); } var walker = new CheckForConstriction(typeParam.Item1); walker.OnType(typeParamRes); return(walker.SharedState.IsConstrictive); }
// Methods /// <summary> /// Updates the combinesOverParameterConstriction flag. If the flag is already set to true, /// nothing will be done. If not, the given type parameter will be checked against the given /// resolution for type parameter constriction, which is when one type parameter is dependent /// on another type parameter of the same callable. /// </summary> private void UpdateConstrictionFlag(TypeParameterName typeParamName, ResolvedType typeParamResolution) { this.combinesOverParameterConstriction = this.combinesOverParameterConstriction || CheckForConstriction.IsConstrictiveResolution(typeParamName, typeParamResolution); }