Binder\Binder_Expressions.cs (6)
1509Debug.Assert(symbol is null or LocalSymbol or LocalFunctionSymbol or RangeVariableSymbol or TypeParameterSymbol);
5217return BindTypeParameterCreationExpression(node, (TypeParameterSymbol)type, diagnostics);
7077private BoundExpression BindTypeParameterCreationExpression(ObjectCreationExpressionSyntax node, TypeParameterSymbol typeParameter, BindingDiagnosticBag diagnostics)
7087private static bool TypeParameterHasParameterlessConstructor(SyntaxNode node, TypeParameterSymbol typeParameter, BindingDiagnosticBag diagnostics)
7099SyntaxNode node, TypeParameterSymbol typeParameter, AnalyzedArguments analyzedArguments, InitializerExpressionSyntax? initializerOpt,
9096if (receiverOpt is { Type: TypeParameterSymbol { AllowsRefLikeType: true } } &&
Binder\Binder_Lookup.cs (4)
256this.LookupMembersInTypeParameter(result, (TypeParameterSymbol)type, name, arity, basesBeingResolved, options, originalBinder, diagnose, ref useSiteInfo);
1254private void LookupMembersInTypeParameter(LookupResult current, TypeParameterSymbol typeParameter, string name, int arity, ConsList<TypeSymbol> basesBeingResolved, LookupOptions options, Binder originalBinder, bool diagnose, ref CompoundUseSiteInfo<AssemblySymbol> useSiteInfo)
1958this.AddMemberLookupSymbolsInfoInTypeParameter(result, (TypeParameterSymbol)type, options, originalBinder);
2123private void AddMemberLookupSymbolsInfoInTypeParameter(LookupSymbolsInfo result, TypeParameterSymbol type, LookupOptions options, Binder originalBinder)
Binder\Semantics\Conversions\ConversionsBase.cs (25)
1897private static bool HasIdentityConversionToAny(NamedTypeSymbol type, ArrayBuilder<(NamedTypeSymbol ParticipatingType, TypeParameterSymbol ConstrainedToTypeOpt)> targetTypes)
2670return HasImplicitReferenceTypeParameterConversion((TypeParameterSymbol)source, destination, ref useSiteInfo);
2849public bool HasImplicitTypeParameterConversion(TypeParameterSymbol source, TypeSymbol destination, ref CompoundUseSiteInfo<AssemblySymbol> useSiteInfo)
2861if (destination is TypeParameterSymbol { AllowsRefLikeType: false } &&
2863source.DependsOn((TypeParameterSymbol)destination))
2871private bool HasImplicitReferenceTypeParameterConversion(TypeParameterSymbol source, TypeSymbol destination, ref CompoundUseSiteInfo<AssemblySymbol> useSiteInfo)
2904if (destination is TypeParameterSymbol { AllowsRefLikeType: false } &&
2905source.DependsOn((TypeParameterSymbol)destination))
2914private bool HasImplicitEffectiveBaseConversion(TypeParameterSymbol source, TypeSymbol destination, ref CompoundUseSiteInfo<AssemblySymbol> useSiteInfo)
2938private bool HasImplicitEffectiveInterfaceSetConversion(TypeParameterSymbol source, TypeSymbol destination, ref CompoundUseSiteInfo<AssemblySymbol> useSiteInfo)
2943private bool HasVarianceCompatibleInterfaceInEffectiveInterfaceSet(TypeParameterSymbol source, TypeSymbol destination, ref CompoundUseSiteInfo<AssemblySymbol> useSiteInfo)
3021if (typeToCheck is TypeParameterSymbol typeParameter)
3186TypeParameterSymbol typeParameterSymbol = (TypeParameterSymbol)typeParameters[paramIndex].Type;
3248private bool HasImplicitBoxingTypeParameterConversion(TypeParameterSymbol source, TypeSymbol destination, ref CompoundUseSiteInfo<AssemblySymbol> useSiteInfo)
3281if (destination is TypeParameterSymbol { AllowsRefLikeType: false } d &&
3309HasImplicitBoxingTypeParameterConversion((TypeParameterSymbol)source, destination, ref useSiteInfo))
3533TypeParameterSymbol s = source as TypeParameterSymbol;
3534TypeParameterSymbol t = destination as TypeParameterSymbol;
3585TypeParameterSymbol s = source as TypeParameterSymbol;
3586TypeParameterSymbol 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,
961var 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,
901ImmutableArray<TypeParameterSymbol> typeParameters,
907HashSet<TypeParameterSymbol> ignoreTypeConstraintsDependentOnTypeParametersOpt = null)
952TypeParameterSymbol typeParameter,
1059TypeParameterSymbol typeParameter,
1064HashSet<TypeParameterSymbol> ignoreTypeConstraintsDependentOnTypeParametersOpt)
1120static bool errorIfNotSatisfiesConstructorConstraint(Symbol containingSymbol, TypeParameterSymbol typeParameter, TypeWithAnnotations typeArgument, ArrayBuilder<TypeParameterDiagnosticInfo> diagnosticsBuilder)
1145TypeParameterSymbol typeParameter,
1169TypeParameterSymbol typeParameter,
1246var typeParameter = type as TypeParameterSymbol;
1284var typeParameter = type as TypeParameterSymbol;
1302TypeParameterSymbol typeParameter,
1387var typeParameter = (TypeParameterSymbol)typeArgument.Type;
1441private static bool IsReferenceType(TypeParameterSymbol typeParameter, ImmutableArray<TypeWithAnnotations> constraintTypes)
1443return typeParameter.HasReferenceTypeConstraint || TypeParameterSymbol.CalculateIsReferenceTypeFromConstraintTypes(constraintTypes);
1446private static bool IsValueType(TypeParameterSymbol typeParameter, ImmutableArray<TypeWithAnnotations> constraintTypes)
1448return typeParameter.HasValueTypeConstraint || TypeParameterSymbol.CalculateIsValueTypeFromConstraintTypes(constraintTypes);
1451private static TypeParameterDiagnosticInfo GenerateConflictingConstraintsError(TypeParameterSymbol typeParameter, TypeSymbol deducedBase, bool classConflict)
1502var 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)
131internal static SmallDictionary<TypeParameterSymbol, bool> BuildIsValueTypeMap(
132ImmutableArray<TypeParameterSymbol> typeParameters,
137var isValueTypeMap = new SmallDictionary<TypeParameterSymbol, bool>(ReferenceEqualityComparer.Instance);
139foreach (TypeParameterSymbol typeParameter in typeParameters)
141isValueType(typeParameter, constraintClauses, isValueTypeMap, ConsList<TypeParameterSymbol>.Empty);
146static bool isValueType(TypeParameterSymbol thisTypeParameter, ImmutableArray<TypeParameterConstraintClause> constraintClauses, SmallDictionary<TypeParameterSymbol, bool> isValueTypeMap, ConsList<TypeParameterSymbol> inProgress)
175if (type is TypeParameterSymbol typeParameter && (object)typeParameter.ContainingSymbol == (object)container)
196internal static SmallDictionary<TypeParameterSymbol, bool> BuildIsReferenceTypeFromConstraintTypesMap(
197ImmutableArray<TypeParameterSymbol> typeParameters,
202var isReferenceTypeFromConstraintTypesMap = new SmallDictionary<TypeParameterSymbol, bool>(ReferenceEqualityComparer.Instance);
204foreach (TypeParameterSymbol typeParameter in typeParameters)
206isReferenceTypeFromConstraintTypes(typeParameter, constraintClauses, isReferenceTypeFromConstraintTypesMap, ConsList<TypeParameterSymbol>.Empty);
211static bool isReferenceTypeFromConstraintTypes(TypeParameterSymbol thisTypeParameter, ImmutableArray<TypeParameterConstraintClause> constraintClauses,
212SmallDictionary<TypeParameterSymbol, bool> isReferenceTypeFromConstraintTypesMap, ConsList<TypeParameterSymbol> inProgress)
235if (type is TypeParameterSymbol typeParameter)
251else if (TypeParameterSymbol.NonTypeParameterConstraintImpliesReferenceType(type))
Symbols\TypeMap.cs (28)
25internal static ImmutableArray<TypeWithAnnotations> TypeParametersAsTypeSymbolsWithAnnotations(ImmutableArray<TypeParameterSymbol> typeParameters)
30internal static ImmutableArray<TypeWithAnnotations> TypeParametersAsTypeSymbolsWithIgnoredAnnotations(ImmutableArray<TypeParameterSymbol> typeParameters)
41internal TypeMap(ImmutableArray<TypeParameterSymbol> from, ImmutableArray<TypeWithAnnotations> to, bool allowAlpha = false)
49internal TypeMap(ImmutableArray<TypeParameterSymbol> from, ImmutableArray<TypeParameterSymbol> to, bool allowAlpha = false)
55private TypeMap(SmallDictionary<TypeParameterSymbol, TypeWithAnnotations> mapping)
56: base(new SmallDictionary<TypeParameterSymbol, TypeWithAnnotations>(mapping, ReferenceEqualityComparer.Instance))
61private static SmallDictionary<TypeParameterSymbol, TypeWithAnnotations> ForType(NamedTypeSymbol containingType)
65new SmallDictionary<TypeParameterSymbol, TypeWithAnnotations>(substituted.TypeSubstitution.Mapping, ReferenceEqualityComparer.Instance) :
66new SmallDictionary<TypeParameterSymbol, TypeWithAnnotations>(ReferenceEqualityComparer.Instance);
69internal TypeMap(NamedTypeSymbol containingType, ImmutableArray<TypeParameterSymbol> typeParameters, ImmutableArray<TypeWithAnnotations> typeArguments)
74TypeParameterSymbol tp = typeParameters[i];
83private static readonly SmallDictionary<TypeParameterSymbol, TypeWithAnnotations> s_emptyDictionary =
84new SmallDictionary<TypeParameterSymbol, TypeWithAnnotations>(ReferenceEqualityComparer.Instance);
102internal TypeMap WithAlphaRename(ImmutableArray<TypeParameterSymbol> oldTypeParameters, Symbol newOwner, out ImmutableArray<TypeParameterSymbol> newTypeParameters)
106newTypeParameters = ImmutableArray<TypeParameterSymbol>.Empty;
117ArrayBuilder<TypeParameterSymbol> newTypeParametersBuilder = ArrayBuilder<TypeParameterSymbol>.GetInstance();
124foreach (var tp in oldTypeParameters)
138internal TypeMap WithAlphaRename(NamedTypeSymbol oldOwner, NamedTypeSymbol newOwner, out ImmutableArray<TypeParameterSymbol> newTypeParameters)
144internal TypeMap WithAlphaRename(MethodSymbol oldOwner, Symbol newOwner, out ImmutableArray<TypeParameterSymbol> newTypeParameters)
150internal static ImmutableArray<TypeParameterSymbol> ConcatMethodTypeParameters(MethodSymbol oldOwner, MethodSymbol stopAt)
167var parameters = ArrayBuilder<TypeParameterSymbol>.GetInstance();
193private static SmallDictionary<TypeParameterSymbol, TypeWithAnnotations> ConstructMapping(ImmutableArray<TypeParameterSymbol> from, ImmutableArray<TypeWithAnnotations> to)
195var mapping = new SmallDictionary<TypeParameterSymbol, TypeWithAnnotations>(ReferenceEqualityComparer.Instance);
201TypeParameterSymbol tp = from[i];
Symbols\TypeSymbolExtensions.cs (20)
76var typeParameter = (TypeParameterSymbol)type;
93return type is TypeParameterSymbol { IsValueType: false, IsNotNullable: false };
120var constraintTypes = ((TypeParameterSymbol)type).ConstraintTypesNoUseSiteDiagnostics;
351public static bool IsMethodTypeParameter(this TypeParameterSymbol p)
427var typeParameter = (TypeParameterSymbol)type;
547return type is { IsRefLikeType: true } or TypeParameterSymbol { AllowsRefLikeType: true };
1199public static bool ContainsTypeParameter(this TypeSymbol type, TypeParameterSymbol? parameter = null)
1205private static readonly Func<TypeSymbol, TypeParameterSymbol?, bool, bool> s_containsTypeParameterPredicate =
1219public static bool ContainsTypeParameters(this TypeSymbol type, HashSet<TypeParameterSymbol> parameters)
1225private static readonly Func<TypeSymbol, HashSet<TypeParameterSymbol>, bool, bool> s_containsTypeParametersPredicate =
1226(type, parameters, unused) => type.TypeKind == TypeKind.TypeParameter && parameters.Contains((TypeParameterSymbol)type);
1686internal static ImmutableArray<TypeParameterSymbol> GetAllTypeParameters(this NamedTypeSymbol type)
1694var builder = ArrayBuilder<TypeParameterSymbol>.GetInstance();
1703internal static void GetAllTypeParameters(this NamedTypeSymbol type, ArrayBuilder<TypeParameterSymbol> result)
1718internal static TypeParameterSymbol? FindEnclosingTypeParameter(this NamedTypeSymbol type, string name)
1722foreach (TypeParameterSymbol tpEnclosing in type.TypeParameters)
1741internal static TypeParameterSymbol? FindEnclosingTypeParameter(this Symbol methodOrType, string name)
1757foreach (var typeParameter in methodOrType.GetMemberTypeParameters())