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;
1752Debug.Assert(elementTypeWithAnnotations.Type is null); // GetCollectionExpressionTypeKind() does not set elementType for these cases.
1773var elementType = elementTypeWithAnnotations.Type;
1894var spanTypeArg = ((NamedTypeSymbol)methodWithTargetTypeParameters.Parameters[0].Type).TypeArgumentsWithAnnotationsNoUseSiteDiagnostics[0].Type;
2489convertedArguments.Add(CreateConversion(argument.Syntax, argument, elementConversion, isCast: isCast, elementConversionGroup, destType.Type, diagnostics));
Binder\Binder_Deconstruct.cs (7)
855var type = declTypeWithAnnotations.Type;
893CheckRestrictedTypeInAsyncMethod(this.ContainingMemberOrLambda, declTypeWithAnnotations.Type, diagnostics, typeSyntax);
897localSymbol.Scope == ScopedKind.ScopedValue && !declTypeWithAnnotations.Type.IsErrorOrRefLikeOrAllowsRefLikeType())
910return new BoundLocal(syntax, localSymbol, BoundLocalDeclarationKind.WithExplicitType, constantValueOpt: null, isNullableUnknown: false, type: declTypeWithAnnotations.Type, hasErrors: hasErrors);
948Debug.Assert(TypeSymbol.Equals(declTypeWithAnnotations.Type, fieldType.Type, TypeCompareKind.ConsiderEverything2));
955type: fieldType.Type);
Binder\Binder_Expressions.cs (35)
452field.GetFieldType(initializerBinder.FieldsBeingBound).Type, diagnostics);
1234return new BoundRefValueOperator(node, typeWithAnnotations.NullableAnnotation, argument, typeWithAnnotations.Type, hasErrors);
1374TypeSymbol type = typeWithAnnotations.Type;
1402var type = typeWithAnnotations.Type;
1427TypeSymbol type = typeWithAnnotations.Type;
1537TypeSymbol type = typeWithAnnotations.Type;
2541TypeSymbol targetType = targetTypeWithAnnotations.Type;
2703TypeSymbol targetType = targetTypeWithAnnotations.Type;
2861var targetElementType = targetElementTypesWithAnnotations[i].Type;
2888TypeWithAnnotations underlyingTargetTypeWithAnnotations = targetTypeWithAnnotations.Type.GetNullableUnderlyingTypeWithAnnotations();
2889var underlyingConversion = Conversions.ClassifyBuiltInConversion(operand.Type, underlyingTargetTypeWithAnnotations.Type, isChecked: CheckOverflowAtRuntime, ref discardedUseSiteInfo);
3133var type = declType.Type;
3187CheckRestrictedTypeInAsyncMethod(this.ContainingMemberOrLambda, declType.Type, diagnostics, typeSyntax);
3189if (localSymbol.Scope == ScopedKind.ScopedValue && !declType.Type.IsErrorOrRefLikeOrAllowsRefLikeType())
3194return new BoundLocal(declarationExpression, localSymbol, BoundLocalDeclarationKind.WithExplicitType, constantValueOpt: null, isNullableUnknown: false, type: declType.Type);
3231TypeSymbol fieldType = expressionVariableField.GetFieldType(this.FieldsBeingBound).Type;
3520coercedArgument = bindInterpolatedStringHandlerInMemberCall(argument, parameterTypeWithAnnotations.Type, argumentsForInterpolationConversion, parameters, in result, arg, receiver, diagnostics);
3527coercedArgument = CreateConversion(argument.Syntax, argument, kind, isCast: false, conversionGroupOpt: null, parameterTypeWithAnnotations.Type, diagnostics);
3548coercedArgument = CreateConversion(argument.Syntax, argument, kind, isCast: false, conversionGroupOpt: null, parameterTypeWithAnnotations.Type, diagnostics);
3602Debug.Assert(methodResult.Result.ParamsElementTypeOpt.Type != (object)ErrorTypeSymbol.EmptyParamsCollectionElementTypeSentinel);
3669if (!methodResult.Member.IsIndexer() && !argument.HasAnyErrors && parameterTypeWithAnnotations.Type.ContainsPointer())
3978var type = (ArrayTypeSymbol)BindArrayType(node.Type, diagnostics, permitDimensions: true, basesBeingResolved: null, disallowRestrictedTypes: true).Type;
4461var arrayType = (ArrayTypeSymbol)BindArrayType(arrayTypeSyntax, diagnostics, permitDimensions: true, basesBeingResolved: null, disallowRestrictedTypes: false).Type;
4465if (!elementType.Type.IsErrorType())
4467hasErrors = hasErrors || CheckManagedAddr(Compilation, elementType.Type, elementTypeSyntax.Location, diagnostics, errorForManaged: true);
4518? new BoundStackAllocArrayCreation(node, elementType.Type, count, initializerOpt: null, type, hasErrors: hasErrors)
4519: BindStackAllocWithInitializer(node, node.StackAllocKeyword, node.Initializer, type, elementType.Type, count, diagnostics, hasErrors);
5143var type = typeWithAnnotations.Type;
7562if (typeArgument.Type.IsPointerOrFunctionPointer() || typeArgument.Type.IsRestrictedType())
7565Error(diagnostics, ErrorCode.ERR_BadTypeArgument, typeArgumentsSyntax[i], typeArgument.Type);
8175resultType = ((FieldSymbol)symbolOpt).GetFieldType(this.FieldsBeingBound).Type;
8617TypeSymbol fieldType = fieldSymbol.GetFieldType(this.FieldsBeingBound).Type;
10817Debug.Assert(returnType.Type is { }); // Expecting System.Void rather than null return type.
10820bool 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;
847Error(diagnostics, ErrorCode.ERR_VarDeclIsStaticClass, typeSyntax, declType.Type);
850if (isConst && !declType.Type.CanBeConst())
852Error(diagnostics, ErrorCode.ERR_BadConstType, typeSyntax, declType.Type);
1027Error(localDiagnostics, ErrorCode.ERR_ImplicitlyTypedVariableAssignedBadValue, declarator, declTypeOpt.Type);
1032if (!declTypeOpt.Type.IsErrorType())
1056initializerOpt = BindPossibleArrayInitializer(value, declTypeOpt.Type, valueKind, diagnostics);
1061declTypeOpt.Type,
1083if (!declTypeOpt.Type.IsPointerType())
1087Error(localDiagnostics, declTypeOpt.Type.IsFunctionPointer() ? ErrorCode.ERR_CannotUseFunctionPointerAsFixedLocal : ErrorCode.ERR_BadFixedInitType, declarator);
1091else if (!IsValidFixedVariableInitializer(declTypeOpt.Type, ref initializerOpt, localDiagnostics))
1097CheckRestrictedTypeInAsyncMethod(this.ContainingMemberOrLambda, declTypeOpt.Type, localDiagnostics, typeSyntax);
1099if (localSymbol.Scope == ScopedKind.ScopedValue && !declTypeOpt.Type.IsErrorOrRefLikeOrAllowsRefLikeType())
2063conversionError(diagnostics, ErrorCode.ERR_ExpressionTreeMustHaveDelegate, ((NamedTypeSymbol)targetType).TypeArgumentsWithAnnotationsNoUseSiteDiagnostics[0].Type);
2522var targetElementType = targetElementTypes[i].Type;
3249type = this.BindType(declaration.Type, diagnostics).Type;
Binder\Binder_Symbols.cs (7)
530else if (LazyMissingNonNullTypesContextDiagnosticInfo.IsNullableReference(typeArgument.Type))
554ReportUseSite(constructedType.Type.OriginalDefinition, diagnostics, syntax);
555var type = (NamedTypeSymbol)constructedType.Type;
598CheckManagedAddr(Compilation, elementType.Type, node.Location, diagnostics);
613if (type.Type.IsTypeParameterDisallowingAnnotationInCSharp8())
638Error(diagnostics, ErrorCode.ERR_ArrayOfStaticClass, node.ElementType, type.Type);
649Error(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"));
316CheckRestrictedTypeInAsyncMethod(this.ContainingMemberOrLambda, declType.Type, diagnostics, typeSyntax);
318if (local.Scope == ScopedKind.ScopedValue && !declType.Type.IsErrorOrRefLikeOrAllowsRefLikeType())
375var valuePlaceholder = new BoundDeconstructValuePlaceholder(_syntax.Expression, variableSymbol: null, isDiscardExpression: false, iterationVariableType.Type).MakeCompilerGenerated();
431hasErrors = hasErrors || boundIterationVariableType.HasErrors || iterationVariableType.Type.IsErrorType();
469Conversion elementConversionClassification = this.Conversions.ClassifyConversionFromType(inferredType.Type, iterationVariableType.Type, isChecked: CheckOverflowAtRuntime, ref useSiteInfo, forCast: true);
473Error(diagnostics, ErrorCode.ERR_RefAssignmentMustHaveIdentityConversion, collectionExpr.Syntax, iterationVariableType.Type);
477var elementPlaceholder = new BoundValuePlaceholder(_syntax, inferredType.Type).MakeCompilerGenerated();
485diagnostics.Add(ErrorCode.ERR_AmbigUDConv, foreachKeyword.GetLocation(), originalUserDefinedConversions[0], originalUserDefinedConversions[1], inferredType.Type, iterationVariableType);
489SymbolDistinguisher distinguisher = new SymbolDistinguisher(this.Compilation, inferredType.Type, iterationVariableType.Type);
501BoundExpression 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))
1605var delegateType = type.TypeArgumentsWithAnnotationsNoUseSiteDiagnostics[0].Type;
1882var type = typeWithAnnotations.Type;
1896ClassifyImplicitConversionFromType(source.Type, destination.Type, ref discardedUseSiteInfo).Kind != ConversionKind.NoConversion;
1962conversions.ClassifyImplicitExtensionMethodThisArgConversion(s, s.Type, d.Type, ref u, isMethodGroupConversion: false),
1984return conversions.ClassifyImplicitExtensionMethodThisArgConversion(sourceExpressionOpt: null, s.Type, d.Type, ref u, isMethodGroupConversion: false);
2297=> conversions.ClassifyImplicitConversionFromExpression(s, d.Type, ref u),
2315conversions.ClassifyConversionFromExpression(s, d.Type, isChecked: isChecked, ref u, forCast: forCast),
2373return conversions.ClassifyImplicitConversionFromType(s.Type, d.Type, ref u);
2392return conversions.ClassifyConversionFromType(s.Type, d.Type, isChecked: isChecked, ref u, forCast);
2600return HasIdentityOrImplicitReferenceConversion(elementType.Type, argument0.Type, ref useSiteInfo);
2614HasIdentityConversionInternal(source.Type, destination.Type, includeNullability: true))
2619return HasImplicitReferenceConversion(source.Type, destination.Type, ref useSiteInfo);
3421&& (HasIdentityOrImplicitReferenceConversion(sourceType.Type, destinationType.Type, ref useSiteInfo)
3422|| HasImplicitPointerToVoidConversion(sourceType.Type, destinationType.Type)
3423|| HasImplicitPointerConversion(sourceType.Type, destinationType.Type, ref useSiteInfo));
3427&& HasIdentityConversion(sourceType.Type, destinationType.Type);
3688var sourceArg = sourceTypeArguments[i].Type;
3689var destinationArg = destinationTypeArguments[i].Type;
3771if (HasExplicitReferenceConversion(sourceArray.ElementType, ((NamedTypeSymbol)destination).TypeArgumentWithDefinitionUseSiteDiagnostics(0, ref useSiteInfo).Type, ref useSiteInfo))
3791var sourceElement = ((NamedTypeSymbol)source).TypeArgumentWithDefinitionUseSiteDiagnostics(0, ref useSiteInfo).Type;
4008return HasIdentityConversionInternal(source.Type, destination.Type) &&
4030return HasIdentityOrReferenceConversion(elementType.Type, spanElementType.Type, ref useSiteInfo) &&
Binder\Semantics\OverloadResolution\MethodTypeInference.cs (72)
452if (!fixedResultType.Type.IsErrorType())
461var errorTypeName = fixedResultType.Type.Name;
490TypeParameterSymbol typeParameter = (TypeParameterSymbol)type.Type;
513var methodTypeParameter = (TypeParameterSymbol)methodTypeParameterWithAnnotations.Type;
547return typeMap.SubstituteType(delegateOrFunctionPointerType).Type;
587ExactOrBoundsKind kind = GetRefKind(arg).IsManagedReference() || target.Type.IsPointerType() ? ExactOrBoundsKind.Exact : ExactOrBoundsKind.LowerBound;
609if (argument.Kind == BoundKind.UnboundLambda && target.Type.GetDelegateType() is { })
623if (IsReallyAType(argumentType.Type))
629var ordinal = ((TypeParameterSymbol)target.Type).Ordinal;
642TypeSymbol targetType = target.Type;
677Debug.Assert(target.Type is { });
678if (target.Type is null)
699if (target.Type.Kind != SymbolKind.NamedType)
705var destination = (NamedTypeSymbol)target.Type;
861if (HasUnfixedParamInOutputType(argument, formalType.Type) && !HasUnfixedParamInInputType(argument, formalType.Type))
879if (!binder.TryGetCollectionIterationType((ExpressionSyntax)argument.Syntax, formalType.Type, out TypeWithAnnotations targetElementType))
895if (formalType.Type.Kind != SymbolKind.NamedType)
901var destination = (NamedTypeSymbol)formalType.Type;
1118var formalParameterType = _formalParameterTypes[iArg].Type;
1360if (MethodGroupReturnTypeInference(binder, expression, target.Type, ref useSiteInfo))
1382var delegateType = target.Type.GetDelegateType();
1404Debug.Assert(inferredReturnType.Type is not FunctionTypeSymbol);
1541var delegateType = target.Type.GetDelegateType();
1594var delegateInvokeMethod = target.Type.GetDelegateType()?.DelegateInvokeMethod();
1639if (ExactSpanInference(source.Type, target.Type, ref useSiteInfo))
1684if (!source.Type.IsArray() || !target.Type.IsArray())
1689var arraySource = (ArrayTypeSymbol)source.Type;
1690var arrayTarget = (ArrayTypeSymbol)target.Type;
1779ExactOrBoundsInference(kind, ((NamedTypeSymbol)source.Type).TypeArgumentsWithAnnotationsNoUseSiteDiagnostics[0], ((NamedTypeSymbol)target.Type).TypeArgumentsWithAnnotationsNoUseSiteDiagnostics[0], ref useSiteInfo);
1813if (!source.Type.TryGetElementTypesWithAnnotationsIfTupleType(out sourceTypes) ||
1814!target.Type.TryGetElementTypesWithAnnotationsIfTupleType(out targetTypes) ||
1837var namedSource = source.Type as NamedTypeSymbol;
1843var namedTarget = target.Type as NamedTypeSymbol;
1862ExactInference(((PointerTypeSymbol)source.Type).PointedAtTypeWithAnnotations, ((PointerTypeSymbol)target.Type).PointedAtTypeWithAnnotations, ref useSiteInfo);
1865else if (source.Type is FunctionPointerTypeSymbol { Signature: { ParameterCount: int sourceParameterCount } sourceSignature } &&
1866target.Type is FunctionPointerTypeSymbol { Signature: { ParameterCount: int targetParameterCount } targetSignature } &&
1976if (LowerBoundArrayInference(source.Type, target.Type, ref useSiteInfo))
1983if (LowerBoundSpanInference(source.Type, target.Type, ref useSiteInfo))
2020if (LowerBoundConstructedInference(source.Type, target.Type, ref useSiteInfo))
2025if (LowerBoundFunctionPointerTypeInference(source.Type, target.Type, ref useSiteInfo))
2109if (elementSource.Type.IsReferenceType)
2144if (!sourceElementType.Type.IsReferenceType || target.IsSpan())
2484Debug.Assert(source.Type.IsReferenceType || source.Type.IsFunctionPointer());
2501if (UpperBoundFunctionPointerTypeInference(source.Type, target.Type, ref useSiteInfo))
2536if (!target.Type.IsArray())
2540var arrayTarget = (ArrayTypeSymbol)target.Type;
2542var elementSource = GetMatchingElementType(arrayTarget, source.Type, ref useSiteInfo);
2548if (elementSource.Type.IsReferenceType)
2569var source = sourceWithAnnotations.Type;
2570var target = targetWithAnnotations.Type;
2821Debug.Assert(best.Type.Type.Equals(withoutNullability.Type, TypeCompareKind.IgnoreDynamicAndTupleNames | TypeCompareKind.IgnoreNullableModifiersForReferenceTypes));
2985functionType = type.Type as FunctionTypeSymbol;
2992return constraintTypes.Any(static t => isExpressionType(t.Type));
3011var source = sourceWithAnnotations.Type;
3012var destination = destinationWithAnnotations.Type;
3251if (!dest.Type.ContainsTypeParameter(pParam))
3395var newBound = TypeWithAnnotations.Create(oldBound.Type, newAnnotation);
3421if (newCandidate.Type.IsDynamic())
3452return obj.Type.GetHashCode();
3459if (x.Type.IsDynamic() ^ y.Type.IsDynamic()) { return false; }
Binder\Semantics\OverloadResolution\OverloadResolution.cs (18)
1253expandedResult.Result.ParamsElementTypeOpt.Type != (object)ErrorTypeSymbol.EmptyParamsCollectionElementTypeSentinel)
1336if (elementType.Type is null)
1357Debug.Assert(elementType.Type is { });
2568Debug.Assert(paramsElementTypeOpt.Type != (object)ErrorTypeSymbol.EmptyParamsCollectionElementTypeSentinel);
2569return paramsElementTypeOpt.Type;
3203t1, kind1, elementType1.Type, underlyingElementConversions1: [],
3204t2, kind2, elementType2.Type, underlyingElementConversions2: [],
3218elementType = typeArg.Type;
3261if (x.HasType && Conversions.HasIdentityConversion(x.Type, y))
3271y = ((NamedTypeSymbol)y).TypeArgumentsWithAnnotationsNoUseSiteDiagnostics[0].Type;
3364if (!ExpressionMatchExactly(sourceArguments[i], destTypes[i].Type, ref useSiteInfo))
3490return BetterConversionTargetCore(((NamedTypeSymbol)type1).TypeArgumentsWithAnnotationsNoUseSiteDiagnostics[0].Type,
3491((NamedTypeSymbol)type2).TypeArgumentsWithAnnotationsNoUseSiteDiagnostics[0].Type,
3996TryInferParamsCollectionIterationType(binder, type.Type, out paramsIterationType);
4265if (!parameterTypes[i].Type.CheckAllConstraints(Compilation, Conversions))
4466&& parameters.ParameterTypes[argumentPosition].Type is NamedTypeSymbol { IsInterpolatedStringHandlerType: true, IsValueType: true })
4479parameters.ParameterTypes[argumentPosition].Type,
4491(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 (91)
130Debug.Assert(TypeSymbol.Equals(RValueType.Type, LValueType.Type, TypeCompareKind.ConsiderEverything));
751if (symbolType.Type.IsValueType || symbolType.Type.IsErrorType())
783var badState = symbolType.Type.IsPossiblyNullableReferenceTypeTypeParameter() && (annotations & FlowAnalysisAnnotations.NotNull) == 0
841SetState(ref this.State, memberSlot, type.Type.IsPossiblyNullableReferenceTypeTypeParameter() ? NullableFlowState.MaybeDefault : NullableFlowState.MaybeNull);
2265type.Type.IsValueType)
2282if (type.Type.IsTypeParameterDisallowingAnnotationInCSharp8() && !(type.Type is TypeParameterSymbol { IsNotNullable: true }))
2308!targetType.Type.Equals(valueType.Type, TypeCompareKind.AllIgnoreOptions))
2541InheritDefaultState(targetType.Type, targetSlot);
2547if (targetType.Type.IsReferenceType ||
2556else if (EmptyStructTypeCache.IsTrackableStructType(targetType.Type))
2558InheritNullableStateOfTrackableStruct(targetType.Type, targetSlot, valueSlot, isDefaultValue: !(valueOpt is null) && IsDefaultValue(valueOpt), skipSlot: targetSlot);
2564target.Type.Equals(assignedValue.Type, TypeCompareKind.AllIgnoreOptions);
2632if (fieldOrPropertyType.Type.IsReferenceType ||
2661else if (EmptyStructTypeCache.IsTrackableStructType(fieldOrPropertyType.Type))
2671InheritNullableStateOfTrackableStruct(fieldOrPropertyType.Type, targetMemberSlot, valueMemberSlot, isDefaultValue: isDefaultValue, skipSlot);
2678return _variables[slot].Symbol.GetTypeOrReturnType().Type;
2713var actualType = _variables[targetSlot].Symbol.GetTypeOrReturnType().Type;
2733InheritDefaultState(symbol.GetTypeOrReturnType().Type, slot);
2831if (EmptyStructTypeCache.IsTrackableStructType(parameterType.Type))
2834parameterType.Type,
2867return TypeWithState.Create(parameterType.Type, NullableFlowState.MaybeDefault);
2872return TypeWithState.Create(parameterType.Type, NullableFlowState.NotNull);
2896returnType.Type.SpecialType == SpecialType.System_Boolean)
3003type = ((NamedTypeSymbol)returnType.Type).TypeArgumentsWithAnnotationsNoUseSiteDiagnostics.Single();
3030if (!node.Type.Equals(type.Type, TypeCompareKind.ConsiderEverything | TypeCompareKind.IgnoreNullableModifiersForReferenceTypes | TypeCompareKind.IgnoreDynamicAndTupleNames))
3035Debug.Assert(node.Type.IsErrorType() || type.Type.IsErrorType());
3398VisitObjectCreationInitializer(resultSlot, resultType.Type, withExpr.InitializerExpression, delayCompletionForType: false);
3451InheritDefaultState(GetDeclaredLocalResult(local).Type, slot);
3509Debug.Assert(type.Type.IsErrorType());
3588return AnonymousTypeManager.GetAnonymousTypeFieldTypes(type).Any(static t => canIgnoreAnyType(t.Type));
3768var strippedTargetCollectionType = targetCollectionType.Type.StrippedType();
3924Debug.Assert(TypeSymbol.Equals(resultTypeWithAnnotations.Type, node.Type, TypeCompareKind.IgnoreNullableModifiersForReferenceTypes));
3926var type = resultTypeWithAnnotations.Type;
4002if (AreNullableAndUnderlyingTypes(type, parameterType.Type, out TypeWithAnnotations underlyingType))
4196Debug.Assert(TypeSymbol.Equals(objectInitializer.Type, symbol.GetTypeOrReturnType().Type, TypeCompareKind.IgnoreNullableModifiersForReferenceTypes));
4213Action<int, TypeSymbol>? nestedCompletion = VisitObjectCreationInitializer(slot, symbol.GetTypeOrReturnType().Type, initializer, delayCompletionForType);
4246nestedCompletion?.Invoke(slot, symbol.GetTypeOrReturnType().Type);
4328Debug.Assert(TypeSymbol.Equals(containingType, receiverResult.LValueType.Type, TypeCompareKind.IgnoreNullableModifiersForReferenceTypes));
4386Debug.Assert(TypeSymbol.Equals(containingType, receiverResult.LValueType.Type, TypeCompareKind.IgnoreNullableModifiersForReferenceTypes));
4637inferredType = TypeWithState.Create(inferredType.Type, elementState).ToTypeWithAnnotations(compilation);
5117if (isLifted && targetTypeWithNullability.Type.IsNonNullableValueType())
5487MarkDependentSlotsNotNull(childSlot, member.GetTypeOrReturnType().Type, ref state, depth - 1);
5560Debug.Assert(targetType.Type.ContainsErrorType() ||
5562TypeSymbol.Equals(targetType.Type.GetNullableUnderlyingType(), node.Type, TypeCompareKind.AllIgnoreOptions));
5566leftSlot = GetNullableOfTValueSlot(targetType.Type, leftSlot, out _);
5572Debug.Assert(TypeSymbol.Equals(targetType.Type, rightResult.Type, TypeCompareKind.AllIgnoreOptions));
5576TypeWithState resultType = TypeWithState.Create(targetType.Type, rightResult.State);
5836TypeSymbol accessType = accessTypeWithAnnotations.Type;
6030var typeWithState = TypeWithState.Create(resultTypeWithAnnotations.Type, resultState);
6043return TypeWithState.Create(resultTypeWithAnnotations.Type, resultState);
6158new BoundExpressionWithNullability(expr.Syntax, expr, type.NullableAnnotation, type.Type);
6598if (parameter.ContainingSymbol.GetTypeOrReturnType().Type.SpecialType != SpecialType.System_Boolean)
7368conversion = GenerateConversion(_conversions, argumentNoConversion, argumentResultType, parameterType.Type, fromExplicitCast: false, extensionMethodThisArgument: false, isChecked: conversionOpt?.Checked ?? false);
7372ReportNullabilityMismatchInArgument(argumentNoConversion.Syntax, argumentResultType, parameter, parameterType.Type, forOutput: false);
7404if (IsNullabilityMismatch(lvalueResultType.Type, parameterType.Type))
7407ReportNullabilityMismatchInRefArgument(argumentNoConversion, argumentType: lvalueResultType.Type, parameter, parameterType.Type);
7511parameterWithState = TypeWithState.Create(parameterType.Type, adjustedState);
7568if (!_conversions.HasIdentityOrImplicitReferenceConversion(parameterType.Type, lValueType.Type, ref discardedUseSiteInfo))
7570ReportNullabilityMismatchInArgument(argument.Syntax, lValueType.Type, parameter, parameterType.Type, forOutput: true);
7805OverloadResolution.TryInferParamsCollectionIterationType(_binder, type.Type, out paramsIterationType);
7994return new BoundExpressionWithNullability(argument.Syntax, argument, argumentType.NullableAnnotation, argumentType.Type);
8274if (TypeAllowsConditionalState(targetType.Type) && TypeAllowsConditionalState(operand.Type))
8387if (typeArg.Type.Equals(underlyingTypeOpt, TypeCompareKind.AllIgnoreOptions))
8808operandType = completion(targetTypeWithNullability.Type.GetNullableUnderlyingTypeWithAnnotations());
8836TypeSymbol targetType = targetTypeWithNullability.Type;
9152if (targetType.Type?.IsTypeParameterDisallowingAnnotationInCSharp8() == true)
9161dependsOnTypeParameter(typeParameter1, (TypeParameterSymbol)targetType.Type, NullableAnnotation.NotAnnotated, out var annotation))
9168if (targetType.Type?.IsTypeParameterDisallowingAnnotationInCSharp8() == false)
9192targetType.Type is TypeParameterSymbol typeParameter2)
9242if (constraintType.Type is TypeParameterSymbol constraintTypeParameter &&
9346TypeSymbol targetType = targetTypeWithNullability.Type;
9516bool typeNeedsLifting = returnType.Type.IsNonNullableValueType();
9517TypeSymbol type = typeNeedsLifting ? MakeNullableOf(returnType) : returnType.Type;
9561var conversion = _conversions.ClassifyStandardConversion(operandType.Type, targetType.Type, ref discardedUseSiteInfo);
9566ReportNullabilityMismatchInArgument(diagnosticLocation, operandType.Type, parameterOpt, targetType.Type, forOutput: false);
9570ReportNullabilityMismatchInAssignment(diagnosticLocation, operandType.Type, targetType.Type);
9651Debug.Assert(TypeSymbol.Equals(resultTypeWithAnnotations.Type, node.Type, TypeCompareKind.IgnoreNullableModifiersForReferenceTypes));
9652var delegateType = (NamedTypeSymbol)resultTypeWithAnnotations.Type;
9828arguments.Add(new BoundExpressionWithNullability(syntax, new BoundParameter(syntax, parameter), parameterType.NullableAnnotation, parameterType.Type));
9978SetResult(node, TypeWithState.Create(leftLValueType.Type, rightState.State), leftLValueType);
10319var valueBeforeNullableWrapping = TypeWithState.Create(underlyingType.Type, NullableFlowState.NotNull);
10603if (argumentType.Type is { } argType && IsNullabilityMismatch(paramType.Type, argType))
10605ReportNullabilityMismatchInArgument(argument.Syntax, argType, parameter, paramType.Type, forOutput: false);
11125conversion = _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;
935if (typeArgument.Type.IsPointerOrFunctionPointer() || typeArgument.IsRestrictedType(ignoreSpanLikeTypes: true) || typeArgument.IsVoidType())
938diagnosticsBuilder.Add(new TypeParameterDiagnosticInfo(typeParameter, new UseSiteInfo<AssemblySymbol>(new CSDiagnosticInfo(ErrorCode.ERR_BadTypeArgument, typeArgument.Type))));
942if (typeArgument.Type.IsRefLikeOrAllowsRefLikeType())
961diagnosticsBuilder.Add(new TypeParameterDiagnosticInfo(typeParameter, new UseSiteInfo<AssemblySymbol>(new CSDiagnosticInfo(ErrorCode.ERR_NotRefStructConstraintNotSatisfied, containingSymbol.ConstructedFrom(), typeParameter, typeArgument.Type))));
969diagnosticsBuilder.Add(new TypeParameterDiagnosticInfo(typeParameter, new UseSiteInfo<AssemblySymbol>(new CSDiagnosticInfo(ErrorCode.ERR_GenericArgIsStaticClass, typeArgument.Type))));
975if (!typeArgument.Type.IsReferenceType)
978diagnosticsBuilder.Add(new TypeParameterDiagnosticInfo(typeParameter, new UseSiteInfo<AssemblySymbol>(new CSDiagnosticInfo(ErrorCode.ERR_RefConstraintNotSatisfied, containingSymbol.ConstructedFrom(), typeParameter, typeArgument.Type))));
988var managedKind = typeArgument.Type.GetManagedKind(ref useSiteInfo);
991if (managedKind == ManagedKind.Managed || !typeArgument.Type.IsNonNullableValueType())
994diagnosticsBuilder.Add(new TypeParameterDiagnosticInfo(typeParameter, new UseSiteInfo<AssemblySymbol>(new CSDiagnosticInfo(ErrorCode.ERR_UnmanagedConstraintNotSatisfied, containingSymbol.ConstructedFrom(), typeParameter, typeArgument.Type))));
1015if (typeParameter.HasValueTypeConstraint && !typeArgument.Type.IsNonNullableValueType())
1018diagnosticsBuilder.Add(new TypeParameterDiagnosticInfo(typeParameter, new UseSiteInfo<AssemblySymbol>(new CSDiagnosticInfo(ErrorCode.ERR_ValConstraintNotSatisfied, containingSymbol.ConstructedFrom(), typeParameter, typeArgument.Type))));
1044if (typeArgument.Type.IsErrorType())
1066if (typeArgument.Type is NamedTypeSymbol { IsInterface: true } iface && SelfOrBaseHasStaticAbstractMember(iface, ref useSiteInfo, out Symbol member))
1095var error = SatisfiesConstructorConstraint(typeArgument.Type);
1103diagnosticsBuilder.Add(new TypeParameterDiagnosticInfo(typeParameter, new UseSiteInfo<AssemblySymbol>(new CSDiagnosticInfo(ErrorCode.ERR_NewConstraintNotSatisfied, containingSymbol.ConstructedFrom(), typeParameter, typeArgument.Type))));
1107diagnosticsBuilder.Add(new TypeParameterDiagnosticInfo(typeParameter, new UseSiteInfo<AssemblySymbol>(new CSDiagnosticInfo(ErrorCode.ERR_NewConstraintCannotHaveRequiredMembers, containingSymbol.ConstructedFrom(), typeParameter, typeArgument.Type))));
1124if (typeParameter.HasNotNullConstraint && typeArgument.GetValueNullableAnnotation().IsAnnotated() && !typeArgument.Type.IsNonNullableValueType())
1164if (typeArgument.Type.IsReferenceType)
1170errorCode = constraintType.Type.IsInterfaceType() ? ErrorCode.ERR_GenericConstraintNotSatisfiedNullableInterface : ErrorCode.ERR_GenericConstraintNotSatisfiedNullableEnum;
1184if (constraintType.Type.Equals(typeArgument.Type, TypeCompareKind.AllIgnoreOptions))
1186constraintTypeErrorArgument = constraintType.Type;
1187typeArgumentErrorArgument = typeArgument.Type;
1191SymbolDistinguisher distinguisher = new SymbolDistinguisher(args.CurrentCompilation, constraintType.Type, typeArgument.Type);
1201var type = typeWithAnnotations.Type;
1244var type = typeWithAnnotations.Type;
1323if (constraintType.Type.IsErrorType())
1334if (conversions.HasIdentityOrImplicitReferenceConversion(typeArgument.Type, constraintType.Type, ref useSiteInfo))
1339if (typeArgument.Type.IsValueType)
1343if (conversions.HasBoxingConversion(typeArgument.Type.IsNullableType() ? ((NamedTypeSymbol)typeArgument.Type).ConstructedFrom : typeArgument.Type,
1344constraintType.Type, ref useSiteInfo))
1349if (typeArgument.Type is NamedTypeSymbol { IsRefLikeType: true } refLike &&
1350conversions.ImplementsVarianceCompatibleInterface(refLike, constraintType.Type, ref useSiteInfo))
1358var typeParameter = (TypeParameterSymbol)typeArgument.Type;
1362if (conversions.HasImplicitTypeParameterConversion(typeParameter, constraintType.Type, ref useSiteInfo))
Symbols\Source\SourceComplexParameterSymbol.cs (11)
1070else if (!compilation.Conversions.HasCallerLineNumberConversion(TypeWithAnnotations.Type, ref useSiteInfo))
1074diagnostics.Add(ErrorCode.ERR_NoConversionForCallerLineNumberParam, node.Name.Location, intType, TypeWithAnnotations.Type);
1098else if (!compilation.Conversions.HasCallerInfoStringConversion(TypeWithAnnotations.Type, ref useSiteInfo))
1102diagnostics.Add(ErrorCode.ERR_NoConversionForCallerFilePathParam, node.Name.Location, stringType, TypeWithAnnotations.Type);
1131else if (!compilation.Conversions.HasCallerInfoStringConversion(TypeWithAnnotations.Type, ref useSiteInfo))
1135diagnostics.Add(ErrorCode.ERR_NoConversionForCallerMemberNameParam, node.Name.Location, stringType, TypeWithAnnotations.Type);
1172else if (!compilation.Conversions.HasCallerInfoStringConversion(TypeWithAnnotations.Type, ref useSiteInfo))
1176diagnostics.Add(ErrorCode.ERR_NoConversionForCallerArgumentExpressionParam, node.Name.Location, stringType, TypeWithAnnotations.Type);
1558var elementType = elementTypeWithAnnotations.Type;
1571elementType = elementTypeWithAnnotations.Type;
1630elementType = elementTypeWithAnnotations.Type;
Symbols\Source\SourceMemberContainerSymbol_ImplementationChecks.cs (16)
795if (IsOrContainsErrorType(parameterType.Type))
960if (!IsOrContainsErrorType(overridingMemberType.Type))
962diagnostics.Add(ErrorCode.ERR_CantChangeTypeOnOverride, overridingMemberLocation, overridingMember, overriddenMember, overriddenMemberType.Type);
998if (DeclaringCompilation.Conversions.HasIdentityOrImplicitReferenceConversion(overridingMethod.ReturnTypeWithAnnotations.Type, overriddenMethod.ReturnTypeWithAnnotations.Type, ref discardedUseSiteInfo))
1063if (!IsOrContainsErrorType(overridingMemberType.Type))
1068DeclaringCompilation.Conversions.HasIdentityOrImplicitReferenceConversion(overridingMemberType.Type, overriddenMemberType.Type, ref discardedUseSiteInfo))
1072diagnostics.Add(ErrorCode.ERR_RuntimeDoesNotSupportCovariantPropertiesOfClasses, overridingMemberLocation, overridingMember, overriddenMember, overriddenMemberType.Type);
1084diagnostics.Add(ErrorCode.ERR_CantChangeTypeOnOverride, overridingMemberLocation, overridingMember, overriddenMember, overriddenMemberType.Type);
1204var result = DeclaringCompilation.Conversions.HasIdentityOrImplicitReferenceConversion(overridingReturnType.Type, overriddenReturnType.Type, ref useSiteInfo);
1269overrideReturnType.Type,
1270baseMethod.ReturnTypeWithAnnotations.Type))
1302baseParameterType.Type,
1303overrideParameterType.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;