Binder\Binder_Expressions.cs (5)
5163return BindTypeParameterCreationExpression(node, (TypeParameterSymbol)type, diagnostics);
7023private BoundExpression BindTypeParameterCreationExpression(ObjectCreationExpressionSyntax node, TypeParameterSymbol typeParameter, BindingDiagnosticBag diagnostics)
7033private static bool TypeParameterHasParameterlessConstructor(SyntaxNode node, TypeParameterSymbol typeParameter, BindingDiagnosticBag diagnostics)
7045SyntaxNode node, TypeParameterSymbol typeParameter, AnalyzedArguments analyzedArguments, InitializerExpressionSyntax? initializerOpt,
8717if (receiverOpt is { Type: TypeParameterSymbol { AllowsRefLikeType: true } } &&
Binder\Binder_Lookup.cs (4)
185this.LookupMembersInTypeParameter(result, (TypeParameterSymbol)type, name, arity, basesBeingResolved, options, originalBinder, diagnose, ref useSiteInfo);
1168private void LookupMembersInTypeParameter(LookupResult current, TypeParameterSymbol typeParameter, string name, int arity, ConsList<TypeSymbol> basesBeingResolved, LookupOptions options, Binder originalBinder, bool diagnose, ref CompoundUseSiteInfo<AssemblySymbol> useSiteInfo)
1868this.AddMemberLookupSymbolsInfoInTypeParameter(result, (TypeParameterSymbol)type, options, originalBinder);
2033private void AddMemberLookupSymbolsInfoInTypeParameter(LookupSymbolsInfo result, TypeParameterSymbol type, LookupOptions options, Binder originalBinder)
Binder\Semantics\Conversions\ConversionsBase.cs (25)
1899private static bool HasIdentityConversionToAny(NamedTypeSymbol type, ArrayBuilder<(NamedTypeSymbol ParticipatingType, TypeParameterSymbol ConstrainedToTypeOpt)> targetTypes)
2672return HasImplicitReferenceTypeParameterConversion((TypeParameterSymbol)source, destination, ref useSiteInfo);
2851public bool HasImplicitTypeParameterConversion(TypeParameterSymbol source, TypeSymbol destination, ref CompoundUseSiteInfo<AssemblySymbol> useSiteInfo)
2863if (destination is TypeParameterSymbol { AllowsRefLikeType: false } &&
2865source.DependsOn((TypeParameterSymbol)destination))
2873private bool HasImplicitReferenceTypeParameterConversion(TypeParameterSymbol source, TypeSymbol destination, ref CompoundUseSiteInfo<AssemblySymbol> useSiteInfo)
2906if (destination is TypeParameterSymbol { AllowsRefLikeType: false } &&
2907source.DependsOn((TypeParameterSymbol)destination))
2916private bool HasImplicitEffectiveBaseConversion(TypeParameterSymbol source, TypeSymbol destination, ref CompoundUseSiteInfo<AssemblySymbol> useSiteInfo)
2940private bool HasImplicitEffectiveInterfaceSetConversion(TypeParameterSymbol source, TypeSymbol destination, ref CompoundUseSiteInfo<AssemblySymbol> useSiteInfo)
2945private bool HasVarianceCompatibleInterfaceInEffectiveInterfaceSet(TypeParameterSymbol source, TypeSymbol destination, ref CompoundUseSiteInfo<AssemblySymbol> useSiteInfo)
3023if (typeToCheck is TypeParameterSymbol typeParameter)
3188TypeParameterSymbol typeParameterSymbol = (TypeParameterSymbol)typeParameters[paramIndex].Type;
3250private bool HasImplicitBoxingTypeParameterConversion(TypeParameterSymbol source, TypeSymbol destination, ref CompoundUseSiteInfo<AssemblySymbol> useSiteInfo)
3283if (destination is TypeParameterSymbol { AllowsRefLikeType: false } d &&
3311HasImplicitBoxingTypeParameterConversion((TypeParameterSymbol)source, destination, ref useSiteInfo))
3535TypeParameterSymbol s = source as TypeParameterSymbol;
3536TypeParameterSymbol t = destination as TypeParameterSymbol;
3587TypeParameterSymbol s = source as TypeParameterSymbol;
3588TypeParameterSymbol t = destination as TypeParameterSymbol;
Binder\Semantics\Conversions\UserDefinedExplicitConversions.cs (7)
36var d = ArrayBuilder<(NamedTypeSymbol ParticipatingType, TypeParameterSymbol ConstrainedToTypeOpt)>.GetInstance();
74private static void ComputeUserDefinedExplicitConversionTypeSet(TypeSymbol source, TypeSymbol target, ArrayBuilder<(NamedTypeSymbol ParticipatingType, TypeParameterSymbol ConstrainedToTypeOpt)> d, ref CompoundUseSiteInfo<AssemblySymbol> useSiteInfo)
90ArrayBuilder<(NamedTypeSymbol ParticipatingType, TypeParameterSymbol ConstrainedToTypeOpt)> d,
102foreach ((NamedTypeSymbol declaringType, TypeParameterSymbol constrainedToTypeOpt) in d)
117foreach ((NamedTypeSymbol declaringType, TypeParameterSymbol constrainedToTypeOpt) in d)
127TypeParameterSymbol constrainedToTypeOpt,
146TypeParameterSymbol constrainedToTypeOpt,
Binder\Semantics\Conversions\UserDefinedImplicitConversions.cs (7)
80var d = ArrayBuilder<(NamedTypeSymbol ParticipatingType, TypeParameterSymbol ConstrainedToTypeOpt)>.GetInstance();
118private static void ComputeUserDefinedImplicitConversionTypeSet(TypeSymbol s, TypeSymbol t, ArrayBuilder<(NamedTypeSymbol ParticipatingType, TypeParameterSymbol ConstrainedToTypeOpt)> d, ref CompoundUseSiteInfo<AssemblySymbol> useSiteInfo)
146ArrayBuilder<(NamedTypeSymbol ParticipatingType, TypeParameterSymbol ConstrainedToTypeOpt)> d,
255foreach ((NamedTypeSymbol declaringType, TypeParameterSymbol constrainedToTypeOpt) in d)
270foreach ((NamedTypeSymbol declaringType, TypeParameterSymbol constrainedToTypeOpt) in d)
280TypeParameterSymbol constrainedToTypeOpt,
956var d = ArrayBuilder<(NamedTypeSymbol ParticipatingType, TypeParameterSymbol ConstrainedToTypeOpt)>.GetInstance();
Binder\WithCrefTypeParametersBinder.cs (10)
22private MultiDictionary<string, TypeParameterSymbol> _lazyTypeParameterMap;
30protected override MultiDictionary<string, TypeParameterSymbol> TypeParameterMap
36MultiDictionary<string, TypeParameterSymbol> map = CreateTypeParameterMap();
44private MultiDictionary<string, TypeParameterSymbol> CreateTypeParameterMap()
46var map = new MultiDictionary<string, TypeParameterSymbol>();
78private void AddTypeParameters(TypeSyntax typeSyntax, MultiDictionary<string, TypeParameterSymbol> map)
103private void AddTypeParameters(MemberCrefSyntax memberSyntax, MultiDictionary<string, TypeParameterSymbol> map)
112private static void AddTypeParameters(GenericNameSyntax genericNameSyntax, MultiDictionary<string, TypeParameterSymbol> map)
132TypeParameterSymbol typeParameterSymbol = new CrefTypeParameterSymbol(name, i, typeParameterSyntax);
145foreach (TypeParameterSymbol typeParameter in kvp.Value)
Symbols\ConstraintsHelper.cs (40)
28public readonly TypeParameterSymbol TypeParameter;
31public TypeParameterDiagnosticInfo(TypeParameterSymbol typeParameter, UseSiteInfo<AssemblySymbol> useSiteInfo)
74ConsList<TypeParameterSymbol> inProgress,
129this TypeParameterSymbol typeParameter,
131ConsList<TypeParameterSymbol> inProgress,
170var constraintTypeParameter = (TypeParameterSymbol)constraintType.Type;
171ConsList<TypeParameterSymbol> constraintsInProgress;
188constraintsInProgress = ConsList<TypeParameterSymbol>.Empty;
244var underlyingTypeParameter = (TypeParameterSymbol)underlyingType;
347ImmutableArray<TypeParameterSymbol> typeParameters,
377ImmutableArray<TypeParameterSymbol> typeParameters,
415internal static ImmutableArray<TypeParameterConstraintClause> AdjustConstraintKindsBasedOnConstraintTypes(ImmutableArray<TypeParameterSymbol> typeParameters, ImmutableArray<TypeParameterConstraintClause> constraintClauses)
421SmallDictionary<TypeParameterSymbol, bool> isValueTypeMap = TypeParameterConstraintClause.BuildIsValueTypeMap(typeParameters, constraintClauses);
422SmallDictionary<TypeParameterSymbol, bool> isReferenceTypeFromConstraintTypesMap = TypeParameterConstraintClause.BuildIsReferenceTypeFromConstraintTypesMap(typeParameters, constraintClauses);
428var typeParameter = typeParameters[i];
465TypeParameterSymbol typeParameter,
892ImmutableArray<TypeParameterSymbol> typeParameters,
898HashSet<TypeParameterSymbol> ignoreTypeConstraintsDependentOnTypeParametersOpt = null)
929TypeParameterSymbol typeParameter,
1032TypeParameterSymbol typeParameter,
1037HashSet<TypeParameterSymbol> ignoreTypeConstraintsDependentOnTypeParametersOpt)
1093static bool errorIfNotSatisfiesConstructorConstraint(Symbol containingSymbol, TypeParameterSymbol typeParameter, TypeWithAnnotations typeArgument, ArrayBuilder<TypeParameterDiagnosticInfo> diagnosticsBuilder)
1118TypeParameterSymbol typeParameter,
1142TypeParameterSymbol typeParameter,
1217var typeParameter = type as TypeParameterSymbol;
1255var typeParameter = type as TypeParameterSymbol;
1273TypeParameterSymbol typeParameter,
1358var typeParameter = (TypeParameterSymbol)typeArgument.Type;
1412private static bool IsReferenceType(TypeParameterSymbol typeParameter, ImmutableArray<TypeWithAnnotations> constraintTypes)
1414return typeParameter.HasReferenceTypeConstraint || TypeParameterSymbol.CalculateIsReferenceTypeFromConstraintTypes(constraintTypes);
1417private static bool IsValueType(TypeParameterSymbol typeParameter, ImmutableArray<TypeWithAnnotations> constraintTypes)
1419return typeParameter.HasValueTypeConstraint || TypeParameterSymbol.CalculateIsValueTypeFromConstraintTypes(constraintTypes);
1422private static TypeParameterDiagnosticInfo GenerateConflictingConstraintsError(TypeParameterSymbol typeParameter, TypeSymbol deducedBase, bool classConflict)
1473var typeParameter = (TypeParameterSymbol)typeArgument;
Symbols\MemberSignatureComparer.cs (9)
641public static bool HaveSameConstraints(ImmutableArray<TypeParameterSymbol> typeParameters1, TypeMap? typeMap1, ImmutableArray<TypeParameterSymbol> typeParameters2, TypeMap? typeMap2)
657public static bool HaveSameConstraints(TypeParameterSymbol typeParameter1, TypeMap? typeMap1, TypeParameterSymbol typeParameter2, TypeMap? typeMap2)
674private static bool HaveSameTypeConstraints(TypeParameterSymbol typeParameter1, TypeMap? typeMap1, TypeParameterSymbol typeParameter2, TypeMap? typeMap2, IEqualityComparer<TypeSymbol> comparer)
701public static bool HaveSameNullabilityInConstraints(TypeParameterSymbol typeParameter1, TypeMap typeMap1, TypeParameterSymbol typeParameter2, TypeMap typeMap2)
721private static bool AreConstraintTypesSubset(HashSet<TypeSymbol> constraintTypes1, HashSet<TypeSymbol> constraintTypes2, TypeParameterSymbol typeParameter2)
Symbols\Source\TypeParameterConstraintClause.cs (19)
132internal static SmallDictionary<TypeParameterSymbol, bool> BuildIsValueTypeMap(
133ImmutableArray<TypeParameterSymbol> typeParameters,
138var isValueTypeMap = new SmallDictionary<TypeParameterSymbol, bool>(ReferenceEqualityComparer.Instance);
140foreach (TypeParameterSymbol typeParameter in typeParameters)
142isValueType(typeParameter, constraintClauses, isValueTypeMap, ConsList<TypeParameterSymbol>.Empty);
147static bool isValueType(TypeParameterSymbol thisTypeParameter, ImmutableArray<TypeParameterConstraintClause> constraintClauses, SmallDictionary<TypeParameterSymbol, bool> isValueTypeMap, ConsList<TypeParameterSymbol> inProgress)
176if (type is TypeParameterSymbol typeParameter && (object)typeParameter.ContainingSymbol == (object)container)
197internal static SmallDictionary<TypeParameterSymbol, bool> BuildIsReferenceTypeFromConstraintTypesMap(
198ImmutableArray<TypeParameterSymbol> typeParameters,
203var isReferenceTypeFromConstraintTypesMap = new SmallDictionary<TypeParameterSymbol, bool>(ReferenceEqualityComparer.Instance);
205foreach (TypeParameterSymbol typeParameter in typeParameters)
207isReferenceTypeFromConstraintTypes(typeParameter, constraintClauses, isReferenceTypeFromConstraintTypesMap, ConsList<TypeParameterSymbol>.Empty);
212static bool isReferenceTypeFromConstraintTypes(TypeParameterSymbol thisTypeParameter, ImmutableArray<TypeParameterConstraintClause> constraintClauses,
213SmallDictionary<TypeParameterSymbol, bool> isReferenceTypeFromConstraintTypesMap, ConsList<TypeParameterSymbol> inProgress)
236if (type is TypeParameterSymbol typeParameter)
252else if (TypeParameterSymbol.NonTypeParameterConstraintImpliesReferenceType(type))
Symbols\TypeMap.cs (29)
26internal static ImmutableArray<TypeWithAnnotations> TypeParametersAsTypeSymbolsWithAnnotations(ImmutableArray<TypeParameterSymbol> typeParameters)
31internal static ImmutableArray<TypeWithAnnotations> TypeParametersAsTypeSymbolsWithIgnoredAnnotations(ImmutableArray<TypeParameterSymbol> typeParameters)
42internal TypeMap(ImmutableArray<TypeParameterSymbol> from, ImmutableArray<TypeWithAnnotations> to, bool allowAlpha = false)
50internal TypeMap(ImmutableArray<TypeParameterSymbol> from, ImmutableArray<TypeParameterSymbol> to, bool allowAlpha = false)
56private TypeMap(SmallDictionary<TypeParameterSymbol, TypeWithAnnotations> mapping)
57: base(new SmallDictionary<TypeParameterSymbol, TypeWithAnnotations>(mapping, ReferenceEqualityComparer.Instance))
62private static SmallDictionary<TypeParameterSymbol, TypeWithAnnotations> ForType(NamedTypeSymbol containingType)
66new SmallDictionary<TypeParameterSymbol, TypeWithAnnotations>(substituted.TypeSubstitution.Mapping, ReferenceEqualityComparer.Instance) :
67new SmallDictionary<TypeParameterSymbol, TypeWithAnnotations>(ReferenceEqualityComparer.Instance);
70internal TypeMap(NamedTypeSymbol containingType, ImmutableArray<TypeParameterSymbol> typeParameters, ImmutableArray<TypeWithAnnotations> typeArguments)
75TypeParameterSymbol tp = typeParameters[i];
84private static readonly SmallDictionary<TypeParameterSymbol, TypeWithAnnotations> s_emptyDictionary =
85new SmallDictionary<TypeParameterSymbol, TypeWithAnnotations>(ReferenceEqualityComparer.Instance);
103private TypeMap WithAlphaRename(ImmutableArray<TypeParameterSymbol> oldTypeParameters, Symbol newOwner, out ImmutableArray<TypeParameterSymbol> newTypeParameters)
107newTypeParameters = ImmutableArray<TypeParameterSymbol>.Empty;
118ArrayBuilder<TypeParameterSymbol> newTypeParametersBuilder = ArrayBuilder<TypeParameterSymbol>.GetInstance();
125foreach (var tp in oldTypeParameters)
139internal TypeMap WithAlphaRename(NamedTypeSymbol oldOwner, NamedTypeSymbol newOwner, out ImmutableArray<TypeParameterSymbol> newTypeParameters)
145internal TypeMap WithAlphaRename(MethodSymbol oldOwner, Symbol newOwner, out ImmutableArray<TypeParameterSymbol> newTypeParameters)
154out ImmutableArray<TypeParameterSymbol> newTypeParameters,
155out ImmutableArray<TypeParameterSymbol> oldTypeParameters,
173var parameters = ArrayBuilder<TypeParameterSymbol>.GetInstance();
200private static SmallDictionary<TypeParameterSymbol, TypeWithAnnotations> ConstructMapping(ImmutableArray<TypeParameterSymbol> from, ImmutableArray<TypeWithAnnotations> to)
202var mapping = new SmallDictionary<TypeParameterSymbol, TypeWithAnnotations>(ReferenceEqualityComparer.Instance);
208TypeParameterSymbol tp = from[i];
Symbols\TypeSymbolExtensions.cs (22)
75var typeParameter = (TypeParameterSymbol)type;
92return type is TypeParameterSymbol { IsValueType: false, IsNotNullable: false };
119var constraintTypes = ((TypeParameterSymbol)type).ConstraintTypesNoUseSiteDiagnostics;
350public static bool IsMethodTypeParameter(this TypeParameterSymbol p)
426var typeParameter = (TypeParameterSymbol)type;
546return type is { IsRefLikeType: true } or TypeParameterSymbol { AllowsRefLikeType: true };
1197public static bool ContainsTypeParameter(this TypeSymbol type, TypeParameterSymbol? parameter = null)
1203private static readonly Func<TypeSymbol, TypeParameterSymbol?, bool, bool> s_containsTypeParameterPredicate =
1217public static bool ContainsTypeParameters(this TypeSymbol type, HashSet<TypeParameterSymbol> parameters)
1223private static readonly Func<TypeSymbol, HashSet<TypeParameterSymbol>, bool, bool> s_containsTypeParametersPredicate =
1224(type, parameters, unused) => type.TypeKind == TypeKind.TypeParameter && parameters.Contains((TypeParameterSymbol)type);
1684internal static ImmutableArray<TypeParameterSymbol> GetAllTypeParameters(this NamedTypeSymbol type)
1692var builder = ArrayBuilder<TypeParameterSymbol>.GetInstance();
1701internal static void GetAllTypeParameters(this NamedTypeSymbol type, ArrayBuilder<TypeParameterSymbol> result)
1716internal static TypeParameterSymbol? FindEnclosingTypeParameter(this NamedTypeSymbol type, string name)
1718var allTypeParameters = ArrayBuilder<TypeParameterSymbol>.GetInstance();
1721TypeParameterSymbol? result = null;
1723foreach (TypeParameterSymbol tpEnclosing in allTypeParameters)
1740internal static TypeParameterSymbol? FindEnclosingTypeParameter(this Symbol methodOrType, string name)
1756foreach (var typeParameter in methodOrType.GetMemberTypeParameters())