Binder\Binder_Constraints.cs (9)
455diagnostics.Add(ErrorCode.ERR_BadVisBound, location, containingSymbol, constraintType.Type);
458if (constraintType.Type.HasFileLocalTypes())
471diagnostics.Add(ErrorCode.ERR_FileTypeDisallowedInSignature, location, constraintType.Type, containingSymbol);
499Error(diagnostics, ErrorCode.ERR_DuplicateBound, syntax, type.Type.SetUnknownNullabilityForReferenceTypes(), typeParameter.Name);
513Error(diagnostics, ErrorCode.ERR_ClassBoundNotFirst, syntax, type.Type);
528Error(diagnostics, ErrorCode.ERR_RefValBoundWithClass, syntax, type.Type);
537Error(diagnostics, ErrorCode.ERR_RefValBoundWithClass, syntax, type.Type);
543Error(diagnostics, ErrorCode.ERR_UnmanagedBoundWithClass, syntax, type.Type);
561TypeSymbol type = typeWithAnnotations.Type;
Binder\Binder_Conversions.cs (14)
384new BoundValuePlaceholder(source.Syntax, sourceTypes[i].Type),
389destTypes[i].Type,
613var sourceElementType = ((NamedTypeSymbol)source).TypeArgumentsWithAnnotationsNoUseSiteDiagnostics[0].Type;
614var destinationElementType = ((NamedTypeSymbol)destination).TypeArgumentsWithAnnotationsNoUseSiteDiagnostics[0].Type;
644typeArgument.Type.IsReferenceType &&
646((NamedTypeSymbol)parameter.Type).TypeArgumentsWithAnnotationsNoUseSiteDiagnostics[0].Type.Equals(typeArgument.Type, TypeCompareKind.ConsiderEverything) &&
648((NamedTypeSymbol)method.ReturnType).TypeArgumentsWithAnnotationsNoUseSiteDiagnostics[0].Type.Equals(((NamedTypeSymbol)arg.destination).TypeParameters[0], TypeCompareKind.ConsiderEverything));
1048collectionBuilderMethod = GetCollectionBuilderMethod(namedType, elementTypeOriginalDefinition.Type, builderType, methodName, ref useSiteInfo, out collectionBuilderReturnTypeConversion);
1064elementType = parameterType.TypeArgumentsWithAnnotationsNoUseSiteDiagnostics[0].Type;
1764Debug.Assert(elementTypeWithAnnotations.Type is null); // GetCollectionExpressionTypeKind() does not set elementType for these cases.
1785var elementType = elementTypeWithAnnotations.Type;
1906var spanTypeArg = ((NamedTypeSymbol)methodWithTargetTypeParameters.Parameters[0].Type).TypeArgumentsWithAnnotationsNoUseSiteDiagnostics[0].Type;
2501convertedArguments.Add(CreateConversion(argument.Syntax, argument, elementConversion, isCast: isCast, elementConversionGroup, destType.Type, diagnostics));
Binder\Binder_Deconstruct.cs (7)
856var type = declTypeWithAnnotations.Type;
896CheckRestrictedTypeInAsyncMethod(this.ContainingMemberOrLambda, declTypeWithAnnotations.Type, diagnostics, typeSyntax);
900localSymbol.Scope == ScopedKind.ScopedValue && !declTypeWithAnnotations.Type.IsErrorOrRefLikeOrAllowsRefLikeType())
913return new BoundLocal(syntax, localSymbol, BoundLocalDeclarationKind.WithExplicitType, constantValueOpt: null, isNullableUnknown: false, type: declTypeWithAnnotations.Type, hasErrors: hasErrors);
951Debug.Assert(TypeSymbol.Equals(declTypeWithAnnotations.Type, fieldType.Type, TypeCompareKind.ConsiderEverything2));
958type: fieldType.Type);
Binder\Binder_Expressions.cs (35)
457field.GetFieldType(initializerBinder.FieldsBeingBound).Type, diagnostics);
1241return new BoundRefValueOperator(node, typeWithAnnotations.NullableAnnotation, argument, typeWithAnnotations.Type, hasErrors);
1381TypeSymbol type = typeWithAnnotations.Type;
1409var type = typeWithAnnotations.Type;
1434TypeSymbol type = typeWithAnnotations.Type;
1574TypeSymbol type = typeWithAnnotations.Type;
2586TypeSymbol targetType = targetTypeWithAnnotations.Type;
2748TypeSymbol targetType = targetTypeWithAnnotations.Type;
2906var targetElementType = targetElementTypesWithAnnotations[i].Type;
2933TypeWithAnnotations underlyingTargetTypeWithAnnotations = targetTypeWithAnnotations.Type.GetNullableUnderlyingTypeWithAnnotations();
2934var underlyingConversion = Conversions.ClassifyBuiltInConversion(operand.Type, underlyingTargetTypeWithAnnotations.Type, isChecked: CheckOverflowAtRuntime, ref discardedUseSiteInfo);
3178var type = declType.Type;
3234CheckRestrictedTypeInAsyncMethod(this.ContainingMemberOrLambda, declType.Type, diagnostics, typeSyntax);
3236if (localSymbol.Scope == ScopedKind.ScopedValue && !declType.Type.IsErrorOrRefLikeOrAllowsRefLikeType())
3241return new BoundLocal(declarationExpression, localSymbol, BoundLocalDeclarationKind.WithExplicitType, constantValueOpt: null, isNullableUnknown: false, type: declType.Type);
3278TypeSymbol fieldType = expressionVariableField.GetFieldType(this.FieldsBeingBound).Type;
3500coercedArgument = bindInterpolatedStringHandlerInMemberCall(argument, parameterTypeWithAnnotations.Type, argumentsForInterpolationConversion, parameters, in result, arg, receiver, diagnostics);
3507coercedArgument = CreateConversion(argument.Syntax, argument, kind, isCast: false, conversionGroupOpt: null, parameterTypeWithAnnotations.Type, diagnostics);
3528coercedArgument = CreateConversion(argument.Syntax, argument, kind, isCast: false, conversionGroupOpt: null, parameterTypeWithAnnotations.Type, diagnostics);
3582Debug.Assert(methodResult.Result.ParamsElementTypeOpt.Type != (object)ErrorTypeSymbol.EmptyParamsCollectionElementTypeSentinel);
3649if (!methodResult.Member.IsIndexer() && !argument.HasAnyErrors && parameterTypeWithAnnotations.Type.ContainsPointerOrFunctionPointer())
4029var type = (ArrayTypeSymbol)BindArrayType(node.Type, diagnostics, permitDimensions: true, basesBeingResolved: null, disallowRestrictedTypes: true).Type;
4512var arrayType = (ArrayTypeSymbol)BindArrayType(arrayTypeSyntax, diagnostics, permitDimensions: true, basesBeingResolved: null, disallowRestrictedTypes: false).Type;
4516if (!elementType.Type.IsErrorType())
4518hasErrors = hasErrors || CheckManagedAddr(Compilation, elementType.Type, elementTypeSyntax.Location, diagnostics, errorForManaged: true);
4569? new BoundStackAllocArrayCreation(node, elementType.Type, count, initializerOpt: null, type, hasErrors: hasErrors)
4570: BindStackAllocWithInitializer(node, node.StackAllocKeyword, node.Initializer, type, elementType.Type, count, diagnostics, hasErrors);
5194var type = typeWithAnnotations.Type;
7611if (typeArgument.Type.IsPointerOrFunctionPointer() || typeArgument.Type.IsRestrictedType())
7614Error(diagnostics, ErrorCode.ERR_BadTypeArgument, typeArgumentsSyntax[i], typeArgument.Type);
8327resultType = ((FieldSymbol)symbolOpt).GetFieldType(this.FieldsBeingBound).Type;
8993TypeSymbol fieldType = fieldSymbol.GetFieldType(this.FieldsBeingBound).Type;
11196Debug.Assert(returnType.Type is { }); // Expecting System.Void rather than null return type.
11199bool returnsVoid = returnType.Type.IsVoidType();
Binder\Binder_Patterns.cs (6)
861hasErrors |= CheckValidPatternType(typeSyntax, inputType, declType.Type, diagnostics: diagnostics);
896CheckRestrictedTypeInAsyncMethod(this.ContainingMemberOrLambda, declType.Type, diagnostics, typeSyntax ?? (SyntaxNode)designation);
900syntax: designation, localSymbol: localSymbol, localSymbol.IsVar ? BoundLocalDeclarationKind.WithInferredType : BoundLocalDeclarationKind.WithExplicitType, constantValueOpt: null, isNullableUnknown: false, type: declType.Type);
974TypeSymbol declType = declTypeWithAnnotations.Type;
1172TypeSymbol elementType = isError ? CreateErrorType() : elementTypesWithAnnotations[i].Type;
1445TypeSymbol elementType = isError ? CreateErrorType() : elementTypes[i].Type;
Binder\Binder_Statements.cs (16)
237TypeSymbol elementType = GetIteratorElementType().Type;
849Error(diagnostics, ErrorCode.ERR_VarDeclIsStaticClass, typeSyntax, declType.Type);
852if (isConst && !declType.Type.CanBeConst())
854Error(diagnostics, ErrorCode.ERR_BadConstType, typeSyntax, declType.Type);
1029Error(localDiagnostics, ErrorCode.ERR_ImplicitlyTypedVariableAssignedBadValue, declarator, declTypeOpt.Type);
1034if (!declTypeOpt.Type.IsErrorType())
1058initializerOpt = BindPossibleArrayInitializer(value, declTypeOpt.Type, valueKind, diagnostics);
1063declTypeOpt.Type,
1085if (!declTypeOpt.Type.IsPointerType())
1089Error(localDiagnostics, declTypeOpt.Type.IsFunctionPointer() ? ErrorCode.ERR_CannotUseFunctionPointerAsFixedLocal : ErrorCode.ERR_BadFixedInitType, declarator);
1093else if (!IsValidFixedVariableInitializer(declTypeOpt.Type, ref initializerOpt, localDiagnostics))
1099CheckRestrictedTypeInAsyncMethod(this.ContainingMemberOrLambda, declTypeOpt.Type, localDiagnostics, typeSyntax);
1101if (localSymbol.Scope == ScopedKind.ScopedValue && !declTypeOpt.Type.IsErrorOrRefLikeOrAllowsRefLikeType())
2075conversionError(diagnostics, ErrorCode.ERR_ExpressionTreeMustHaveDelegate, ((NamedTypeSymbol)targetType).TypeArgumentsWithAnnotationsNoUseSiteDiagnostics[0].Type);
2538var targetElementType = targetElementTypes[i].Type;
3265type = this.BindType(declaration.Type, diagnostics).Type;
Binder\Binder_Symbols.cs (7)
538else if (LazyMissingNonNullTypesContextDiagnosticInfo.IsNullableReference(typeArgument.Type))
562ReportUseSite(constructedType.Type.OriginalDefinition, diagnostics, syntax);
563var type = (NamedTypeSymbol)constructedType.Type;
606CheckManagedAddr(Compilation, elementType.Type, node.Location, diagnostics);
621if (type.Type.IsTypeParameterDisallowingAnnotationInCSharp8())
646Error(diagnostics, ErrorCode.ERR_ArrayOfStaticClass, node.ElementType, type.Type);
657Error(diagnostics, ErrorCode.ERR_ArrayElementCantBeRefAny, node.ElementType, type.Type);
Binder\ForEachLoopBinder.cs (13)
200var valuePlaceholder = new BoundDeconstructValuePlaceholder(_syntax.Expression, variableSymbol: null, isDiscardExpression: false, inferredType.Type ?? CreateErrorType("var"));
326CheckRestrictedTypeInAsyncMethod(this.ContainingMemberOrLambda, declType.Type, diagnostics, typeSyntax);
328if (local.Scope == ScopedKind.ScopedValue && !declType.Type.IsErrorOrRefLikeOrAllowsRefLikeType())
385var valuePlaceholder = new BoundDeconstructValuePlaceholder(_syntax.Expression, variableSymbol: null, isDiscardExpression: false, iterationVariableType.Type).MakeCompilerGenerated();
441hasErrors = hasErrors || boundIterationVariableType.HasErrors || iterationVariableType.Type.IsErrorType();
479Conversion elementConversionClassification = this.Conversions.ClassifyConversionFromType(inferredType.Type, iterationVariableType.Type, isChecked: CheckOverflowAtRuntime, ref useSiteInfo, forCast: true);
483Error(diagnostics, ErrorCode.ERR_RefAssignmentMustHaveIdentityConversion, collectionExpr.Syntax, iterationVariableType.Type);
487var elementPlaceholder = new BoundValuePlaceholder(_syntax, inferredType.Type).MakeCompilerGenerated();
495diagnostics.Add(ErrorCode.ERR_AmbigUDConv, foreachKeyword.GetLocation(), originalUserDefinedConversions[0], originalUserDefinedConversions[1], inferredType.Type, iterationVariableType);
499SymbolDistinguisher distinguisher = new SymbolDistinguisher(this.Compilation, inferredType.Type, iterationVariableType.Type);
511BoundExpression elementConversion = CreateConversion(_syntax, elementPlaceholder, elementConversionClassification, isCast: false, conversionGroupOpt: null, iterationVariableType.Type, createConversionDiagnostics);
Binder\Semantics\AccessCheck.cs (3)
164return IsSymbolAccessibleCore(((DiscardSymbol)symbol).TypeWithAnnotations.Type, within, null, out failedThroughTypeCheck, compilation, ref useSiteInfo, basesBeingResolved);
239if (typeArg.Type.Kind != SymbolKind.TypeParameter && !IsSymbolAccessibleCore(typeArg.Type, within, null, out unused, compilation, ref useSiteInfo, basesBeingResolved))
Binder\Semantics\Conversions\ConversionsBase.cs (36)
1488!invokeMethod.ReturnType.Equals(returnType.Type, TypeCompareKind.AllIgnoreOptions))
1603var delegateType = type.TypeArgumentsWithAnnotationsNoUseSiteDiagnostics[0].Type;
1880var type = typeWithAnnotations.Type;
1894ClassifyImplicitConversionFromType(source.Type, destination.Type, ref discardedUseSiteInfo).Kind != ConversionKind.NoConversion;
1960conversions.ClassifyImplicitExtensionMethodThisArgConversion(s, s.Type, d.Type, ref u, isMethodGroupConversion: false),
1982return conversions.ClassifyImplicitExtensionMethodThisArgConversion(sourceExpressionOpt: null, s.Type, d.Type, ref u, isMethodGroupConversion: false);
2295=> conversions.ClassifyImplicitConversionFromExpression(s, d.Type, ref u),
2313conversions.ClassifyConversionFromExpression(s, d.Type, isChecked: isChecked, ref u, forCast: forCast),
2371return conversions.ClassifyImplicitConversionFromType(s.Type, d.Type, ref u);
2390return conversions.ClassifyConversionFromType(s.Type, d.Type, isChecked: isChecked, ref u, forCast);
2598return HasIdentityOrImplicitReferenceConversion(elementType.Type, argument0.Type, ref useSiteInfo);
2612HasIdentityConversionInternal(source.Type, destination.Type, includeNullability: true))
2617return HasImplicitReferenceConversion(source.Type, destination.Type, ref useSiteInfo);
3419&& (HasIdentityOrImplicitReferenceConversion(sourceType.Type, destinationType.Type, ref useSiteInfo)
3420|| HasImplicitPointerToVoidConversion(sourceType.Type, destinationType.Type)
3421|| HasImplicitPointerConversion(sourceType.Type, destinationType.Type, ref useSiteInfo));
3425&& HasIdentityConversion(sourceType.Type, destinationType.Type);
3686var sourceArg = sourceTypeArguments[i].Type;
3687var destinationArg = destinationTypeArguments[i].Type;
3769if (HasExplicitReferenceConversion(sourceArray.ElementType, ((NamedTypeSymbol)destination).TypeArgumentWithDefinitionUseSiteDiagnostics(0, ref useSiteInfo).Type, ref useSiteInfo))
3789var sourceElement = ((NamedTypeSymbol)source).TypeArgumentWithDefinitionUseSiteDiagnostics(0, ref useSiteInfo).Type;
4006return HasIdentityConversionInternal(source.Type, destination.Type) &&
4028return HasIdentityOrReferenceConversion(elementType.Type, spanElementType.Type, ref useSiteInfo) &&
Binder\Semantics\OverloadResolution\MethodTypeInference.cs (72)
468if (!fixedResultType.Type.IsErrorType())
477var errorTypeName = fixedResultType.Type.Name;
506TypeParameterSymbol typeParameter = (TypeParameterSymbol)type.Type;
539var methodTypeParameter = (TypeParameterSymbol)methodTypeParameterWithAnnotations.Type;
573return typeMap.SubstituteType(delegateOrFunctionPointerType).Type;
613ExactOrBoundsKind kind = GetRefKind(arg).IsManagedReference() || target.Type.IsPointerType() ? ExactOrBoundsKind.Exact : ExactOrBoundsKind.LowerBound;
635if (argument.Kind == BoundKind.UnboundLambda && target.Type.GetDelegateType() is { })
649if (IsReallyAType(argumentType.Type))
655var ordinal = GetOrdinal((TypeParameterSymbol)target.Type); // Tracked by https://github.com/dotnet/roslyn/issues/76130 : test nullability scenario where the override of ordinals matters
668TypeSymbol targetType = target.Type;
703Debug.Assert(target.Type is { });
704if (target.Type is null)
725if (target.Type.Kind != SymbolKind.NamedType)
731var destination = (NamedTypeSymbol)target.Type;
887if (HasUnfixedParamInOutputType(argument, formalType.Type) && !HasUnfixedParamInInputType(argument, formalType.Type))
905if (!binder.TryGetCollectionIterationType((ExpressionSyntax)argument.Syntax, formalType.Type, out TypeWithAnnotations targetElementType))
921if (formalType.Type.Kind != SymbolKind.NamedType)
927var destination = (NamedTypeSymbol)formalType.Type;
1144var formalParameterType = _formalParameterTypes[iArg].Type;
1386if (MethodGroupReturnTypeInference(binder, expression, target.Type, ref useSiteInfo))
1408var delegateType = target.Type.GetDelegateType();
1430Debug.Assert(inferredReturnType.Type is not FunctionTypeSymbol);
1569var delegateType = target.Type.GetDelegateType();
1622var delegateInvokeMethod = target.Type.GetDelegateType()?.DelegateInvokeMethod();
1667if (ExactSpanInference(source.Type, target.Type, ref useSiteInfo))
1712if (!source.Type.IsArray() || !target.Type.IsArray())
1717var arraySource = (ArrayTypeSymbol)source.Type;
1718var arrayTarget = (ArrayTypeSymbol)target.Type;
1807ExactOrBoundsInference(kind, ((NamedTypeSymbol)source.Type).TypeArgumentsWithAnnotationsNoUseSiteDiagnostics[0], ((NamedTypeSymbol)target.Type).TypeArgumentsWithAnnotationsNoUseSiteDiagnostics[0], ref useSiteInfo);
1841if (!source.Type.TryGetElementTypesWithAnnotationsIfTupleType(out sourceTypes) ||
1842!target.Type.TryGetElementTypesWithAnnotationsIfTupleType(out targetTypes) ||
1865var namedSource = source.Type as NamedTypeSymbol;
1871var namedTarget = target.Type as NamedTypeSymbol;
1890ExactInference(((PointerTypeSymbol)source.Type).PointedAtTypeWithAnnotations, ((PointerTypeSymbol)target.Type).PointedAtTypeWithAnnotations, ref useSiteInfo);
1893else if (source.Type is FunctionPointerTypeSymbol { Signature: { ParameterCount: int sourceParameterCount } sourceSignature } &&
1894target.Type is FunctionPointerTypeSymbol { Signature: { ParameterCount: int targetParameterCount } targetSignature } &&
2004if (LowerBoundArrayInference(source.Type, target.Type, ref useSiteInfo))
2011if (LowerBoundSpanInference(source.Type, target.Type, ref useSiteInfo))
2048if (LowerBoundConstructedInference(source.Type, target.Type, ref useSiteInfo))
2053if (LowerBoundFunctionPointerTypeInference(source.Type, target.Type, ref useSiteInfo))
2137if (elementSource.Type.IsReferenceType)
2172if (!sourceElementType.Type.IsReferenceType || target.IsSpan())
2512Debug.Assert(source.Type.IsReferenceType || source.Type.IsFunctionPointer());
2529if (UpperBoundFunctionPointerTypeInference(source.Type, target.Type, ref useSiteInfo))
2564if (!target.Type.IsArray())
2568var arrayTarget = (ArrayTypeSymbol)target.Type;
2570var elementSource = GetMatchingElementType(arrayTarget, source.Type, ref useSiteInfo);
2576if (elementSource.Type.IsReferenceType)
2597var source = sourceWithAnnotations.Type;
2598var target = targetWithAnnotations.Type;
2849Debug.Assert(best.Type.Type.Equals(withoutNullability.Type, TypeCompareKind.IgnoreDynamicAndTupleNames | TypeCompareKind.IgnoreNullableModifiersForReferenceTypes));
3013functionType = type.Type as FunctionTypeSymbol;
3020return constraintTypes.Any(static t => isExpressionType(t.Type));
3039var source = sourceWithAnnotations.Type;
3040var destination = destinationWithAnnotations.Type;
3318if (!dest.Type.ContainsTypeParameter(pParam))
3462var newBound = TypeWithAnnotations.Create(oldBound.Type, newAnnotation);
3488if (newCandidate.Type.IsDynamic())
3519return obj.Type.GetHashCode();
3526if (x.Type.IsDynamic() ^ y.Type.IsDynamic()) { return false; }
Binder\Semantics\OverloadResolution\OverloadResolution.cs (20)
1264expandedResult.Result.ParamsElementTypeOpt.Type != (object)ErrorTypeSymbol.EmptyParamsCollectionElementTypeSentinel)
1347if (elementType.Type is null)
1368Debug.Assert(elementType.Type is { });
2602Debug.Assert(paramsElementTypeOpt.Type != (object)ErrorTypeSymbol.EmptyParamsCollectionElementTypeSentinel);
2603return paramsElementTypeOpt.Type;
3225t1, kind1, elementType1.Type, underlyingElementConversions1: [],
3226t2, kind2, elementType2.Type, underlyingElementConversions2: [],
3240elementType = typeArg.Type;
3283if (x.HasType && Conversions.HasIdentityConversion(x.Type, y))
3293y = ((NamedTypeSymbol)y).TypeArgumentsWithAnnotationsNoUseSiteDiagnostics[0].Type;
3386if (!ExpressionMatchExactly(sourceArguments[i], destTypes[i].Type, ref useSiteInfo))
3533return BetterConversionTargetCore(((NamedTypeSymbol)type1).TypeArgumentsWithAnnotationsNoUseSiteDiagnostics[0].Type,
3534((NamedTypeSymbol)type2).TypeArgumentsWithAnnotationsNoUseSiteDiagnostics[0].Type,
3644var type1Element = ((NamedTypeSymbol)type1).TypeArgumentsWithAnnotationsNoUseSiteDiagnostics[0].Type;
3645var type2Element = ((NamedTypeSymbol)type2).TypeArgumentsWithAnnotationsNoUseSiteDiagnostics[0].Type;
4064TryInferParamsCollectionIterationType(binder, type.Type, out paramsIterationType);
4337if (!parameterTypes[i].Type.CheckAllConstraints(Compilation, Conversions))
4579&& parameters.ParameterTypes[argumentPosition].Type is NamedTypeSymbol { IsInterpolatedStringHandlerType: true, IsValueType: true })
4592parameters.ParameterTypes[argumentPosition].Type,
4604(ignoreOpenTypes && parameters.ParameterTypes[argumentPosition].Type.ContainsTypeParameter(parameterContainer: (MethodSymbol)candidate))));
BoundTree\VariablePendingInference.cs (4)
65Binder.CheckRestrictedTypeInAsyncMethod(localSymbol.ContainingSymbol, type.Type, diagnosticsOpt, typeOrDesignationSyntax);
67if (localSymbol.Scope == ScopedKind.ScopedValue && !type.Type.IsErrorOrRefLikeOrAllowsRefLikeType())
76return new BoundLocal(this.Syntax, localSymbol, BoundLocalDeclarationKind.WithInferredType, constantValueOpt: null, isNullableUnknown: false, type: type.Type, hasErrors: this.HasErrors || inferenceFailed).WithWasConverted();
106type: type.Type,
FlowAnalysis\NullableWalker.cs (85)
130Debug.Assert(TypeSymbol.Equals(RValueType.Type, LValueType.Type, TypeCompareKind.ConsiderEverything));
765if (symbolType.Type.IsValueType || symbolType.Type.IsErrorType())
797var badState = symbolType.Type.IsPossiblyNullableReferenceTypeTypeParameter() && (annotations & FlowAnalysisAnnotations.NotNull) == 0
855SetState(ref this.State, memberSlot, type.Type.IsPossiblyNullableReferenceTypeTypeParameter() ? NullableFlowState.MaybeDefault : NullableFlowState.MaybeNull);
2363type.Type.IsValueType)
2380if (type.Type.IsTypeParameterDisallowingAnnotationInCSharp8() && !(type.Type is TypeParameterSymbol { IsNotNullable: true }))
2406!targetType.Type.Equals(valueType.Type, TypeCompareKind.AllIgnoreOptions))
2639InheritDefaultState(targetType.Type, targetSlot);
2645if (targetType.Type.IsReferenceType ||
2654else if (EmptyStructTypeCache.IsTrackableStructType(targetType.Type))
2656InheritNullableStateOfTrackableStruct(targetType.Type, targetSlot, valueSlot, isDefaultValue: !(valueOpt is null) && IsDefaultValue(valueOpt), skipSlot: targetSlot);
2662target.Type.Equals(assignedValue.Type, TypeCompareKind.AllIgnoreOptions);
2733if (fieldOrPropertyType.Type.IsReferenceType ||
2762else if (EmptyStructTypeCache.IsTrackableStructType(fieldOrPropertyType.Type))
2772InheritNullableStateOfTrackableStruct(fieldOrPropertyType.Type, targetMemberSlot, valueMemberSlot, isDefaultValue: isDefaultValue, skipSlot);
2855private static TypeSymbol GetTypeOrReturnType(Symbol symbol) => symbol.GetTypeOrReturnType().Type;
2887typeWithAnnotations = TypeWithAnnotations.Create(typeWithAnnotations.Type, nullableAnnotation);
2988if (EmptyStructTypeCache.IsTrackableStructType(parameterType.Type))
2991parameterType.Type,
3024return TypeWithState.Create(parameterType.Type, NullableFlowState.MaybeDefault);
3029return TypeWithState.Create(parameterType.Type, NullableFlowState.NotNull);
3053returnType.Type.SpecialType == SpecialType.System_Boolean)
3161type = ((NamedTypeSymbol)returnType.Type).TypeArgumentsWithAnnotationsNoUseSiteDiagnostics.Single();
3188if (!node.Type.Equals(type.Type, TypeCompareKind.ConsiderEverything | TypeCompareKind.IgnoreNullableModifiersForReferenceTypes | TypeCompareKind.IgnoreDynamicAndTupleNames))
3193Debug.Assert(node.Type.IsErrorType() || type.Type.IsErrorType());
3556VisitObjectCreationInitializer(resultSlot, resultType.Type, withExpr.InitializerExpression, delayCompletionForType: false);
3609InheritDefaultState(GetDeclaredLocalResult(local).Type, slot);
3667Debug.Assert(type.Type.IsErrorType());
3746return AnonymousTypeManager.GetAnonymousTypeFieldTypes(type).Any(static t => canIgnoreAnyType(t.Type));
3926var strippedTargetCollectionType = targetCollectionType.Type.StrippedType();
4083Debug.Assert(TypeSymbol.Equals(resultTypeWithAnnotations.Type, node.Type, TypeCompareKind.IgnoreNullableModifiersForReferenceTypes));
4085var type = resultTypeWithAnnotations.Type;
4162if (AreNullableAndUnderlyingTypes(type, parameterType.Type, out TypeWithAnnotations underlyingType))
4489Debug.Assert(TypeSymbol.Equals(containingType, receiverResult.LValueType.Type, TypeCompareKind.IgnoreNullableModifiersForReferenceTypes));
4547Debug.Assert(TypeSymbol.Equals(containingType, receiverResult.LValueType.Type, TypeCompareKind.IgnoreNullableModifiersForReferenceTypes));
4799inferredType = TypeWithState.Create(inferredType.Type, elementState).ToTypeWithAnnotations(compilation);
5339if (isLifted && targetTypeWithNullability.Type.IsNonNullableValueType())
5718Debug.Assert(targetType.Type.ContainsErrorType() ||
5720TypeSymbol.Equals(targetType.Type.GetNullableUnderlyingType(), node.Type, TypeCompareKind.AllIgnoreOptions));
5724leftSlot = GetNullableOfTValueSlot(targetType.Type, leftSlot, out _);
5730Debug.Assert(TypeSymbol.Equals(targetType.Type, rightResult.Type, TypeCompareKind.AllIgnoreOptions));
5734TypeWithState resultType = TypeWithState.Create(targetType.Type, rightResult.State);
5994TypeSymbol accessType = accessTypeWithAnnotations.Type;
6188var typeWithState = TypeWithState.Create(resultTypeWithAnnotations.Type, resultState);
6201return TypeWithState.Create(resultTypeWithAnnotations.Type, resultState);
6316new BoundExpressionWithNullability(expr.Syntax, expr, type.NullableAnnotation, type.Type);
7655conversion = GenerateConversion(_conversions, argumentNoConversion, argumentResultType, parameterType.Type, fromExplicitCast: false, extensionMethodThisArgument: false, isChecked: conversionOpt?.Checked ?? false);
7659ReportNullabilityMismatchInArgument(argumentNoConversion.Syntax, argumentResultType, parameter, parameterType.Type, forOutput: false);
7691if (IsNullabilityMismatch(lvalueResultType.Type, parameterType.Type))
7694ReportNullabilityMismatchInRefArgument(argumentNoConversion, argumentType: lvalueResultType.Type, parameter, parameterType.Type);
7798parameterWithState = TypeWithState.Create(parameterType.Type, adjustedState);
7855if (!_conversions.HasIdentityOrImplicitReferenceConversion(parameterType.Type, lValueType.Type, ref discardedUseSiteInfo))
7857ReportNullabilityMismatchInArgument(argument.Syntax, lValueType.Type, parameter, parameterType.Type, forOutput: true);
8092OverloadResolution.TryInferParamsCollectionIterationType(_binder, type.Type, out paramsIterationType);
8285return new BoundExpressionWithNullability(argument.Syntax, argument, argumentType.NullableAnnotation, argumentType.Type);
8569if (TypeAllowsConditionalState(targetType.Type) && TypeAllowsConditionalState(operand.Type))
8682if (typeArg.Type.Equals(underlyingTypeOpt, TypeCompareKind.AllIgnoreOptions))
9103operandType = completion(targetTypeWithNullability.Type.GetNullableUnderlyingTypeWithAnnotations());
9131TypeSymbol targetType = targetTypeWithNullability.Type;
9447if (targetType.Type?.IsTypeParameterDisallowingAnnotationInCSharp8() == true)
9456dependsOnTypeParameter(typeParameter1, (TypeParameterSymbol)targetType.Type, NullableAnnotation.NotAnnotated, out var annotation))
9463if (targetType.Type?.IsTypeParameterDisallowingAnnotationInCSharp8() == false)
9487targetType.Type is TypeParameterSymbol typeParameter2)
9537if (constraintType.Type is TypeParameterSymbol constraintTypeParameter &&
9641TypeSymbol targetType = targetTypeWithNullability.Type;
9811bool typeNeedsLifting = returnType.Type.IsNonNullableValueType();
9812TypeSymbol type = typeNeedsLifting ? MakeNullableOf(returnType) : returnType.Type;
9856var conversion = _conversions.ClassifyStandardConversion(operandType.Type, targetType.Type, ref discardedUseSiteInfo);
9861ReportNullabilityMismatchInArgument(diagnosticLocation, operandType.Type, parameterOpt, targetType.Type, forOutput: false);
9865ReportNullabilityMismatchInAssignment(diagnosticLocation, operandType.Type, targetType.Type);
9946Debug.Assert(TypeSymbol.Equals(resultTypeWithAnnotations.Type, node.Type, TypeCompareKind.IgnoreNullableModifiersForReferenceTypes));
9947var delegateType = (NamedTypeSymbol)resultTypeWithAnnotations.Type;
10126arguments.Add(new BoundExpressionWithNullability(syntax, new BoundParameter(syntax, parameter), parameterType.NullableAnnotation, parameterType.Type));
10299SetResult(node, TypeWithState.Create(leftLValueType.Type, rightState.State), leftLValueType);
10643var valueBeforeNullableWrapping = TypeWithState.Create(underlyingType.Type, NullableFlowState.NotNull);
10959if (argumentType.Type is { } argType && IsNullabilityMismatch(paramType.Type, argType))
10961ReportNullabilityMismatchInArgument(argument.Syntax, argType, parameter, paramType.Type, forOutput: false);
11483conversion = _conversions.ClassifyImplicitConversionFromType(sourceType.Type, destinationType.Type, ref discardedUseSiteInfo);
FlowAnalysis\NullableWalker_Patterns.cs (14)
452var output = new BoundDagTemp(e.Syntax, parameterType.Type, e, i);
455addToTempMap(output, outputSlot, parameterType.Type);
490var output = new BoundDagTemp(e.Syntax, type.Type, e);
528addToTempMap(output, outputSlot, type.Type);
536var output = new BoundDagTemp(e.Syntax, type.Type, e);
543addToTempMap(output, outputSlot, type.Type);
561var output = new BoundDagTemp(e.Syntax, type.Type, e);
565addToTempMap(output, outputSlot, type.Type);
573var output = new BoundDagTemp(e.Syntax, type.Type, e);
576addToTempMap(output, outputSlot, type.Type);
688inferredType = TypeWithAnnotations.Create(inferredType.Type, existingType.NullableAnnotation.Join(inferredType.NullableAnnotation));
840var output = new BoundDagTemp(e.Syntax, type.Type, e, index: index);
843addToTempMap(output, outputSlot, type.Type);
1020TypeWithState resultType = TypeWithState.Create(inferredTypeWithAnnotations.Type, inferredState);
Lowering\LocalRewriter\LocalRewriter_CollectionExpression.cs (7)
275ShouldUseRuntimeHelpersCreateSpan(node, elementType.Type))
278Debug.Assert(!IsAllocatingRefStructCollectionExpression(node, collectionTypeKind, elementType.Type, _compilation));
281return _factory.New(constructor, _factory.Array(elementType.Type, rewrittenElements));
287Debug.Assert(!IsAllocatingRefStructCollectionExpression(node, collectionTypeKind, elementType.Type, _compilation));
295Debug.Assert(IsAllocatingRefStructCollectionExpression(node, collectionTypeKind, elementType.Type, _compilation));
893asSpanMethod = collectionsMarshalAsSpanMethod.Construct(namedType.TypeArgumentsWithAnnotationsNoUseSiteDiagnostics[0].Type);
1129var elementType = ((NamedTypeSymbol)spanTemp.Type).TypeArgumentsWithAnnotationsNoUseSiteDiagnostics[0].Type;
Lowering\LocalRewriter\LocalRewriter_TupleBinaryOperator.cs (3)
69var elementType = resultTypes[i].Type;
121syntax, fieldAccess, elementConversions[i], boundConversion.Checked, boundConversion.ExplicitCastInCode, null, null, destElementTypes[i].Type, boundConversion.HasErrors);
476conversionGroupOpt: null, constantValueOpt: null, type: type.Type);
Symbols\ConstraintsHelper.cs (52)
161Debug.Assert(!constraintType.Type.ContainsDynamic());
170var constraintTypeParameter = (TypeParameterSymbol)constraintType.Type;
225if (constraintType.Type.IsInterfaceType())
227AddInterface(interfacesBuilder, (NamedTypeSymbol)constraintType.Type);
233constraintEffectiveBase = (NamedTypeSymbol)constraintType.Type;
234constraintDeducedBase = constraintType.Type;
241var underlyingType = constraintType.Type.GetNullableUnderlyingType();
259constraintDeducedBase = constraintType.Type;
265constraintDeducedBase = constraintType.Type;
271constraintDeducedBase = constraintType.Type;
275constraintEffectiveBase = (NamedTypeSymbol)constraintType.Type;
276constraintDeducedBase = constraintType.Type;
950if (typeArgument.Type.IsPointerOrFunctionPointer() || typeArgument.IsRestrictedType(ignoreSpanLikeTypes: true) || typeArgument.IsVoidType())
953diagnosticsBuilder.Add(new TypeParameterDiagnosticInfo(typeParameter, new UseSiteInfo<AssemblySymbol>(new CSDiagnosticInfo(ErrorCode.ERR_BadTypeArgument, typeArgument.Type))));
957if (typeArgument.Type.IsRefLikeOrAllowsRefLikeType())
976diagnosticsBuilder.Add(new TypeParameterDiagnosticInfo(typeParameter, new UseSiteInfo<AssemblySymbol>(new CSDiagnosticInfo(ErrorCode.ERR_NotRefStructConstraintNotSatisfied, containingSymbol.ConstructedFrom(), typeParameter, typeArgument.Type))));
984diagnosticsBuilder.Add(new TypeParameterDiagnosticInfo(typeParameter, new UseSiteInfo<AssemblySymbol>(new CSDiagnosticInfo(ErrorCode.ERR_GenericArgIsStaticClass, typeArgument.Type))));
990if (!typeArgument.Type.IsReferenceType)
993diagnosticsBuilder.Add(new TypeParameterDiagnosticInfo(typeParameter, new UseSiteInfo<AssemblySymbol>(new CSDiagnosticInfo(ErrorCode.ERR_RefConstraintNotSatisfied, containingSymbol.ConstructedFrom(), typeParameter, typeArgument.Type))));
1003var managedKind = typeArgument.Type.GetManagedKind(ref useSiteInfo);
1006if (managedKind == ManagedKind.Managed || !typeArgument.Type.IsNonNullableValueType())
1009diagnosticsBuilder.Add(new TypeParameterDiagnosticInfo(typeParameter, new UseSiteInfo<AssemblySymbol>(new CSDiagnosticInfo(ErrorCode.ERR_UnmanagedConstraintNotSatisfied, containingSymbol.ConstructedFrom(), typeParameter, typeArgument.Type))));
1030if (typeParameter.HasValueTypeConstraint && !typeArgument.Type.IsNonNullableValueType())
1033diagnosticsBuilder.Add(new TypeParameterDiagnosticInfo(typeParameter, new UseSiteInfo<AssemblySymbol>(new CSDiagnosticInfo(ErrorCode.ERR_ValConstraintNotSatisfied, containingSymbol.ConstructedFrom(), typeParameter, typeArgument.Type))));
1059if (typeArgument.Type.IsErrorType())
1081if (typeArgument.Type is NamedTypeSymbol { IsInterface: true } iface && SelfOrBaseHasStaticAbstractMember(iface, ref useSiteInfo, out Symbol member))
1110var error = SatisfiesConstructorConstraint(typeArgument.Type);
1118diagnosticsBuilder.Add(new TypeParameterDiagnosticInfo(typeParameter, new UseSiteInfo<AssemblySymbol>(new CSDiagnosticInfo(ErrorCode.ERR_NewConstraintNotSatisfied, containingSymbol.ConstructedFrom(), typeParameter, typeArgument.Type))));
1122diagnosticsBuilder.Add(new TypeParameterDiagnosticInfo(typeParameter, new UseSiteInfo<AssemblySymbol>(new CSDiagnosticInfo(ErrorCode.ERR_NewConstraintCannotHaveRequiredMembers, containingSymbol.ConstructedFrom(), typeParameter, typeArgument.Type))));
1139if (typeParameter.HasNotNullConstraint && typeArgument.GetValueNullableAnnotation().IsAnnotated() && !typeArgument.Type.IsNonNullableValueType())
1179if (typeArgument.Type.IsReferenceType)
1185errorCode = constraintType.Type.IsInterfaceType() ? ErrorCode.ERR_GenericConstraintNotSatisfiedNullableInterface : ErrorCode.ERR_GenericConstraintNotSatisfiedNullableEnum;
1199if (constraintType.Type.Equals(typeArgument.Type, TypeCompareKind.AllIgnoreOptions))
1201constraintTypeErrorArgument = constraintType.Type;
1202typeArgumentErrorArgument = typeArgument.Type;
1206SymbolDistinguisher distinguisher = new SymbolDistinguisher(args.CurrentCompilation, constraintType.Type, typeArgument.Type);
1216var type = typeWithAnnotations.Type;
1259var type = typeWithAnnotations.Type;
1338if (constraintType.Type.IsErrorType())
1349if (conversions.HasIdentityOrImplicitReferenceConversion(typeArgument.Type, constraintType.Type, ref useSiteInfo))
1354if (typeArgument.Type.IsValueType)
1358if (conversions.HasBoxingConversion(typeArgument.Type.IsNullableType() ? ((NamedTypeSymbol)typeArgument.Type).ConstructedFrom : typeArgument.Type,
1359constraintType.Type, ref useSiteInfo))
1364if (typeArgument.Type is NamedTypeSymbol { IsRefLikeType: true } refLike &&
1365conversions.ImplementsVarianceCompatibleInterface(refLike, constraintType.Type, ref useSiteInfo))
1373var typeParameter = (TypeParameterSymbol)typeArgument.Type;
1377if (conversions.HasImplicitTypeParameterConversion(typeParameter, constraintType.Type, ref useSiteInfo))
Symbols\Source\SourceComplexParameterSymbol.cs (11)
1066else if (!compilation.Conversions.HasCallerLineNumberConversion(TypeWithAnnotations.Type, ref useSiteInfo))
1070diagnostics.Add(ErrorCode.ERR_NoConversionForCallerLineNumberParam, node.Name.Location, intType, TypeWithAnnotations.Type);
1094else if (!compilation.Conversions.HasCallerInfoStringConversion(TypeWithAnnotations.Type, ref useSiteInfo))
1098diagnostics.Add(ErrorCode.ERR_NoConversionForCallerFilePathParam, node.Name.Location, stringType, TypeWithAnnotations.Type);
1127else if (!compilation.Conversions.HasCallerInfoStringConversion(TypeWithAnnotations.Type, ref useSiteInfo))
1131diagnostics.Add(ErrorCode.ERR_NoConversionForCallerMemberNameParam, node.Name.Location, stringType, TypeWithAnnotations.Type);
1168else if (!compilation.Conversions.HasCallerInfoStringConversion(TypeWithAnnotations.Type, ref useSiteInfo))
1172diagnostics.Add(ErrorCode.ERR_NoConversionForCallerArgumentExpressionParam, node.Name.Location, stringType, TypeWithAnnotations.Type);
1554var elementType = elementTypeWithAnnotations.Type;
1567elementType = elementTypeWithAnnotations.Type;
1625elementType = elementTypeWithAnnotations.Type;
Symbols\Source\SourceMemberContainerSymbol_ImplementationChecks.cs (16)
796if (IsOrContainsErrorType(parameterType.Type))
965if (!IsOrContainsErrorType(overridingMemberType.Type))
967diagnostics.Add(ErrorCode.ERR_CantChangeTypeOnOverride, overridingMemberLocation, overridingMember, overriddenMember, overriddenMemberType.Type);
1003if (DeclaringCompilation.Conversions.HasIdentityOrImplicitReferenceConversion(overridingMethod.ReturnTypeWithAnnotations.Type, overriddenMethod.ReturnTypeWithAnnotations.Type, ref discardedUseSiteInfo))
1068if (!IsOrContainsErrorType(overridingMemberType.Type))
1073DeclaringCompilation.Conversions.HasIdentityOrImplicitReferenceConversion(overridingMemberType.Type, overriddenMemberType.Type, ref discardedUseSiteInfo))
1077diagnostics.Add(ErrorCode.ERR_RuntimeDoesNotSupportCovariantPropertiesOfClasses, overridingMemberLocation, overridingMember, overriddenMember, overriddenMemberType.Type);
1089diagnostics.Add(ErrorCode.ERR_CantChangeTypeOnOverride, overridingMemberLocation, overridingMember, overriddenMember, overriddenMemberType.Type);
1209var result = DeclaringCompilation.Conversions.HasIdentityOrImplicitReferenceConversion(overridingReturnType.Type, overriddenReturnType.Type, ref useSiteInfo);
1274overrideReturnType.Type,
1275baseMethod.ReturnTypeWithAnnotations.Type))
1307baseParameterType.Type,
1308overrideParameterType.Type))
Symbols\TypeWithAnnotations.cs (49)
63public override string ToString() => Type.ToString();
110if (NullableAnnotation.IsAnnotated() || (Type.IsValueType && Type.IsNullableType()))
115return Create(Type, NullableAnnotation.Annotated, CustomModifiers);
120if (NullableAnnotation.IsNotAnnotated() || (Type.IsValueType && !Type.IsNullableType()))
125return Create(Type, NullableAnnotation.NotAnnotated, CustomModifiers);
136if (Type?.IsPossiblyNullableReferenceTypeTypeParameter() == true)
141if (Type.IsNullableTypeOrTypeParameter())
160return Type.IsNullableTypeOrTypeParameter();
198var typeSymbol = this.Type;
243TypeSymbol typeSymbol = other.Type;
245TypeSymbol type = Type.MergeEquivalentTypes(typeSymbol, variance);
264public bool IsNullableType() => Type.IsNullableType();
267/// The list of custom modifiers, if any, associated with the <see cref="Type"/>.
271public TypeKind TypeKind => Type.TypeKind;
273public Cci.PrimitiveTypeCode PrimitiveTypeCode => Type.PrimitiveTypeCode;
304var str = !HasType ? "<null>" : Type.ToDisplayString(format);
309(!HasType || (!IsNullableType() && !Type.IsValueType)))
315(!HasType || (!Type.IsValueType && !Type.IsTypeParameterDisallowingAnnotationInCSharp8())))
377TypeSymbol type = Type;
408return obj.Type.GetHashCode();
426return Type.GetUnificationUseSiteDiagnosticRecursive(ref result, owner, ref checkedTypes) ||
445TypeSymbol typeSymbol = this.Type;
454if (typeSymbol.Equals(newTypeWithModifiers.Type, TypeCompareKind.ConsiderEverything) &&
465return Create(newTypeWithModifiers.Type, NullableAnnotation, newCustomModifiers);
478if (newTypeWithModifiers.Type is PlaceholderTypeArgumentSymbol)
484Debug.Assert(newTypeWithModifiers.Type is not IndexedTypeParameterSymbol || newTypeWithModifiers.NullableAnnotation == NullableAnnotation.Ignored);
512Debug.Assert((object)newTypeWithModifiers.DefaultType == newTypeWithModifiers.Type);
534newTypeWithModifiers.Type,
544return Type.Equals(other.Type, comparison);
549binder.ReportDiagnosticsIfObsolete(diagnostics, Type, syntax, hasBaseReceiver: false);
596typeWithAnnotationsPredicate: (t, a, b) => t.NullableAnnotation != NullableAnnotation.Oblivious && !t.Type.IsErrorType() && !t.Type.IsValueType,
629var type = typeWithAnnotations.Type;
665TypeSymbol oldTypeSymbol = Type;
726var typeSymbol = Type;
737var typeSymbol = Type;
775return Type.GetHashCode();
811return TypeWithState.Create(Type, getFlowState(Type, NullableAnnotation));
1084TryForceResolve(asValueType: _underlying.Type.IsValueType);
1090internal override TypeSymbol GetNullableUnderlyingTypeOrSelf(TypeSymbol typeSymbol) => _underlying.Type;
1145if (!_underlying.Type.IsValueType)
1162if (newUnderlying.Type.Equals(this._underlying.Type, TypeCompareKind.ConsiderEverything) &&
1204_underlying.Type;