Esempio n. 1
0
 /// <summary>
 /// Gets the best common type (C# 4.0 spec: §7.5.2.14) of a set of expressions.
 /// </summary>
 public IType GetBestCommonType(IList <ResolveResult> expressions, out bool success)
 {
     if (expressions == null)
     {
         throw new ArgumentNullException("expressions");
     }
     if (expressions.Count == 1)
     {
         success = (expressions[0].Type.Kind != TypeKind.Unknown);
         return(expressions[0].Type);
     }
     Log.WriteCollection("GetBestCommonType() for ", expressions);
     try {
         ITypeParameter tp = DummyTypeParameter.GetMethodTypeParameter(0);
         this.typeParameters = new TP[1] {
             new TP(tp)
         };
         foreach (ResolveResult r in expressions)
         {
             MakeOutputTypeInference(r, tp);
         }
         success = Fix(typeParameters[0]);
         return(typeParameters[0].FixedTo ?? SpecialType.UnknownType);
     } finally {
         Reset();
     }
 }
Esempio n. 2
0
 public override IType VisitTypeParameter(ITypeParameter type)
 {
     if (type.OwnerType == EntityType.Method)
     {
         return(DummyTypeParameter.GetMethodTypeParameter(type.Index));
     }
     else
     {
         return(base.VisitTypeParameter(type));
     }
 }
Esempio n. 3
0
 public ITypeParameter GetMethodTypeParameter(int index)
 {
     if (index < MethodTypeParameters?.Count)
     {
         return(MethodTypeParameters[index]);
     }
     else
     {
         return(DummyTypeParameter.GetMethodTypeParameter(index));
     }
 }
Esempio n. 4
0
 public override IType VisitTypeParameter(ITypeParameter type)
 {
     if (type.OwnerType == SymbolKind.Method && ReplaceMethodTypeParametersWithDummy)
     {
         return(DummyTypeParameter.GetMethodTypeParameter(type.Index));
     }
     else if (type.OwnerType == SymbolKind.TypeDefinition && ReplaceClassTypeParametersWithDummy)
     {
         return(DummyTypeParameter.GetClassTypeParameter(type.Index));
     }
     else
     {
         return(base.VisitTypeParameter(type));
     }
 }
Esempio n. 5
0
 public override IType VisitTypeParameter(ITypeParameter type)
 {
     if (type.OwnerType == SymbolKind.Method && ReplaceMethodTypeParametersWithDummy)
     {
         return(DummyTypeParameter.GetMethodTypeParameter(type.Index));
     }
     else if (type.OwnerType == SymbolKind.TypeDefinition && ReplaceClassTypeParametersWithDummy)
     {
         return(DummyTypeParameter.GetClassTypeParameter(type.Index));
     }
     else if (RemoveNullability && type is NullabilityAnnotatedTypeParameter natp)
     {
         return(natp.TypeWithoutAnnotation.AcceptVisitor(this));
     }
     else
     {
         return(base.VisitTypeParameter(type));
     }
 }