Binder\Binder_Constraints.cs (9)
414diagnostics.Add(ErrorCode.ERR_BadVisBound, location, containingSymbol, constraintType.Type);
417if (constraintType.Type.HasFileLocalTypes())
430diagnostics.Add(ErrorCode.ERR_FileTypeDisallowedInSignature, location, constraintType.Type, containingSymbol);
458Error(diagnostics, ErrorCode.ERR_DuplicateBound, syntax, type.Type.SetUnknownNullabilityForReferenceTypes(), typeParameter.Name);
472Error(diagnostics, ErrorCode.ERR_ClassBoundNotFirst, syntax, type.Type);
487Error(diagnostics, ErrorCode.ERR_RefValBoundWithClass, syntax, type.Type);
496Error(diagnostics, ErrorCode.ERR_RefValBoundWithClass, syntax, type.Type);
502Error(diagnostics, ErrorCode.ERR_UnmanagedBoundWithClass, syntax, type.Type);
520TypeSymbol type = typeWithAnnotations.Type;
Binder\Binder_Deconstruct.cs (7)
855var type = declTypeWithAnnotations.Type;
893CheckRestrictedTypeInAsyncMethod(this.ContainingMemberOrLambda, declTypeWithAnnotations.Type, diagnostics, typeSyntax);
897localSymbol.Scope == ScopedKind.ScopedValue && !declTypeWithAnnotations.Type.IsErrorTypeOrRefLikeType())
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 (34)
440field.GetFieldType(initializerBinder.FieldsBeingBound).Type, diagnostics);
1198return new BoundRefValueOperator(node, typeWithAnnotations.NullableAnnotation, argument, typeWithAnnotations.Type, hasErrors);
1338TypeSymbol type = typeWithAnnotations.Type;
1366var type = typeWithAnnotations.Type;
1391TypeSymbol type = typeWithAnnotations.Type;
1448TypeSymbol type = typeWithAnnotations.Type;
2328TypeSymbol targetType = targetTypeWithAnnotations.Type;
2490TypeSymbol targetType = targetTypeWithAnnotations.Type;
2643var targetElementType = targetElementTypesWithAnnotations[i].Type;
2670TypeWithAnnotations underlyingTargetTypeWithAnnotations = targetTypeWithAnnotations.Type.GetNullableUnderlyingTypeWithAnnotations();
2671var underlyingConversion = Conversions.ClassifyBuiltInConversion(operand.Type, underlyingTargetTypeWithAnnotations.Type, isChecked: CheckOverflowAtRuntime, ref discardedUseSiteInfo);
2914var type = declType.Type;
2968CheckRestrictedTypeInAsyncMethod(this.ContainingMemberOrLambda, declType.Type, diagnostics, typeSyntax);
2970if (localSymbol.Scope == ScopedKind.ScopedValue && !declType.Type.IsErrorTypeOrRefLikeType())
2975return new BoundLocal(declarationExpression, localSymbol, BoundLocalDeclarationKind.WithExplicitType, constantValueOpt: null, isNullableUnknown: false, type: declType.Type);
3012TypeSymbol fieldType = expressionVariableField.GetFieldType(this.FieldsBeingBound).Type;
3186arguments[arg] = CreateConversion(argument.Syntax, argument, kind, isCast: false, conversionGroupOpt: null, parameterTypeWithAnnotations.Type, diagnostics);
3211arguments[arg] = CreateConversion(argument.Syntax, argument, kind, isCast: false, conversionGroupOpt: null, parameterTypeWithAnnotations.Type, diagnostics);
3223if (!methodResult.Member.IsIndexer() && !argument.HasAnyErrors && parameterTypeWithAnnotations.Type.IsUnsafe())
3246type = ((ArrayTypeSymbol)type.Type).ElementTypeWithAnnotations;
3321var type = (ArrayTypeSymbol)BindArrayType(node.Type, diagnostics, permitDimensions: true, basesBeingResolved: null, disallowRestrictedTypes: true).Type;
3804var arrayType = (ArrayTypeSymbol)BindArrayType(arrayTypeSyntax, diagnostics, permitDimensions: true, basesBeingResolved: null, disallowRestrictedTypes: false).Type;
3808if (!elementType.Type.IsErrorType())
3810hasErrors = hasErrors || CheckManagedAddr(Compilation, elementType.Type, elementTypeSyntax.Location, diagnostics, errorForManaged: true);
3861? new BoundStackAllocArrayCreation(node, elementType.Type, count, initializerOpt: null, type, hasErrors: hasErrors)
3862: BindStackAllocWithInitializer(node, node.StackAllocKeyword, node.Initializer, type, elementType.Type, count, diagnostics, hasErrors);
4432var type = typeWithAnnotations.Type;
6493if (typeArgument.Type.IsPointerOrFunctionPointer() || typeArgument.Type.IsRestrictedType())
6496Error(diagnostics, ErrorCode.ERR_BadTypeArgument, typeArgumentsSyntax[i], typeArgument.Type);
7105resultType = ((FieldSymbol)symbolOpt).GetFieldType(this.FieldsBeingBound).Type;
7532TypeSymbol fieldType = fieldSymbol.GetFieldType(this.FieldsBeingBound).Type;
9207Debug.Assert(returnType.Type is { }); // Expecting System.Void rather than null return type.
9210bool returnsVoid = returnType.Type.IsVoidType();
Binder\Binder_Patterns.cs (6)
852hasErrors |= CheckValidPatternType(typeSyntax, inputType, declType.Type, diagnostics: diagnostics);
887CheckRestrictedTypeInAsyncMethod(this.ContainingMemberOrLambda, declType.Type, diagnostics, typeSyntax ?? (SyntaxNode)designation);
891syntax: designation, localSymbol: localSymbol, localSymbol.IsVar ? BoundLocalDeclarationKind.WithInferredType : BoundLocalDeclarationKind.WithExplicitType, constantValueOpt: null, isNullableUnknown: false, type: declType.Type);
965TypeSymbol declType = declTypeWithAnnotations.Type;
1163TypeSymbol elementType = isError ? CreateErrorType() : elementTypesWithAnnotations[i].Type;
1436TypeSymbol elementType = isError ? CreateErrorType() : elementTypes[i].Type;
Binder\Binder_Statements.cs (16)
238TypeSymbol elementType = GetIteratorElementType().Type;
850Error(diagnostics, ErrorCode.ERR_VarDeclIsStaticClass, typeSyntax, declType.Type);
853if (isConst && !declType.Type.CanBeConst())
855Error(diagnostics, ErrorCode.ERR_BadConstType, typeSyntax, declType.Type);
1030Error(localDiagnostics, ErrorCode.ERR_ImplicitlyTypedVariableAssignedBadValue, declarator, declTypeOpt.Type);
1035if (!declTypeOpt.Type.IsErrorType())
1059initializerOpt = BindPossibleArrayInitializer(value, declTypeOpt.Type, valueKind, diagnostics);
1064declTypeOpt.Type,
1086if (!declTypeOpt.Type.IsPointerType())
1090Error(localDiagnostics, declTypeOpt.Type.IsFunctionPointer() ? ErrorCode.ERR_CannotUseFunctionPointerAsFixedLocal : ErrorCode.ERR_BadFixedInitType, declarator);
1094else if (!IsValidFixedVariableInitializer(declTypeOpt.Type, ref initializerOpt, localDiagnostics))
1100CheckRestrictedTypeInAsyncMethod(this.ContainingMemberOrLambda, declTypeOpt.Type, localDiagnostics, typeSyntax);
1102if (localSymbol.Scope == ScopedKind.ScopedValue && !declTypeOpt.Type.IsErrorTypeOrRefLikeType())
2030Error(diagnostics, ErrorCode.ERR_ExpressionTreeMustHaveDelegate, syntax, ((NamedTypeSymbol)targetType).TypeArgumentsWithAnnotationsNoUseSiteDiagnostics[0].Type);
2482var targetElementType = targetElementTypes[i].Type;
3148type = this.BindType(declaration.Type, diagnostics).Type;
Binder\Binder_Symbols.cs (7)
528else if (LazyMissingNonNullTypesContextDiagnosticInfo.IsNullableReference(typeArgument.Type))
552ReportUseSite(constructedType.Type.OriginalDefinition, diagnostics, syntax);
553var type = (NamedTypeSymbol)constructedType.Type;
596CheckManagedAddr(Compilation, elementType.Type, node.Location, diagnostics);
611if (type.Type.IsTypeParameterDisallowingAnnotationInCSharp8())
636Error(diagnostics, ErrorCode.ERR_ArrayOfStaticClass, node.ElementType, type.Type);
647Error(diagnostics, ErrorCode.ERR_ArrayElementCantBeRefAny, node.ElementType, type.Type);
Binder\ForEachLoopBinder.cs (13)
185var valuePlaceholder = new BoundDeconstructValuePlaceholder(_syntax.Expression, variableSymbol: null, isDiscardExpression: false, inferredType.Type ?? CreateErrorType("var"));
301CheckRestrictedTypeInAsyncMethod(this.ContainingMemberOrLambda, declType.Type, diagnostics, typeSyntax);
303if (local.Scope == ScopedKind.ScopedValue && !declType.Type.IsErrorTypeOrRefLikeType())
353var valuePlaceholder = new BoundDeconstructValuePlaceholder(_syntax.Expression, variableSymbol: null, isDiscardExpression: false, iterationVariableType.Type).MakeCompilerGenerated();
409hasErrors = hasErrors || boundIterationVariableType.HasErrors || iterationVariableType.Type.IsErrorType();
447Conversion elementConversionClassification = this.Conversions.ClassifyConversionFromType(inferredType.Type, iterationVariableType.Type, isChecked: CheckOverflowAtRuntime, ref useSiteInfo, forCast: true);
451Error(diagnostics, ErrorCode.ERR_RefAssignmentMustHaveIdentityConversion, collectionExpr.Syntax, iterationVariableType.Type);
455var elementPlaceholder = new BoundValuePlaceholder(_syntax, inferredType.Type).MakeCompilerGenerated();
463diagnostics.Add(ErrorCode.ERR_AmbigUDConv, foreachKeyword.GetLocation(), originalUserDefinedConversions[0], originalUserDefinedConversions[1], inferredType.Type, iterationVariableType);
467SymbolDistinguisher distinguisher = new SymbolDistinguisher(this.Compilation, inferredType.Type, iterationVariableType.Type);
479BoundExpression 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 (40)
1203HasImplicitConstantExpressionConversion(source, nt.TypeArgumentsWithAnnotationsNoUseSiteDiagnostics[0].Type))
1231var underlyingTupleConversion = GetImplicitTupleLiteralConversion(source, nt.TypeArgumentsWithAnnotationsNoUseSiteDiagnostics[0].Type, ref useSiteInfo);
1262var underlyingTupleConversion = GetExplicitTupleLiteralConversion(source, nt.TypeArgumentsWithAnnotationsNoUseSiteDiagnostics[0].Type, isChecked: isChecked, ref useSiteInfo, forCast);
1413!invokeMethod.ReturnType.Equals(returnType.Type, TypeCompareKind.AllIgnoreOptions))
1527var delegateType = type.TypeArgumentsWithAnnotationsNoUseSiteDiagnostics[0].Type;
1740var type = typeWithAnnotations.Type;
1754ClassifyImplicitConversionFromType(source.Type, destination.Type, ref discardedUseSiteInfo).Kind != ConversionKind.NoConversion;
1814conversions.ClassifyImplicitExtensionMethodThisArgConversion(s, s.Type, d.Type, ref u),
1836return conversions.ClassifyImplicitExtensionMethodThisArgConversion(sourceExpressionOpt: null, s.Type, d.Type, ref u);
2148=> conversions.ClassifyImplicitConversionFromExpression(s, d.Type, ref u),
2166conversions.ClassifyConversionFromExpression(s, d.Type, isChecked: isChecked, ref u, forCast: forCast),
2224return conversions.ClassifyImplicitConversionFromType(s.Type, d.Type, ref u);
2243return conversions.ClassifyConversionFromType(s.Type, d.Type, isChecked: isChecked, ref u, forCast);
2451return HasIdentityOrImplicitReferenceConversion(elementType.Type, argument0.Type, ref useSiteInfo);
2465HasIdentityConversionInternal(source.Type, destination.Type, includeNullability: true))
2470return HasImplicitReferenceConversion(source.Type, destination.Type, ref useSiteInfo);
2958if (HasIdentityConversionInternal(sourceTypeArgument.Type, destinationTypeArgument.Type) &&
2964TypeParameterSymbol typeParameterSymbol = (TypeParameterSymbol)typeParameters[paramIndex].Type;
2977TypeSymbol.Equals(destinationTypeArgument.Type, sourceTypeArgument.Type, TypeCompareKind.AllNullableIgnoreOptions) &&
3192&& (HasIdentityOrImplicitReferenceConversion(sourceType.Type, destinationType.Type, ref useSiteInfo)
3193|| HasImplicitPointerToVoidConversion(sourceType.Type, destinationType.Type)
3194|| HasImplicitPointerConversion(sourceType.Type, destinationType.Type, ref useSiteInfo));
3198&& HasIdentityConversion(sourceType.Type, destinationType.Type);
3449var sourceArg = sourceTypeArguments[i].Type;
3450var destinationArg = destinationTypeArguments[i].Type;
3532if (HasExplicitReferenceConversion(sourceArray.ElementType, ((NamedTypeSymbol)destination).TypeArgumentWithDefinitionUseSiteDiagnostics(0, ref useSiteInfo).Type, ref useSiteInfo))
3552var sourceElement = ((NamedTypeSymbol)source).TypeArgumentWithDefinitionUseSiteDiagnostics(0, ref useSiteInfo).Type;
Binder\Semantics\OverloadResolution\MethodTypeInference.cs (68)
451if (!fixedResultType.Type.IsErrorType())
460var errorTypeName = fixedResultType.Type.Name;
489TypeParameterSymbol typeParameter = (TypeParameterSymbol)type.Type;
512var methodTypeParameter = (TypeParameterSymbol)methodTypeParameterWithAnnotations.Type;
546return typeMap.SubstituteType(delegateOrFunctionPointerType).Type;
586ExactOrBoundsKind kind = GetRefKind(arg).IsManagedReference() || target.Type.IsPointerType() ? ExactOrBoundsKind.Exact : ExactOrBoundsKind.LowerBound;
607if (argument.Kind == BoundKind.UnboundLambda && target.Type.GetDelegateType() is { })
617if (IsReallyAType(argumentType.Type))
623var ordinal = ((TypeParameterSymbol)target.Type).Ordinal;
635if (target.Type.Kind != SymbolKind.NamedType)
641var destination = (NamedTypeSymbol)target.Type;
793if (HasUnfixedParamInOutputType(argument, formalType.Type) && !HasUnfixedParamInInputType(argument, formalType.Type))
806if (formalType.Type.Kind != SymbolKind.NamedType)
812var destination = (NamedTypeSymbol)formalType.Type;
1027var formalParameterType = _formalParameterTypes[iArg].Type;
1269if (MethodGroupReturnTypeInference(binder, expression, target.Type, ref useSiteInfo))
1291var delegateType = target.Type.GetDelegateType();
1313Debug.Assert(inferredReturnType.Type is not FunctionTypeSymbol);
1448var delegateType = target.Type.GetDelegateType();
1501var delegateInvokeMethod = target.Type.GetDelegateType()?.DelegateInvokeMethod();
1584if (!source.Type.IsArray() || !target.Type.IsArray())
1589var arraySource = (ArrayTypeSymbol)source.Type;
1590var arrayTarget = (ArrayTypeSymbol)target.Type;
1630ExactOrBoundsInference(kind, ((NamedTypeSymbol)source.Type).TypeArgumentsWithAnnotationsNoUseSiteDiagnostics[0], ((NamedTypeSymbol)target.Type).TypeArgumentsWithAnnotationsNoUseSiteDiagnostics[0], ref useSiteInfo);
1664if (!source.Type.TryGetElementTypesWithAnnotationsIfTupleType(out sourceTypes) ||
1665!target.Type.TryGetElementTypesWithAnnotationsIfTupleType(out targetTypes) ||
1688var namedSource = source.Type as NamedTypeSymbol;
1694var namedTarget = target.Type as NamedTypeSymbol;
1713ExactInference(((PointerTypeSymbol)source.Type).PointedAtTypeWithAnnotations, ((PointerTypeSymbol)target.Type).PointedAtTypeWithAnnotations, ref useSiteInfo);
1716else if (source.Type is FunctionPointerTypeSymbol { Signature: { ParameterCount: int sourceParameterCount } sourceSignature } &&
1717target.Type is FunctionPointerTypeSymbol { Signature: { ParameterCount: int targetParameterCount } targetSignature } &&
1827if (LowerBoundArrayInference(source.Type, target.Type, ref useSiteInfo))
1864if (LowerBoundConstructedInference(source.Type, target.Type, ref useSiteInfo))
1869if (LowerBoundFunctionPointerTypeInference(source.Type, target.Type, ref useSiteInfo))
1953if (elementSource.Type.IsReferenceType)
2183if (sourceTypeArgument.Type.IsReferenceType && typeParameter.Variance == VarianceKind.Out)
2187else if (sourceTypeArgument.Type.IsReferenceType && typeParameter.Variance == VarianceKind.In)
2290Debug.Assert(source.Type.IsReferenceType || source.Type.IsFunctionPointer());
2307if (UpperBoundFunctionPointerTypeInference(source.Type, target.Type, ref useSiteInfo))
2342if (!target.Type.IsArray())
2346var arrayTarget = (ArrayTypeSymbol)target.Type;
2348var elementSource = GetMatchingElementType(arrayTarget, source.Type, ref useSiteInfo);
2354if (elementSource.Type.IsReferenceType)
2375var source = sourceWithAnnotations.Type;
2376var target = targetWithAnnotations.Type;
2533if (sourceTypeArgument.Type.IsReferenceType && typeParameter.Variance == VarianceKind.Out)
2537else if (sourceTypeArgument.Type.IsReferenceType && typeParameter.Variance == VarianceKind.In)
2627Debug.Assert(best.Type.Type.Equals(withoutNullability.Type, TypeCompareKind.IgnoreDynamicAndTupleNames | TypeCompareKind.IgnoreNullableModifiersForReferenceTypes));
2788functionType = type.Type as FunctionTypeSymbol;
2795return constraintTypes.Any(static t => isExpressionType(t.Type));
2832var source = sourceWithAnnotations.Type;
2833var destination = destinationWithAnnotations.Type;
3055if (!dest.Type.ContainsTypeParameter(pParam))
3180var newBound = TypeWithAnnotations.Create(oldBound.Type, newAnnotation);
3206if (newCandidate.Type.IsDynamic())
3237return obj.Type.GetHashCode();
3244if (x.Type.IsDynamic() ^ y.Type.IsDynamic()) { return false; }
BoundTree\VariablePendingInference.cs (4)
65Binder.CheckRestrictedTypeInAsyncMethod(localSymbol.ContainingSymbol, type.Type, diagnosticsOpt, typeOrDesignationSyntax);
67if (localSymbol.Scope == ScopedKind.ScopedValue && !type.Type.IsErrorTypeOrRefLikeType())
76return new BoundLocal(this.Syntax, localSymbol, BoundLocalDeclarationKind.WithInferredType, constantValueOpt: null, isNullableUnknown: false, type: type.Type, hasErrors: this.HasErrors || inferenceFailed).WithWasConverted();
104type: type.Type,
FlowAnalysis\NullableWalker.cs (85)
115Debug.Assert(TypeSymbol.Equals(RValueType.Type, LValueType.Type, TypeCompareKind.ConsiderEverything));
719if (symbolType.Type.IsValueType || symbolType.Type.IsErrorType())
748var badState = symbolType.Type.IsPossiblyNullableReferenceTypeTypeParameter() && (annotations & FlowAnalysisAnnotations.NotNull) == 0
909SetState(ref this.State, memberSlot, type.Type.IsPossiblyNullableReferenceTypeTypeParameter() ? NullableFlowState.MaybeDefault : NullableFlowState.MaybeNull);
2193type.Type.IsValueType)
2210if (type.Type.IsTypeParameterDisallowingAnnotationInCSharp8() && !(type.Type is TypeParameterSymbol { IsNotNullable: true }))
2236!targetType.Type.Equals(valueType.Type, TypeCompareKind.AllIgnoreOptions))
2474InheritDefaultState(targetType.Type, targetSlot);
2480if (targetType.Type.IsReferenceType ||
2489else if (EmptyStructTypeCache.IsTrackableStructType(targetType.Type))
2491InheritNullableStateOfTrackableStruct(targetType.Type, targetSlot, valueSlot, isDefaultValue: !(valueOpt is null) && IsDefaultValue(valueOpt), skipSlot: targetSlot);
2497target.Type.Equals(assignedValue.Type, TypeCompareKind.AllIgnoreOptions);
2565if (fieldOrPropertyType.Type.IsReferenceType ||
2594else if (EmptyStructTypeCache.IsTrackableStructType(fieldOrPropertyType.Type))
2604InheritNullableStateOfTrackableStruct(fieldOrPropertyType.Type, targetMemberSlot, valueMemberSlot, isDefaultValue: isDefaultValue, skipSlot);
2611return _variables[slot].Symbol.GetTypeOrReturnType().Type;
2652InheritDefaultState(symbol.GetTypeOrReturnType().Type, slot);
2753if (EmptyStructTypeCache.IsTrackableStructType(parameterType.Type))
2756parameterType.Type,
2789return TypeWithState.Create(parameterType.Type, NullableFlowState.MaybeDefault);
2794return TypeWithState.Create(parameterType.Type, NullableFlowState.NotNull);
2818returnType.Type.SpecialType == SpecialType.System_Boolean)
2925type = ((NamedTypeSymbol)returnType.Type).TypeArgumentsWithAnnotationsNoUseSiteDiagnostics.Single();
2952if (!node.Type.Equals(type.Type, TypeCompareKind.ConsiderEverything | TypeCompareKind.IgnoreNullableModifiersForReferenceTypes | TypeCompareKind.IgnoreDynamicAndTupleNames))
2957Debug.Assert(node.Type.IsErrorType() || type.Type.IsErrorType());
3199VisitObjectCreationInitializer(resultSlot, resultType.Type, withExpr.InitializerExpression, delayCompletionForType: false);
3252InheritDefaultState(GetDeclaredLocalResult(local).Type, slot);
3310Debug.Assert(type.Type.IsErrorType());
3376return AnonymousTypeManager.GetAnonymousTypeFieldTypes(type).Any(static t => canIgnoreAnyType(t.Type));
3523Debug.Assert(TypeSymbol.Equals(resultTypeWithAnnotations.Type, node.Type, TypeCompareKind.IgnoreNullableModifiersForReferenceTypes));
3526var type = resultTypeWithAnnotations.Type;
3602if (AreNullableAndUnderlyingTypes(type, parameterType.Type, out TypeWithAnnotations underlyingType))
3796Debug.Assert(TypeSymbol.Equals(objectInitializer.Type, symbol.GetTypeOrReturnType().Type, TypeCompareKind.IgnoreNullableModifiersForReferenceTypes));
3813Action<int, TypeSymbol>? nestedCompletion = VisitObjectCreationInitializer(slot, symbol.GetTypeOrReturnType().Type, initializer, delayCompletionForType);
3846nestedCompletion?.Invoke(slot, symbol.GetTypeOrReturnType().Type);
3928Debug.Assert(TypeSymbol.Equals(containingType, receiverResult.LValueType.Type, TypeCompareKind.IgnoreNullableModifiersForReferenceTypes));
3986Debug.Assert(TypeSymbol.Equals(containingType, receiverResult.LValueType.Type, TypeCompareKind.IgnoreNullableModifiersForReferenceTypes));
4231inferredType = TypeWithState.Create(inferredType.Type, elementState).ToTypeWithAnnotations(compilation);
4674if (isLifted && targetTypeWithNullability.Type.IsNonNullableValueType())
5041MarkDependentSlotsNotNull(childSlot, member.GetTypeOrReturnType().Type, ref state, depth - 1);
5115TypeWithState resultType = TypeWithState.Create(targetType.Type, rightResult.State);
5375TypeSymbol accessType = accessTypeWithAnnotations.Type;
5544var typeWithState = TypeWithState.Create(resultTypeWithAnnotations.Type, resultState);
5557return TypeWithState.Create(resultTypeWithAnnotations.Type, resultState);
5664new BoundExpressionWithNullability(expr.Syntax, expr, type.NullableAnnotation, type.Type);
6574conversion = GenerateConversion(_conversions, argumentNoConversion, argumentResultType, parameterType.Type, fromExplicitCast: false, extensionMethodThisArgument: false, isChecked: conversionOpt?.Checked ?? false);
6578ReportNullabilityMismatchInArgument(argumentNoConversion.Syntax, argumentResultType, parameter, parameterType.Type, forOutput: false);
6610if (IsNullabilityMismatch(lvalueResultType.Type, parameterType.Type))
6613ReportNullabilityMismatchInRefArgument(argumentNoConversion, argumentType: lvalueResultType.Type, parameter, parameterType.Type);
6717parameterWithState = TypeWithState.Create(parameterType.Type, adjustedState);
6774if (!_conversions.HasIdentityOrImplicitReferenceConversion(parameterType.Type, lValueType.Type, ref discardedUseSiteInfo))
6776ReportNullabilityMismatchInArgument(argument.Syntax, lValueType.Type, parameter, parameterType.Type, forOutput: true);
7007type = ((ArrayTypeSymbol)type.Type).ElementTypeWithAnnotations;
7162return new BoundExpressionWithNullability(argument.Syntax, argument, argumentType.NullableAnnotation, argumentType.Type);
7539if (typeArg.Type.Equals(underlyingTypeOpt, TypeCompareKind.AllIgnoreOptions))
7940operandType = completion(targetTypeWithNullability.Type.GetNullableUnderlyingTypeWithAnnotations());
7970TypeSymbol targetType = targetTypeWithNullability.Type;
8259if (targetType.Type?.IsTypeParameterDisallowingAnnotationInCSharp8() == true)
8268dependsOnTypeParameter(typeParameter1, (TypeParameterSymbol)targetType.Type, NullableAnnotation.NotAnnotated, out var annotation))
8275if (targetType.Type?.IsTypeParameterDisallowingAnnotationInCSharp8() == false)
8299targetType.Type is TypeParameterSymbol typeParameter2)
8349if (constraintType.Type is TypeParameterSymbol constraintTypeParameter &&
8452TypeSymbol targetType = targetTypeWithNullability.Type;
8619bool typeNeedsLifting = returnType.Type.IsNonNullableValueType();
8620TypeSymbol type = typeNeedsLifting ? MakeNullableOf(returnType) : returnType.Type;
8664var conversion = _conversions.ClassifyStandardConversion(operandType.Type, targetType.Type, ref discardedUseSiteInfo);
8669ReportNullabilityMismatchInArgument(diagnosticLocation, operandType.Type, parameterOpt, targetType.Type, forOutput: false);
8673ReportNullabilityMismatchInAssignment(diagnosticLocation, operandType.Type, targetType.Type);
8754Debug.Assert(TypeSymbol.Equals(resultTypeWithAnnotations.Type, node.Type, TypeCompareKind.IgnoreNullableModifiersForReferenceTypes));
8755var delegateType = (NamedTypeSymbol)resultTypeWithAnnotations.Type;
8931arguments.Add(new BoundExpressionWithNullability(syntax, new BoundParameter(syntax, parameter), parameterType.NullableAnnotation, parameterType.Type));
9096SetResult(node, TypeWithState.Create(leftLValueType.Type, rightState.State), leftLValueType);
9430AreNullableAndUnderlyingTypes(lvalueType.Type, operandType.Type, out TypeWithAnnotations underlyingType))
9435var valueBeforeNullableWrapping = TypeWithState.Create(underlyingType.Type, NullableFlowState.NotNull);
9436TrackNullableStateOfNullableValue(targetSlot, lvalueType.Type, rightPart, valueBeforeNullableWrapping, valueSlot);
9734if (argumentType.Type is { } argType && IsNullabilityMismatch(paramType.Type, argType))
9736ReportNullabilityMismatchInArgument(argument.Syntax, argType, parameter, paramType.Type, forOutput: false);
10208conversion = _conversions.ClassifyImplicitConversionFromType(sourceType.Type, destinationType.Type, ref discardedUseSiteInfo);
FlowAnalysis\NullableWalker_Patterns.cs (14)
414var output = new BoundDagTemp(e.Syntax, parameterType.Type, e, i);
417addToTempMap(output, outputSlot, parameterType.Type);
452var output = new BoundDagTemp(e.Syntax, type.Type, e);
488addToTempMap(output, outputSlot, type.Type);
496var output = new BoundDagTemp(e.Syntax, type.Type, e);
503addToTempMap(output, outputSlot, type.Type);
521var output = new BoundDagTemp(e.Syntax, type.Type, e);
525addToTempMap(output, outputSlot, type.Type);
533var output = new BoundDagTemp(e.Syntax, type.Type, e);
536addToTempMap(output, outputSlot, type.Type);
648inferredType = TypeWithAnnotations.Create(inferredType.Type, existingType.NullableAnnotation.Join(inferredType.NullableAnnotation));
800var output = new BoundDagTemp(e.Syntax, type.Type, e, index: index);
803addToTempMap(output, outputSlot, type.Type);
975TypeWithState resultType = TypeWithState.Create(inferredTypeWithAnnotations.Type, inferredState);
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 (48)
132Debug.Assert(!constraintType.Type.ContainsDynamic());
141var constraintTypeParameter = (TypeParameterSymbol)constraintType.Type;
196if (constraintType.Type.IsInterfaceType())
198AddInterface(interfacesBuilder, (NamedTypeSymbol)constraintType.Type);
204constraintEffectiveBase = (NamedTypeSymbol)constraintType.Type;
205constraintDeducedBase = constraintType.Type;
212var underlyingType = constraintType.Type.GetNullableUnderlyingType();
230constraintDeducedBase = constraintType.Type;
236constraintDeducedBase = constraintType.Type;
242constraintDeducedBase = constraintType.Type;
246constraintEffectiveBase = (NamedTypeSymbol)constraintType.Type;
247constraintDeducedBase = constraintType.Type;
881if (typeArgument.Type.IsPointerOrFunctionPointer() || typeArgument.IsRestrictedType() || typeArgument.IsVoidType())
884diagnosticsBuilder.Add(new TypeParameterDiagnosticInfo(typeParameter, new UseSiteInfo<AssemblySymbol>(new CSDiagnosticInfo(ErrorCode.ERR_BadTypeArgument, typeArgument.Type))));
891diagnosticsBuilder.Add(new TypeParameterDiagnosticInfo(typeParameter, new UseSiteInfo<AssemblySymbol>(new CSDiagnosticInfo(ErrorCode.ERR_GenericArgIsStaticClass, typeArgument.Type))));
897if (!typeArgument.Type.IsReferenceType)
900diagnosticsBuilder.Add(new TypeParameterDiagnosticInfo(typeParameter, new UseSiteInfo<AssemblySymbol>(new CSDiagnosticInfo(ErrorCode.ERR_RefConstraintNotSatisfied, containingSymbol.ConstructedFrom(), typeParameter, typeArgument.Type))));
910var managedKind = typeArgument.Type.GetManagedKind(ref useSiteInfo);
913if (managedKind == ManagedKind.Managed || !typeArgument.Type.IsNonNullableValueType())
916diagnosticsBuilder.Add(new TypeParameterDiagnosticInfo(typeParameter, new UseSiteInfo<AssemblySymbol>(new CSDiagnosticInfo(ErrorCode.ERR_UnmanagedConstraintNotSatisfied, containingSymbol.ConstructedFrom(), typeParameter, typeArgument.Type))));
937if (typeParameter.HasValueTypeConstraint && !typeArgument.Type.IsNonNullableValueType())
940diagnosticsBuilder.Add(new TypeParameterDiagnosticInfo(typeParameter, new UseSiteInfo<AssemblySymbol>(new CSDiagnosticInfo(ErrorCode.ERR_ValConstraintNotSatisfied, containingSymbol.ConstructedFrom(), typeParameter, typeArgument.Type))));
966if (typeArgument.Type.IsErrorType())
988if (typeArgument.Type is NamedTypeSymbol { IsInterface: true } iface && SelfOrBaseHasStaticAbstractMember(iface, ref useSiteInfo, out Symbol member))
1017var error = SatisfiesConstructorConstraint(typeArgument.Type);
1025diagnosticsBuilder.Add(new TypeParameterDiagnosticInfo(typeParameter, new UseSiteInfo<AssemblySymbol>(new CSDiagnosticInfo(ErrorCode.ERR_NewConstraintNotSatisfied, containingSymbol.ConstructedFrom(), typeParameter, typeArgument.Type))));
1029diagnosticsBuilder.Add(new TypeParameterDiagnosticInfo(typeParameter, new UseSiteInfo<AssemblySymbol>(new CSDiagnosticInfo(ErrorCode.ERR_NewConstraintCannotHaveRequiredMembers, containingSymbol.ConstructedFrom(), typeParameter, typeArgument.Type))));
1046if (typeParameter.HasNotNullConstraint && typeArgument.GetValueNullableAnnotation().IsAnnotated() && !typeArgument.Type.IsNonNullableValueType())
1086if (typeArgument.Type.IsReferenceType)
1092errorCode = constraintType.Type.IsInterfaceType() ? ErrorCode.ERR_GenericConstraintNotSatisfiedNullableInterface : ErrorCode.ERR_GenericConstraintNotSatisfiedNullableEnum;
1106if (constraintType.Type.Equals(typeArgument.Type, TypeCompareKind.AllIgnoreOptions))
1108constraintTypeErrorArgument = constraintType.Type;
1109typeArgumentErrorArgument = typeArgument.Type;
1113SymbolDistinguisher distinguisher = new SymbolDistinguisher(args.CurrentCompilation, constraintType.Type, typeArgument.Type);
1123var type = typeWithAnnotations.Type;
1166var type = typeWithAnnotations.Type;
1245if (constraintType.Type.IsErrorType())
1256if (conversions.HasIdentityOrImplicitReferenceConversion(typeArgument.Type, constraintType.Type, ref useSiteInfo))
1263if (typeArgument.Type.IsValueType &&
1264conversions.HasBoxingConversion(typeArgument.Type.IsNullableType() ? ((NamedTypeSymbol)typeArgument.Type).ConstructedFrom : typeArgument.Type,
1265constraintType.Type, ref useSiteInfo))
1272var typeParameter = (TypeParameterSymbol)typeArgument.Type;
1276if (conversions.HasImplicitTypeParameterConversion(typeParameter, constraintType.Type, ref useSiteInfo))
Symbols\Source\SourceComplexParameterSymbol.cs (10)
396if (parameterType.Type.IsNullableType())
398convertedExpression = binder.GenerateConversionForAssignment(parameterType.Type.GetNullableUnderlyingType(),
1059else if (!compilation.Conversions.HasCallerLineNumberConversion(TypeWithAnnotations.Type, ref useSiteInfo))
1063diagnostics.Add(ErrorCode.ERR_NoConversionForCallerLineNumberParam, node.Name.Location, intType, TypeWithAnnotations.Type);
1087else if (!compilation.Conversions.HasCallerInfoStringConversion(TypeWithAnnotations.Type, ref useSiteInfo))
1091diagnostics.Add(ErrorCode.ERR_NoConversionForCallerFilePathParam, node.Name.Location, stringType, TypeWithAnnotations.Type);
1120else if (!compilation.Conversions.HasCallerInfoStringConversion(TypeWithAnnotations.Type, ref useSiteInfo))
1124diagnostics.Add(ErrorCode.ERR_NoConversionForCallerMemberNameParam, node.Name.Location, stringType, TypeWithAnnotations.Type);
1161else if (!compilation.Conversions.HasCallerInfoStringConversion(TypeWithAnnotations.Type, ref useSiteInfo))
1165diagnostics.Add(ErrorCode.ERR_NoConversionForCallerArgumentExpressionParam, node.Name.Location, stringType, TypeWithAnnotations.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))
1065if (!IsOrContainsErrorType(overridingMemberType.Type))
1070DeclaringCompilation.Conversions.HasIdentityOrImplicitReferenceConversion(overridingMemberType.Type, overriddenMemberType.Type, ref discardedUseSiteInfo))
1074diagnostics.Add(ErrorCode.ERR_RuntimeDoesNotSupportCovariantPropertiesOfClasses, overridingMemberLocation, overridingMember, overriddenMember, overriddenMemberType.Type);
1086diagnostics.Add(ErrorCode.ERR_CantChangeTypeOnOverride, overridingMemberLocation, overridingMember, overriddenMember, overriddenMemberType.Type);
1205var result = DeclaringCompilation.Conversions.HasIdentityOrImplicitReferenceConversion(overridingReturnType.Type, overriddenReturnType.Type, ref useSiteInfo);
1270overrideReturnType.Type,
1271baseMethod.ReturnTypeWithAnnotations.Type))
1303baseParameterType.Type,
1304overrideParameterType.Type))
Symbols\TypeWithAnnotations.cs (48)
60public override string ToString() => Type.ToString();
107if (NullableAnnotation.IsAnnotated() || (Type.IsValueType && Type.IsNullableType()))
112return Create(Type, NullableAnnotation.Annotated, CustomModifiers);
117if (NullableAnnotation.IsNotAnnotated() || (Type.IsValueType && !Type.IsNullableType()))
122return Create(Type, NullableAnnotation.NotAnnotated, CustomModifiers);
133if (Type?.IsPossiblyNullableReferenceTypeTypeParameter() == true)
138if (Type.IsNullableTypeOrTypeParameter())
157return Type.IsNullableTypeOrTypeParameter();
190var typeSymbol = this.Type;
235TypeSymbol typeSymbol = other.Type;
237TypeSymbol type = Type.MergeEquivalentTypes(typeSymbol, variance);
255public bool IsNullableType() => Type.IsNullableType();
258/// The list of custom modifiers, if any, associated with the <see cref="Type"/>.
262public TypeKind TypeKind => Type.TypeKind;
264public Cci.PrimitiveTypeCode PrimitiveTypeCode => Type.PrimitiveTypeCode;
293var str = !HasType ? "<null>" : Type.ToDisplayString(format);
298(!HasType || (!IsNullableType() && !Type.IsValueType)))
304(!HasType || (!Type.IsValueType && !Type.IsTypeParameterDisallowingAnnotationInCSharp8())))
366TypeSymbol type = Type;
397return obj.Type.GetHashCode();
415return Type.GetUnificationUseSiteDiagnosticRecursive(ref result, owner, ref checkedTypes) ||
434TypeSymbol typeSymbol = this.Type;
443if (typeSymbol.Equals(newTypeWithModifiers.Type, TypeCompareKind.ConsiderEverything) &&
454return Create(newTypeWithModifiers.Type, NullableAnnotation, newCustomModifiers);
467if (newTypeWithModifiers.Type is PlaceholderTypeArgumentSymbol)
473Debug.Assert(newTypeWithModifiers.Type is not IndexedTypeParameterSymbol || newTypeWithModifiers.NullableAnnotation == NullableAnnotation.Ignored);
506newTypeWithModifiers.Type,
516return Type.Equals(other.Type, comparison);
521binder.ReportDiagnosticsIfObsolete(diagnostics, Type, syntax, hasBaseReceiver: false);
568typeWithAnnotationsPredicate: (t, a, b) => t.NullableAnnotation != NullableAnnotation.Oblivious && !t.Type.IsErrorType() && !t.Type.IsValueType,
601var type = typeWithAnnotations.Type;
637TypeSymbol oldTypeSymbol = Type;
698var typeSymbol = Type;
709var typeSymbol = Type;
746return Type.GetHashCode();
782return TypeWithState.Create(Type, getFlowState(Type, NullableAnnotation));
950TryForceResolve(asValueType: _underlying.Type.IsValueType);
956internal override TypeSymbol GetNullableUnderlyingTypeOrSelf(TypeSymbol typeSymbol) => _underlying.Type;
1010if (!_underlying.Type.IsValueType)
1027if (newUnderlying.Type.Equals(this._underlying.Type, TypeCompareKind.ConsiderEverything) &&
1069_underlying.Type;
Microsoft.CodeAnalysis.CSharp.ExpressionEvaluator.ExpressionCompiler.UnitTests (3)