private IEntity ConstructAmbiguousEntity(Node constructionNode, Ambiguous ambiguousDefinition, IType[] typeArguments)
{
var checker = new GenericConstructionChecker(typeArguments, constructionNode);
var matches = new List<IEntity>(ambiguousDefinition.Entities);
bool reportErrors = false;
foreach (Predicate<IEntity> check in checker.Checks)
{
matches = matches.Collect(check);
if (matches.Count == 0)
{
Errors.Add(checker.Errors[0]); // only report first error, assuming the rest are superfluous
return TypeSystemServices.ErrorEntity;
}
if (reportErrors)
checker.ReportErrors(Errors);
checker.DiscardErrors();
// We only want full error reporting once we get down to a single candidate
if (matches.Count == 1)
reportErrors = true;
}
IEntity[] constructedMatches = Array.ConvertAll<IEntity, IEntity>(matches.ToArray(), def => MakeGenericEntity(def, typeArguments));
return Entities.EntityFromList(constructedMatches);
}