//internal static void AddUseSiteDiagnostics( // this TypeSymbol type, // ref HashSet<DiagnosticInfo> useSiteDiagnostics) //{ // DiagnosticInfo errorInfo = type.GetUseSiteDiagnostic(); // if ((object)errorInfo != null) // { // if (useSiteDiagnostics == null) // { // useSiteDiagnostics = new HashSet<DiagnosticInfo>(); // } // useSiteDiagnostics.Add(errorInfo); // } //} /// <summary> /// Return all of the type parameters in this type and enclosing types, /// from outer-most to inner-most type. /// </summary> internal static ImmutableArray <TypeParameterSymbol> GetAllTypeParameters(this NamedTypeSymbol type) { // Avoid allocating a builder in the common case. if ((object)type.ContainingType == null) { return(type.TypeParameters); } var builder = ArrayBuilder <TypeParameterSymbol> .GetInstance(); type.GetAllTypeParameters(builder); return(builder.ToImmutableAndFree()); }
internal override TypeSymbol SubstituteTypeParameters( PEModuleSymbol moduleSymbol, TypeSymbol genericTypeDef, ImmutableArray <KeyValuePair <TypeSymbol, ImmutableArray <ModifierInfo <TypeSymbol> > > > arguments, ImmutableArray <bool> refersToNoPiaLocalType) { if (genericTypeDef is UnsupportedMetadataTypeSymbol) { return(genericTypeDef); } // Let's return unsupported metadata type if any argument is unsupported metadata type foreach (var arg in arguments) { if (arg.Key.Kind == SymbolKind.ErrorType && arg.Key is UnsupportedMetadataTypeSymbol) { return(new UnsupportedMetadataTypeSymbol()); } } NamedTypeSymbol genericType = (NamedTypeSymbol)genericTypeDef; //// See if it is or its enclosing type is a non-interface closed over NoPia local types. //ImmutableArray<AssemblySymbol> linkedAssemblies = moduleSymbol.ContainingAssembly.GetLinkedReferencedAssemblies(); //bool noPiaIllegalGenericInstantiation = false; //if (!linkedAssemblies.IsDefaultOrEmpty || moduleSymbol.Module.ContainsNoPiaLocalTypes()) //{ // NamedTypeSymbol typeToCheck = genericType; // int argumentIndex = refersToNoPiaLocalType.Length - 1; // do // { // if (!typeToCheck.IsInterface) // { // break; // } // else // { // argumentIndex -= typeToCheck.Arity; // } // typeToCheck = typeToCheck.ContainingType; // } // while ((object)typeToCheck != null); // for (int i = argumentIndex; i >= 0; i--) // { // if (refersToNoPiaLocalType[i] || // (!linkedAssemblies.IsDefaultOrEmpty && // MetadataDecoder.IsOrClosedOverATypeFromAssemblies(arguments[i].Key, linkedAssemblies))) // { // noPiaIllegalGenericInstantiation = true; // break; // } // } //} // Collect generic parameters for the type and its containers in the order // that matches passed in arguments, i.e. sorted by the nesting. ImmutableArray <TypeParameterSymbol> typeParameters = genericType.GetAllTypeParameters(); Debug.Assert(typeParameters.Length > 0); if (typeParameters.Length != arguments.Length) { return(new UnsupportedMetadataTypeSymbol()); } TypeMap substitution = new TypeMap(typeParameters, arguments.SelectAsArray(arg => new TypeWithModifiers(arg.Key, CSharpCustomModifier.Convert(arg.Value)))); NamedTypeSymbol constructedType = substitution.SubstituteNamedType(genericType); //if (noPiaIllegalGenericInstantiation) //{ // constructedType = new NoPiaIllegalGenericInstantiationSymbol(moduleSymbol, constructedType); //} return(constructedType); }