Binder\Binder_Await.cs (15)
32var placeholder = new BoundAwaitableValuePlaceholder(expression.Syntax, expression.Type);
87var type = expression.Type;
289Debug.Assert(TypeSymbol.Equals(expression.Type, getAwaiterArgument.Type, TypeCompareKind.ConsiderEverything));
325TypeSymbol awaiterType = getAwaiter.Type!;
326return GetIsCompletedProperty(awaiterType, node, expression.Type!, diagnostics, out isCompleted)
328&& GetGetResultMethod(getAwaiter, node, expression.Type!, diagnostics, out getResult, out getAwaiterGetResultCall)
353if (expression.Type is not NamedTypeSymbol { Arity: 0 or 1 } exprType)
380placeholder = new BoundAwaitableValuePlaceholder(expression.Syntax, expression.Type);
571if (expression.Type is null)
593RoslynDebug.Assert(expression.Type is object);
594if (expression.Type.IsVoidType())
610Error(diagnostics, ErrorCode.ERR_BadAwaitArg, node, expression.Type);
623Error(diagnostics, ErrorCode.ERR_BadAwaitArg, node, expression.Type);
714var awaiterType = awaiterExpression.Type;
Binder\Binder_Conversions.cs (38)
161RoslynDebug.Assert(source.Type is object);
165if (!isCast && source.Type.Equals(destination, TypeCompareKind.IgnoreNullableModifiersForReferenceTypes))
255TypeSymbol? type = source.Type;
300Debug.Assert(source.Type is null);
334source.Type is { } sourceType &&
383switch (source.Type?.IsNullableType())
388new BoundValuePlaceholder(source.Syntax, source.Type.GetNullableUnderlyingType()),
415else if (source.Type?.IsNullableType() == true)
419new BoundValuePlaceholder(source.Syntax, source.Type.GetNullableUnderlyingType()),
437if (source.Type?.TryGetElementTypesWithAnnotationsIfTupleType(out sourceTypes) == true &&
523Debug.Assert(source.Type is { });
525FieldSymbol? elementField = source.Type.TryGetInlineArrayElementField();
558CheckInlineArrayTypeIsSupported(syntax, source.Type, elementField.Type, diagnostics);
562Debug.Assert(source.Type is not null);
571if (source.Type is ArrayTypeSymbol)
582if (source.Type.IsSpan())
586TryFindImplicitOperatorFromSpan(source.Type.OriginalDefinition, destination.OriginalDefinition),
587source.Type.OriginalDefinition,
594if (source.Type.IsSpan() || source.Type.IsReadOnlySpan())
597if (NeedsSpanCastUp(source.Type, destination))
602TypeSymbol sourceForCastUp = source.Type.IsSpan()
604: source.Type.OriginalDefinition;
615.Construct([((NamedTypeSymbol)source.Type).TypeArgumentsWithAnnotationsNoUseSiteDiagnostics[0]])
621if (source.Type.IsStringType())
799unconvertedSource.Type,
1955Debug.Assert(methodGroup.ReceiverOpt.Type is not null);
2025diagnostics.Add(ErrorCode.ERR_CollectionExpressionMissingAdd, syntax, methodGroup.ReceiverOpt.Type);
2090TypeSymbol? receiverType = methodGroup.ReceiverOpt.Type;
2495Debug.Assert(targetTyped || destination.IsErrorType() || destination.Equals(source.Type, TypeCompareKind.ConsiderEverything));
2514source.Syntax, source.Type, targetTyped, source.Expression, newSwitchArms, source.ReachabilityDecisionDag,
2600Conversion toParameterTypeConversion = Conversions.ClassifyStandardConversion(convertedOperand.Type, conversionParameterType, ref useSiteInfo);
2753Debug.Assert(source.Type?.IsDynamic() != true);
3388RoslynDebug.Assert(receiverOpt.Type is object);
3390diagnostics.Add(ErrorCode.ERR_QueryNoProvider, node.Location, receiverOpt.Type, memberSymbol.Name);
3408RoslynDebug.Assert(receiverOpt.Type is object);
3409diagnostics.Add(ErrorCode.ERR_BadAwaitArg, node.Location, receiverOpt.Type);
3544(Conversions.ConvertExtensionMethodThisArg(GetReceiverParameter(method)!.Type, receiverOpt!.Type, ref useSiteInfo, isMethodGroupConversion: true).Exists && useSiteInfo.Diagnostics.IsNullOrEmpty()));
Binder\Binder_Deconstruct.cs (20)
122if ((object?)boundRHS.Type == null || boundRHS.Type.IsErrorType())
128var type = boundRHS.Type ?? voidType;
143boundRHS.Type,
158Debug.Assert(hasErrors || lhsTuple.Type is object);
159TypeSymbol returnType = hasErrors ? CreateErrorType() : lhsTuple.Type!;
227else if ((object?)boundRHS.Type == null)
323Debug.Assert(single.Type is not null);
325nestedConversion = this.Conversions.ClassifyConversionFromType(tupleOrDeconstructedTypes[i], single.Type, isChecked: CheckOverflowAtRuntime, ref useSiteInfo);
331GenerateImplicitConversionError(diagnostics, Compilation, single.Syntax, nestedConversion, tupleOrDeconstructedTypes[i], single.Type);
338nestedConversion, isCast: false, conversionGroupOpt: null, InConversionGroupFlags.Unspecified, single.Type, diagnostics)));
359if ((object?)pending.Type != null)
423Debug.Assert((object?)variables[i].Single!.Type != null);
483TypeSymbol? mergedType = element.Type;
504if ((object?)variable.Single.Type != null)
507mergedType = variable.Single.Type;
571typesWithAnnotationsBuilder.Add(TypeWithAnnotations.Create(value.Type));
624if (receiver.Type?.IsDynamic() ?? false)
720if (receiver.Type?.IsErrorType() == false)
722Error(diagnostics, ErrorCode.ERR_MissingDeconstruct, rightSyntax, receiver.Type, numParameters);
Binder\Binder_Expressions.cs (115)
223TypeSymbol resultType = expr.Type;
321var commonType = expr.Type;
401case BoundStackAllocArrayCreation { Type: null } boundStackAlloc:
602TypeSymbol exprType = expr.Type;
1022subExpressions.SelectAsArray(e => TypeWithAnnotations.Create(e.Type)),
1079if (boundArgument.Type?.SpecialType == SpecialType.System_Void)
1089var elementTypeWithAnnotations = TypeWithAnnotations.Create(boundArgument.Type);
1288if ((object)argument.Type != null && argument.Type.IsRestrictedType())
1291Error(diagnostics, ErrorCode.ERR_MethodArgCantBeRefAny, node, argument.Type);
1746type: expression.Type,
2669(object)operand.Type != null &&
2670!operand.Type.IsNullableType() &&
2671!TypeSymbol.Equals(targetType.GetNullableUnderlyingType(), operand.Type, TypeCompareKind.ConsiderEverything2))
2692if ((object)boundOperand.Type != null && boundOperand.Type.IsNullableType())
2771if (left?.Type.IsNullableType() == true || right?.Type.IsNullableType() == true)
2799if (boundOperand.Type?.IsNullableType() == true)
2891SymbolDistinguisher distinguisher1 = new SymbolDistinguisher(this.Compilation, operand.Type, targetType);
2940case BoundKind.UnconvertedConditionalOperator when operand.Type is null:
2941case BoundKind.UnconvertedSwitchExpression when operand.Type is null:
2965Debug.Assert((object)operand.Type != null);
2966SymbolDistinguisher distinguisher = new SymbolDistinguisher(this.Compilation, operand.Type, targetType);
3007Debug.Assert((object)operand.Type != null && !operand.Type.IsNullableType());
3013var underlyingConversion = Conversions.ClassifyBuiltInConversion(operand.Type, underlyingTargetTypeWithAnnotations.Type, isChecked: CheckOverflowAtRuntime, ref discardedUseSiteInfo);
3869Debug.Assert(receiver!.Type is not null);
3871placeholderType = receiver.Type;
4317if ((object)boundExpression.Type == null || !boundExpression.Type.IsErrorType())
4401Debug.Assert(init.Type.IsErrorType());
4823if (constantValue == null || constantValue.IsBad || expression.Type.SpecialType != SpecialType.System_Int32)
4846var type = expression.Type.SpecialType;
5422Debug.Assert(expression.Type is { });
5424var expressionPlaceholder = new BoundCollectionExpressionSpreadExpressionPlaceholder(syntax.Expression, expression.Type);
5436_ = expression.Type.HasInlineArrayAttribute(out int length);
5478if (arg.Type is { TypeKind: TypeKind.Dynamic })
5627else if ((object)argument.Type == null)
5639else if (argument.Type.TypeKind == TypeKind.Delegate)
5641var sourceDelegate = (NamedTypeSymbol)argument.Type;
5645if (ReportDelegateInvokeUseSiteDiagnostic(diagnostics, argument.Type, node: node))
5906Debug.Assert((object)boundLeft.Type != null);
5915type: boundLeft.Type,
6200type: boundMember.Type,
7763leftType = BindRangeVariable(left, (RangeVariableSymbol)leftSymbol, BindingDiagnosticBag.Discarded).Type;
7778if (TypeSymbol.Equals(boundType.Type, leftType, TypeCompareKind.AllIgnoreOptions))
7790Debug.Assert(leftType.Equals(boundValue.Type, TypeCompareKind.ConsiderEverything));
7808TypeSymbol.Equals(BindNamespaceOrType(id, BindingDiagnosticBag.Discarded).Type, type, TypeCompareKind.AllIgnoreOptions);
7918TypeSymbol leftType = boundLeft.Type;
7956leftType = boundLeft.Type;
8200Error(diagnostics, ErrorCode.WRN_DotOnDefault, node, boundLeft.Type);
8327var leftType = boundLeft.Type;
8462if ((object)boundLeft.Type == null)
8471Error(diagnostics, ErrorCode.ERR_NoSuchMember, name, boundLeft.Type, plainName);
8473else if (WouldUsingSystemFindExtension(boundLeft.Type, plainName))
8475Error(diagnostics, ErrorCode.ERR_NoSuchMemberOrExtensionNeedUsing, name, boundLeft.Type, plainName, "System");
8477else if (boundLeft.Kind == BoundKind.AwaitableValuePlaceholder && boundLeft.Type.IsIAsyncEnumerableType(Compilation))
8479Error(diagnostics, ErrorCode.ERR_NoAwaitOnAsyncEnumerable, name, boundLeft.Type, plainName);
8483Error(diagnostics, ErrorCode.ERR_NoSuchMemberOrExtension, name, boundLeft.Type, plainName);
8773Debug.Assert(left.Type is not null);
8774Debug.Assert(!left.Type.IsDynamic());
8868Debug.Assert(left.Type is not null);
9025errorInfo = new CSDiagnosticInfo(ErrorCode.ERR_ExtensionResolutionFailed, left.Type, memberName);
9059TypeSymbol? receiverType = left.Type;
9149if (arguments.Arguments is not [{ Type: TypeSymbol argType }])
9193Debug.Assert(left.Type is not null);
9194Debug.Assert(!left.Type.IsDynamic());
9195Debug.Assert(!left.Type.IsArray());
9196Debug.Assert(left.Type.SpecialType != SpecialType.System_String);
9246Debug.Assert(receiver.Type is not null);
9290Debug.Assert(left.Type is not null);
9291Debug.Assert(!left.Type.IsDynamic());
9292Debug.Assert(!left.Type.IsArray());
9293Debug.Assert(left.Type.SpecialType != SpecialType.System_String);
9330Debug.Assert(receiver.Type is not null);
9332var receiverPlaceholder = new BoundImplicitIndexerReceiverPlaceholder(receiver.Syntax, receiver.IsEquivalentToThisReference, receiver, receiver.Type).MakeCompilerGenerated();
9426Debug.Assert(receiver.Type is not null);
9837TypeSymbol receiverType = receiver.Type;
10033if (receiverOpt is { Type: TypeParameterSymbol { AllowsRefLikeType: true } } &&
10075bool isUsableAsField = eventSymbol.HasAssociatedField && this.IsAccessible(eventSymbol.AssociatedField, ref useSiteInfo, (receiver != null) ? receiver.Type : null);
10297if (!result.HasErrors && receiver.Type?.IsPointerOrFunctionPointer() == true)
10299Debug.Assert(receiver.Type?.IsFunctionPointer() != true, "There should have been an error reported for indexing into a function pointer.");
10333if ((object)expr.Type == null)
10354expr.Type.HasInlineArrayAttribute(out int length) && expr.Type.TryGetPossiblyUnsupportedByLanguageInlineArrayElementField() is FieldSymbol elementField)
10366Debug.Assert(expr.Type.TryGetInlineArrayElementField() is not null);
10386{ Code: (int)ErrorCode.ERR_BadIndexLHS, Arguments: [TypeSymbol type] } && type.Equals(expr.Type, TypeCompareKind.ConsiderEverything))
10513CheckInlineArrayTypeIsSupported(node, expr.Type, elementField.Type, diagnostics);
10564if (IsWellKnownSystemIndex(convertedIndex.Type, compilation))
10612Debug.Assert((object)expr.Type != null);
10615var exprType = expr.Type;
10658var arrayType = (ArrayTypeSymbol)expr.Type;
10705var receiverPlaceholder = new BoundImplicitIndexerReceiverPlaceholder(expr.Syntax, isEquivalentToThisReference: expr.IsEquivalentToThisReference, expr, expr.Type) { WasCompilerGenerated = true };
10869Debug.Assert(expr.Type.IsPointerType());
10870PointerTypeSymbol pointerType = (PointerTypeSymbol)expr.Type;
10917Debug.Assert((object?)expr.Type != null);
10923this.LookupMembersWithFallback(lookupResult, expr.Type, WellKnownMemberNames.Indexer, arity: 0, useSiteInfo: ref useSiteInfo, options: lookupOptions);
10956else if (expr.Type.SpecialType != SpecialType.System_String)
11261Debug.Assert(receiver.Type is not null);
11274var receiverPlaceholder = new BoundImplicitIndexerReceiverPlaceholder(receiver.Syntax, isEquivalentToThisReference: receiver.IsEquivalentToThisReference, receiver, receiver.Type) { WasCompilerGenerated = true };
11302Debug.Assert(indexerOrSliceAccess.Type is not null);
11312indexerOrSliceAccess.Type);
11496Debug.Assert(receiverPlaceholder.Type is not null);
11499Debug.Assert(receiverPlaceholder.Type is not null);
11500if (tryLookupLengthOrCount(syntax, receiverPlaceholder.Type, lookupResult, binder: this, out var lengthOrCountProperty, ref useSiteInfo, diagnostics))
11864Debug.Assert(node.ReceiverOpt!.Type is not null); // extensions are only considered on member access
11895var substituted = (MethodSymbol?)extensionMember.GetReducedAndFilteredSymbol(typeArguments, receiver.Type, Compilation, checkFullyInferred: true);
11901else if (m.ReduceExtensionMethod(receiver.Type, Compilation) is { } reduced)
12080Debug.Assert(node.ReceiverOpt!.Type is not null); // extensions are only considered on member access
12106var substituted = (MethodSymbol?)extensionMember.GetReducedAndFilteredSymbol(typeArguments, receiver.Type, Compilation, checkFullyInferred: true);
12355var receiverType = receiver.Type;
12364var accessType = access.Type;
12503var receiverType = receiver.Type;
12534var receiverType = receiver.Type;
Binder\Binder_InterpolatedString.cs (17)
219Debug.Assert(unconvertedInterpolatedString.Type?.SpecialType == SpecialType.System_String);
245Debug.Assert(unconvertedInterpolatedString.Parts.All(static part => part.Type is null or { SpecialType: SpecialType.System_String }));
259if (unconvertedInterpolatedString.Type.IsErrorType() || haveErrors || canLowerToStringConcatenation(parts))
264return BindUnconvertedInterpolatedExpressionToFactory(unconvertedInterpolatedString, parts, (NamedTypeSymbol)unconvertedInterpolatedString.Type, factoryMethod: "Format", unconvertedInterpolatedString.Type, diagnostics);
272unconvertedInterpolatedString.Type,
304fillin.Value.Type?.SpecialType != SpecialType.System_String ||
367unconvertedSource.Type,
397if (value.Type?.TypeKind == TypeKind.Dynamic)
433&& unconvertedInterpolatedString.Parts.All(p => p is not BoundStringInsert { Value.Type.TypeKind: TypeKind.Dynamic });
436=> parts.All(p => p is BoundLiteral or BoundStringInsert { Value.Type.SpecialType: SpecialType.System_String, Alignment: null, Format: null });
536expression.Type,
597unconvertedInterpolatedString.Type,
684if (value.Type is not null)
860if (insert.Value.Type is null)
887Debug.Assert(part is BoundLiteral { Type: { SpecialType: SpecialType.System_String }, ConstantValueOpt.IsString: true });
955argumentsBuilder.Add(boundLiteral.Update(ConstantValue.Create(literalText), boundLiteral.Type));
Binder\Binder_Invocation.cs (27)
285else if ((object)argument.Type == null && !argument.HasAnyErrors)
296else if (argument.Type.IsVoidType())
350if ((object)boundExpression.Type != null && boundExpression.Type.IsDynamic())
378else if (boundExpression.Type?.Kind == SymbolKind.FunctionPointerType)
565Debug.Assert(receiver.Type is not null);
566Error(diagnostics, ErrorCode.ERR_CannotDynamicInvokeOnExpression, receiver.Syntax, receiver.Type);
617Debug.Assert((object?)arg.Type != null);
620Error(diagnostics, ErrorCode.ERR_BadDynamicMethodArg, arg.Syntax, arg.Type);
881Debug.Assert(methodGroup.ReceiverOpt != null && (object)methodGroup.ReceiverOpt.Type != null);
883Error(diagnostics, ErrorCode.ERR_BadArgTypeDynamicExtension, syntax, methodGroup.ReceiverOpt.Type, methodGroup.Name);
1110if (!call.HasAnyErrors && call.ReceiverOpt != null && (object)call.ReceiverOpt.Type != null && !call.Method.IsExtensionBlockMember())
1115if (call.ReceiverOpt.Type.IsRestrictedType() && !call.Method.ContainingType.IsInterface && !TypeSymbol.Equals(call.Method.ContainingType, call.ReceiverOpt.Type, TypeCompareKind.ConsiderEverything2))
1117SymbolDistinguisher distinguisher = new SymbolDistinguisher(compilation, call.ReceiverOpt.Type, call.Method.ContainingType);
1133(object)dynInvoke.Expression.Type != null &&
1134dynInvoke.Expression.Type.IsRestrictedType())
1138Error(diagnostics, ErrorCode.ERR_BadDynamicMethodArg, dynInvoke.Expression.Syntax, dynInvoke.Expression.Type);
1426if (receiver is BoundValuePlaceholderBase || receiver?.Type is null or { IsReferenceType: true })
1949receiver.Type.IsValueType &&
2020Debug.Assert(typeOrValue.Type.Equals(boundValue.Type, TypeCompareKind.ConsiderEverything));
2067var type = expr.Type as NamedTypeSymbol;
2122var methodContainer = (object)receiver != null && (object)receiver.Type != null
2123? receiver.Type
2365var methodContainer = expr.Type ?? this.ContainingType;
2573RoslynDebug.Assert(boundExpression.Type is FunctionPointerTypeSymbol);
2575var funcPtr = (FunctionPointerTypeSymbol)boundExpression.Type;
Binder\Binder_Operators.cs (87)
72Debug.Assert(left.Type is { });
75var placeholder = new BoundValuePlaceholder(right.Syntax, left.HasDynamicType() ? left.Type : right.Type).MakeCompilerGenerated();
76var finalDynamicConversion = this.Compilation.Conversions.ClassifyConversionFromExpression(placeholder, left.Type, isChecked: CheckOverflowAtRuntime, ref useSiteInfo);
78var conversion = (BoundConversion)CreateConversion(node, placeholder, finalDynamicConversion, isCast: true, conversionGroupOpt: null, InConversionGroupFlags.Unspecified, left.Type, diagnostics);
87left.Type,
88right.Type,
96left.Type,
267var leftType = left.Type;
340var leftType = left.Type;
383var leftType = left.Type;
434var leftType = left.Type;
780TypeSymbol type = operand.Type;
808Debug.Assert((object)left.Type != null && left.Type.IsDynamic() || (object)right.Type != null && right.Type.IsDynamic());
832Error(diagnostics, ErrorCode.ERR_InvalidDynamicCondition, node.Left, left.Type, kind == BinaryOperatorKind.LogicalAnd ? "false" : "true");
838Debug.Assert(left.Type is not TypeParameterSymbol);
952TypeSymbol leftType = left.Type;
953TypeSymbol rightType = right.Type;
988Debug.Assert(right.Type.SpecialType == SpecialType.System_String);
989var stringConstant = FoldBinaryOperator(node, BinaryOperatorKind.StringConcatenation, left, right, right.Type, diagnostics);
990return new BoundBinaryOperator(node, BinaryOperatorKind.StringConcatenation, BoundBinaryOperator.UncommonData.UnconvertedInterpolatedStringAddition(stringConstant), LookupResultKind.Empty, left, right, right.Type);
1191TypeSymbol leftType = left.Type;
1192TypeSymbol rightType = right.Type;
1309(object?)left.Type != null && left.Type.TypeKind == TypeKind.Delegate)
1313var conversion = this.Conversions.ClassifyConversionFromExpression(right, left.Type, isChecked: CheckOverflowAtRuntime, ref discardedUseSiteInfo);
1315GenerateImplicitConversionError(diagnostics, right.Syntax, conversion, right, left.Type);
1343case (BoundKind.DefaultLiteral, _) when right.Type is TypeParameterSymbol:
1344Debug.Assert(!right.Type.IsReferenceType);
1345Error(diagnostics, ErrorCode.ERR_AmbigBinaryOpsOnUnconstrainedDefault, node, operatorToken.Text, right.Type);
1347case (_, BoundKind.DefaultLiteral) when left.Type is TypeParameterSymbol:
1348Debug.Assert(!left.Type.IsReferenceType);
1349Error(diagnostics, ErrorCode.ERR_AmbigBinaryOpsOnUnconstrainedDefault, node, operatorToken.Text, left.Type);
1367case LookupResultKind.OverloadResolutionFailure when operatorToken.Kind() is SyntaxKind.PlusToken && isReadOnlySpanOfByte(left.Type) && isReadOnlySpanOfByte(right.Type):
1441if ((object)left.Type != null && left.Type.SpecialType == SpecialType.System_Boolean &&
1442(object)right.Type != null && right.Type.SpecialType == SpecialType.System_Boolean)
1444var constantValue = FoldBinaryOperator(node, kind | BinaryOperatorKind.Bool, left, right, left.Type, diagnostics);
1448resultKind: LookupResultKind.Viable, left, right, type: left.Type, hasErrors: constantValue != null && constantValue.IsBad);
1535Debug.Assert(resultLeft.Type.Equals(signature.LeftType, TypeCompareKind.IgnoreNullableModifiersForReferenceTypes));
1536var operandPlaceholder = new BoundValuePlaceholder(resultLeft.Syntax, resultLeft.Type).MakeCompilerGenerated();
1592var type = left.Type;
1609if (left.Type is not null)
1611CreateConversion(left.Syntax, new BoundValuePlaceholder(left.Syntax, left.Type).MakeCompilerGenerated(), implicitConversion, isCast: false, conversionGroupOpt: null, InConversionGroupFlags.Unspecified, booleanType, diagnostics);
2101if (left.Type is null && right.Type is null)
2361(object)operand.Type != null &&
2362(operand.Type.SpecialType == SpecialType.System_UInt64 || isNuint(operand.Type)))
2414operand.Type is null) // GetUserDefinedOperators performs this check too, let's optimize early
2647return left.Type;
2650return right.Type;
2714BinaryOperatorKind newKind = kind.Operator().WithType(newLeftOperand.Type!.SpecialType);
3297var operandType = operand.Type;
3451var operandType = operand.Type;
3498Debug.Assert(operand.Type is not null);
3504operand.Type,
3541var operandType = operand.Type;
3693Debug.Assert(operand.Type is not null);
4099var operandType = operand.Type as PointerTypeSymbol;
4154TypeSymbol operandType = operand.Type;
4233if (receiver.Type.IsReferenceType)
4359if (isOperandNullOrNew || operand.Type?.IsErrorType() == true)
4387type: operand.Type!);
4441var underlyingType = operand.Type.GetEnumUnderlyingType()!;
4776if ((object)operand.Type == null && !operand.IsLiteralNull())
4826TypeSymbol inputType = operand.Type;
4962inputType = operand.Type;
4993if (originalExpression.Type is not null && !originalExpression.Type.Equals(unionMatchingInputType.StrippedType(), TypeCompareKind.AllIgnoreOptions))
5009convertedExpression.Type ?? inputType,
5397if ((object)operand.Type == null)
5459Debug.Assert(operand.Type is null);
5460operandPlaceholder = new BoundValuePlaceholder(operand.Syntax, operand.Type).MakeCompilerGenerated();
5474var operandType = operand.Type;
5507operandPlaceholder = new BoundValuePlaceholder(operand.Syntax, operand.Type).MakeCompilerGenerated();
5686TypeSymbol optLeftType = leftOperand.Type; // "A"
5687TypeSymbol optRightType = rightOperand.Type; // "B"
5860TypeSymbol leftType = leftOperand.Type;
5878if (underlyingRightConversion.Exists && rightOperand.Type?.IsDynamic() != true)
6019TypeSymbol trueType = trueExpr.Type;
6020TypeSymbol falseType = falseExpr.Type;
Binder\Binder_Patterns.cs (21)
67TypeSymbol? expressionType = expression.Type;
80Debug.Assert(expression.Type is { });
82BoundPattern pattern = BindPattern(node.Pattern, ref unionType, expression.Type, permitDesignations: true, hasErrors, diagnostics, out bool hasUnionMatching, underIsPattern: true);
112Debug.Assert(expression.Type is object);
113diagnostics.Add(ErrorCode.ERR_IsPatternImpossible, node.Location, expression.Type);
130Debug.Assert(expression.Type is object);
131diagnostics.Add(ErrorCode.WRN_IsPatternAlways, node.Location, expression.Type);
311Debug.Assert(indexerAccess.Type is not null);
312sliceType = indexerAccess.Type;
396Debug.Assert(indexerAccess!.Type is not null);
397elementType = indexerAccess.Type;
514var convertedType = convertedExpression.Type ?? inputType;
535if (originalExpression.Type is not null && !originalExpression.Type.Equals(unionMatchingInputType.StrippedType(), TypeCompareKind.AllIgnoreOptions))
670if (convertedExpression.Type is null && constantValueOpt != ConstantValue.Null)
712RoslynDebug.Assert(expression.Type is { });
713ConstantValue match = ExpressionOfTypeMatchesPatternType(Conversions, inputType, expression.Type, ref useSiteInfo, out _, operandConstantValue: null);
745if (expression.Type?.SpecialType == SpecialType.System_String && inputType.IsSpanOrReadOnlySpanChar())
800(conversion.ConversionKind == ConversionKind.NoConversion && convertedExpression.Type?.IsErrorType() == true))
809if (!hasErrors && unionType is not null && !convertedExpression.HasErrors && constantValue is { IsBad: false } && expression.Type is not null)
1976var type = value.Type ?? inputType;
Binder\Binder_Query.cs (14)
300Debug.Assert(state.fromExpression.Type is { });
303ImmutableArray.Create(state.fromExpression), state.fromExpression.Type);
743else if (!yExpression.HasAnyErrors && yExpression.Type!.IsVoidType())
745Error(d, ErrorCode.ERR_QueryRangeVariableAssignedBadValue, errorLocation, yExpression.Type!);
746Debug.Assert(yExpression.Type is { });
747yExpression = new BoundBadExpression(yExpression.Syntax, LookupResultKind.Empty, ImmutableArray<Symbol?>.Empty, ImmutableArray.Create(yExpression), yExpression.Type);
808field2Value = new BoundBadExpression(field2Value.Syntax, LookupResultKind.Empty, ImmutableArray<Symbol?>.Empty, ImmutableArray.Create(field2Value), field2Value.Type, true);
828return e.Type ?? CreateErrorType();
933Debug.Assert(receiver.Type is object || ultimateReceiver.Type is null);
934if ((object?)ultimateReceiver.Type == null)
968if (ultimateReceiver.Type.TypeKind == TypeKind.TypeParameter)
971Error(diagnostics, ErrorCode.ERR_BadSKunknown, ultimateReceiver.Syntax, ultimateReceiver.Type, MessageID.IDS_SK_TYVAR.Localize());
979else if (receiver.Type!.IsVoidType())
Binder\Binder_QueryErrors.cs (7)
45if (instanceArgument.Type.IsDynamic())
52else if (ImplementsStandardQueryInterface(instanceArgument.Type, name, ref useSiteInfo))
57new object[] { instanceArgument.Type, name },
60else if (fromClause != null && fromClause.Type == null && HasCastToQueryProvider(instanceArgument.Type, ref useSiteInfo))
65new object[] { instanceArgument.Type, name, fromClause.Identifier.ValueText },
73new object[] { instanceArgument.Type, name },
238TypeSymbol receiverType = receiver?.Type;
Binder\Binder_Statements.cs (26)
407var type = boundExpr.Type;
764Debug.Assert(expr.Type is object);
765Debug.Assert(expr.Type.IsRefLikeType || hasAwait); // pattern dispose lookup is only valid on ref structs or asynchronous usings
1027TypeSymbol initializerType = initializerOpt?.Type;
1237TypeSymbol initializerType = initializerOpt.Type;
1253elementType = ((BoundAddressOfOperator)initializerOpt).Operand.Type;
1327if (initializer.Type.IsVoidType())
1347additionalDiagnostics.Add(ErrorCode.WRN_PatternBadSignature, initializer.Syntax.Location, initializer.Type, "fixed", patternMethodSymbol);
1465var inferredType = op2.Type;
1491if (op1.Type is { } lhsType && !lhsType.IsErrorType())
1539type = op1.Type;
1560Debug.Assert(op1.Type is { });
1593Debug.Assert(leftEscape.Equals(rightEscape) || op1.Type.IsRefLikeOrAllowsRefLikeType());
1627if (!hasErrors && op1.Type.IsRefLikeOrAllowsRefLikeType())
1861Debug.Assert((object)receiver.Type != null);
1862return receiver.Type;
1988this.Conversions.ClassifyConversionFromType(expression.Type, targetType, isChecked: CheckOverflowAtRuntime, ref useSiteInfo);
2020expression.Type,
2480var sourceType = operand.Type;
3115hasErrors |= arg.HasErrors || ((object)arg.Type != null && arg.Type.IsErrorType());
3190if ((object)arg?.Type != null && arg.Type.IsVoidType())
3255&& TypeSymbol.Equals(argument.Type, this.GetCurrentReturnType(out unusedRefKind), TypeCompareKind.ConsiderEverything2))
3258Error(diagnostics, ErrorCode.ERR_BadAsyncReturnExpression, argument.Syntax, returnType, argument.Type);
3607else if (expression.Type?.SpecialType == SpecialType.System_Void)
Binder\Binder_Symbols.cs (3)
1522receiver = new BoundBadExpression(receiver.Syntax, LookupResultKind.Ambiguous, ImmutableArray<Symbol>.Empty, ImmutableArray.Create(receiver), receiver.Type, hasErrors: true).MakeCompilerGenerated();
1531Error(diagnostics, ErrorCode.ERR_NoSuchMemberOrExtension, right, receiver.Type, plainName);
1532receiver = new BoundBadExpression(receiver.Syntax, LookupResultKind.Empty, ImmutableArray<Symbol>.Empty, childBoundNodes: [AdjustBadExpressionChild(receiver)], receiver.Type, hasErrors: true).MakeCompilerGenerated();
Binder\Binder.ValueChecks.cs (32)
923Debug.Assert(!checkingReceiver || expr.Type.IsValueType || expr.Type.IsTypeParameter());
950if ((expr.ConstantValueOpt != null) || (expr.Type.GetSpecialTypeSafe() == SpecialType.System_Void))
1140getItemOrSliceHelper = getItemOrSliceHelper.AsMember(getItemOrSliceHelper.ContainingType.Construct(ImmutableArray.Create(elementAccess.Expression.Type.TryGetInlineArrayElementField().TypeWithAnnotations)));
1215indices[0].Type,
1253Error(diagnostics, ErrorCode.ERR_BadSKunknown, expr.Syntax, expr.Type, MessageID.IDS_SK_TYPE.Localize());
1923&& receiver?.Type?.IsValueType == true;
2157if (receiver is BoundObjectOrCollectionValuePlaceholder && receiver.Type.IsAnonymousType)
2319if (methodInvocationInfo.MethodInfo.Method?.RequiresInstanceReceiver == true && methodInvocationInfo.Receiver?.Type?.IsRefLikeOrAllowsRefLikeType() == true)
2542if (receiver?.Type?.IsRefLikeOrAllowsRefLikeType() == true)
2653Debug.Assert(receiver.Type is { });
2658Debug.Assert(receiver is not BoundValuePlaceholderBase && method is not null && receiver.Type?.IsReferenceType == false);
2663receiver = new BoundCapturedReceiverPlaceholder(receiver.Syntax, receiver, receiver.Type).MakeCompilerGenerated();
2757if (receiver.Type is TypeParameterSymbol typeParameter)
2996if (argument.Type?.IsRefLikeOrAllowsRefLikeType() == true)
3056if (argument.Type?.IsRefLikeOrAllowsRefLikeType() == true)
3192&& argument.Type?.IsRefLikeOrAllowsRefLikeType() == true)
3656Debug.Assert(expr.Type is not null);
3688if (expr.Type?.GetSpecialTypeSafe() == SpecialType.System_Void)
3962Debug.Assert(!checkingReceiver || expr.Type.IsValueType || expr.Type.IsTypeParameter());
3977if (expr.Type?.GetSpecialTypeSafe() == SpecialType.System_Void)
4342if (expr.Type?.IsRefLikeOrAllowsRefLikeType() != true)
4751RoslynDebug.Assert(false, $"{expr.Kind} expression of {expr.Type} type");
5022Debug.Assert(!checkingReceiver || expr.Type.IsValueType || expr.Type.IsTypeParameter());
5043if (expr.Type?.IsRefLikeOrAllowsRefLikeType() != true)
5111Error(diagnostics, inUnsafeRegion ? ErrorCode.WRN_EscapeStackAlloc : ErrorCode.ERR_EscapeStackAlloc, node, expr.Type);
5370Error(diagnostics, ErrorCode.ERR_CollectionExpressionEscape, node, expr.Type);
5556RoslynDebug.Assert(false, $"{expr.Kind} expression of {expr.Type} type");
5729TypeWithAnnotations.Create(elementAccess.Expression.Type),
5769TypeWithAnnotations.Create(inlineArray.Type),
Binder\ForEachLoopBinder.cs (18)
558(builder.ElementType.IsPointerOrFunctionPointer() && collectionExpr.Type.IsArray()) ||
559(builder.ElementType.IsNullableType() && builder.ElementType.GetMemberTypeArgumentsNoUseSiteDiagnostics().Single().IsErrorType() && collectionExpr.Type.IsArray()));
595(collectionConversionClassification.Kind == ConversionKind.ExplicitReference && collectionExpr.Type.SpecialType == SpecialType.System_String));
665Debug.Assert(collectionType.Equals(collectionExpr.Type, TypeCompareKind.AllIgnoreOptions)); // Should not create an Identity conversion that changes type.
705else if (collectionExpr.Type.SpecialType == SpecialType.System_String && builder.CollectionType.SpecialType == SpecialType.System_Collections_IEnumerable)
723TypeSymbol collectionExprType = collectionExpr.Type;
805TypeSymbol collectionExprType = collectionExpr.Type;
844if (!isAsync && collectionExpr.Type?.HasInlineArrayAttribute(out _) == true && collectionExpr.Type.TryGetPossiblyUnsupportedByLanguageInlineArrayElementField() is FieldSymbol elementField)
875diagnostics.Add(ErrorCode.ERR_InlineArrayForEachNotSupported, collectionExpr.Syntax.GetLocation(), collectionExpr.Type);
898builder.CollectionType = collectionExpr.Type;
915CheckInlineArrayTypeIsSupported(collectionExpr.Syntax, collectionExpr.Type, elementField.Type, diagnostics);
923diagnostics.Add(ErrorCode.ERR_InlineArrayForEachNotSupported, collectionExpr.Syntax.GetLocation(), collectionExpr.Type);
947TypeSymbol collectionExprType = collectionExpr.Type;
987var unwrappedCollectionExprType = unwrappedCollectionExpr.Type;
1057builder.CollectionType = collectionExpr.Type;
1359getEnumeratorInfo = FindForEachPatternMethod(syntax, collectionSyntax, collectionExpr.Type, methodName, lookupResult, warningsOnly: true, diagnostics, isAsync);
1610diagnostics.Add(ErrorCode.WRN_PatternIsAmbiguous, collectionSyntax.Location, collectionExpr.Type, MessageID.IDS_Collection.Localize(),
Binder\Semantics\Conversions\ConversionsBase.cs (13)
104var sourceType = sourceExpression.Type;
289if (TryGetVoidConversion(sourceExpression.Type, destination, out var conversion))
609Debug.Assert(sourceExpression == null || (object)sourceExpression.Type == (object)source);
1048Debug.Assert(sourceExpression == null || (object)sourceExpression.Type == (object)source);
1090var innerConversion = ClassifyImplicitBuiltInConversionFromExpression(innerExpression, innerExpression.Type, destination, ref useSiteInfo);
1368if (constantValue == null || (object)source.Type == null)
1378var specialSource = source.Type.GetSpecialTypeSafe();
1434var sourceType = sourceExpression.Type;
1477source.Type is object &&
1478IsNumericType(source.Type) &&
1939Debug.Assert(sourceExpressionOpt == null || (object)sourceExpressionOpt.Type == sourceType);
1976conversions.ClassifyImplicitExtensionMethodThisArgConversion(s, s.Type, d.Type, ref u, isMethodGroupConversion: false),
3065if (expressionToCheck.Type is TypeSymbol typeToCheck && IsRefLikeOrAllowsRefLikeTypeImplementingVarianceCompatibleInterface(typeToCheck, targetInterfaceType, ref useSiteInfo))
Binder\Semantics\Operators\BinaryOperatorOverloadResolution.cs (35)
78TypeSymbol leftOperatorSourceOpt = left.Type?.StrippedType();
79TypeSymbol rightOperatorSourceOpt = right.Type?.StrippedType();
373var leftType = left.Type;
375var rightType = right.Type;
517bool isExactSubtraction = TypeSymbol.Equals(right.Type?.StrippedType(), underlying, TypeCompareKind.ConsiderEverything2);
621var leftType = left.Type;
627var rightType = right.Type;
696var leftType = left.Type as PointerTypeSymbol;
697var rightType = right.Type as PointerTypeSymbol;
712if ((object)leftType != null || (object)rightType != null || left.Type is FunctionPointerTypeSymbol || right.Type is FunctionPointerTypeSymbol)
734if ((left.Type is TypeParameterSymbol { AllowsRefLikeType: true } && right.IsLiteralNull()) ||
735(right.Type is TypeParameterSymbol { AllowsRefLikeType: true } && left.IsLiteralNull()))
754this.Compilation.BuiltInOperators.GetSimpleBuiltInOperators(kind, operators, skipNativeIntegerOperators: !left.Type.IsNativeIntegerOrNullableThereof() && !right.Type.IsNativeIntegerOrNullableThereof());
769this.Compilation.BuiltInOperators.GetUtf8ConcatenationBuiltInOperator(left.Type, operators);
780BuiltInOperators.IsValidObjectEquality(conversions, left.Type, left.IsLiteralNull(), leftIsDefault: false, right.Type, right.IsLiteralNull(), rightIsDefault: false, ref useSiteInfo) &&
781((object)left.Type == null || (!left.Type.IsDelegateType() && left.Type.SpecialType != SpecialType.System_String && left.Type.SpecialType != SpecialType.System_Delegate)) &&
782((object)right.Type == null || (!right.Type.IsDelegateType() && right.Type.SpecialType != SpecialType.System_String && right.Type.SpecialType != SpecialType.System_Delegate));
792return (operand.Type is TypeParameterSymbol { AllowsRefLikeType: true }) ? Conversion.Boxing : Conversions.ClassifyConversionFromExpression(operand, objectType, isChecked: isChecked, ref useSiteInfo);
1448if (left.Type?.IsNullableType() == true || right.Type?.IsNullableType() == true) // Wouldn't be applicable to the receiver type otherwise
1590if (left.Type is not null && parameterMatchesReceiver(in candidate, 0) && isOperandApplicableToReceiver(in candidate, left, ref useSiteInfo))
1595if (!kind.IsShift() && right.Type is not null && parameterMatchesReceiver(in candidate, 1) && isOperandApplicableToReceiver(in candidate, right, ref useSiteInfo))
1614Debug.Assert(operand.Type is not null);
1617if (candidate.Kind.IsLifted() && operand.Type.IsNullableType())
1620!Conversions.ConvertExtensionMethodThisArg(MakeNullable(candidate.Method.ContainingType.ExtensionParameter.Type), operand.Type, ref useSiteInfo, isMethodGroupConversion: false).Exists)
1625else if (!Conversions.ConvertExtensionMethodThisArg(candidate.Method.ContainingType.ExtensionParameter.Type, operand.Type, ref useSiteInfo, isMethodGroupConversion: false).Exists)
Binder\Semantics\Operators\UnaryOperatorOverloadResolution.cs (11)
83Debug.Assert(operand.Type is not null);
89if (operand.Type.IsNullableType()) // Wouldn't be applicable to the receiver type otherwise
220Debug.Assert(operand.Type is not null);
225Debug.Assert(operand.Type.IsNullableType());
228!Conversions.ConvertExtensionMethodThisArg(MakeNullable(candidate.Method.ContainingType.ExtensionParameter.Type), operand.Type, ref useSiteInfo, isMethodGroupConversion: false).Exists)
233else if (!Conversions.ConvertExtensionMethodThisArg(candidate.Method.ContainingType.ExtensionParameter.Type, operand.Type, ref useSiteInfo, isMethodGroupConversion: false).Exists)
514this.Compilation.BuiltInOperators.GetSimpleBuiltInOperators(kind, operators, skipNativeIntegerOperators: !operand.Type.IsNativeIntegerOrNullableThereof());
553var enumType = operand.Type;
584var pointerType = operand.Type as PointerTypeSymbol;
615if ((object)operand.Type == null)
643return GetUserDefinedOperators(operand.Type.StrippedType(), kind, isChecked, name1, name2Opt, operand, results, ref useSiteInfo);
Binder\Semantics\OverloadResolution\OverloadResolutionResult.cs (7)
545diagnostics.Add(ErrorCode.ERR_CollectionExpressionMissingAdd, location, receiver.Type);
685diagnostics.Add(ErrorCode.ERR_QueryNoProvider, location, receiverOpt.Type, symbol.Name);
693diagnostics.Add(ErrorCode.ERR_BadAwaitArg, location, receiverOpt.Type);
813new object[] { instanceArgument.Type, inferenceFailed.Member.Name },
1171diagnostics.Add(ErrorCode.ERR_CollectionExpressionMissingAdd, location, receiver.Type);
1410=> argument is BoundLiteral { Type.SpecialType: SpecialType.System_String } &&
1449diagnostics.Add(ErrorCode.ERR_QueryMultipleProviders, location, receiver.Type, name);
CodeGen\EmitExpression.cs (51)
52if ((object)expression.Type == null ||
53(expression.Type.SpecialType != SpecialType.System_Decimal &&
54!expression.Type.IsNullableType()))
56EmitConstantExpression(expression.Type, constantValue, used, expression.Syntax);
385EmitDefaultValue(node.Type, used, node.Syntax);
420var receiverType = receiver.Type;
533Debug.Assert(receiver.Type.IsNullableType());
691EmitSymbolToken(expression.Operand.Type, expression.Operand.Syntax);
741Debug.Assert(refKind is RefKind.In || argument.Type.IsDynamic() || argument is BoundFieldAccess { FieldSymbol.RefKind: not RefKind.None }, "passing args byref should not clone them into temps");
818EmitLoadIndirect(expression.Type, expression.Syntax);
827var meth = expression.MethodOpt ?? receiver.Type.DelegateInvokeMethod();
1040if (((ArrayTypeSymbol)arrayAccess.Expression.Type).IsSZArray)
1127_builder.EmitArrayElementLoad(_module.Translate((ArrayTypeSymbol)arrayAccess.Expression.Type), arrayAccess.Expression.Syntax);
1137LocalRewriter.IsInvariantArray(arrayAccess.Expression.Type) ||
1168if (!field.IsVolatile && !field.IsStatic && (receiver = fieldAccess.ReceiverOpt).Type.IsVerifierValue() && field.RefKind == RefKind.None &&
1240if (fieldType.IsValueType && (object)fieldType == (object)receiver.Type)
1295if (receiver == null || !receiver.Type.IsValueType)
1306EmitSymbolToken(receiver.Type, receiver.Syntax);
1335if (!receiver.Type.IsVerifierValue())
1387var type = expr.Type;
1592if (receiver.Type.IsTypeParameter())
1597Debug.Assert(receiver.Type.IsVerifierReference(), "this is not a reference");
1727Debug.Assert(TypeSymbol.Equals(method.ContainingType, receiver.Type, TypeCompareKind.ConsiderEverything2));
1762EmitSymbolToken(receiver.Type, receiver.Syntax);
1929var receiverType = receiver.Type;
2019var receiverType = receiver.Type;
2079Debug.Assert(receiver.Type.IsVerifierReference());
2090Debug.Assert(receiver.Type.IsVerifierReference());
2116EmitSymbolToken(receiver.Type, receiver.Syntax);
2131var receiverType = receiver.Type;
2194var receiverType = receiver.Type;
2727var rightType = right.Type;
2783if (left.Kind == BoundKind.ArrayAccess && left.Type.TypeKind == TypeKind.TypeParameter && !left.Type.IsValueType)
2807EmitSymbolToken(target.Type, target.Syntax);
3201assignmentOperator.Left.Type,
3248var arrayType = (ArrayTypeSymbol)array.Type;
3268EmitIndirectStore(expression.Type, expression.Syntax);
3273EmitIndirectStore(expression.Type, expression.Syntax);
3279EmitIndirectStore(expression.Type, expression.Syntax);
3291EmitIndirectStore(expression.Type, expression.Syntax);
3296EmitIndirectStore(expression.Type, expression.Syntax);
3542Debug.Assert((object)operand.Type != null);
3543if (!operand.Type.IsVerifierReference())
3546EmitBox(operand.Type, operand.Syntax);
3569var operandType = operand.Type;
4063if (!(expr.Type.IsInterfaceType() || expr.Type.IsDelegateType()))
4065return expr.Type;
4110return expr.Type;
4181temp = AllocateTemp(ptrInvocation.InvokedExpression.Type, ptrInvocation.Syntax);
CodeGen\EmitStatement.cs (28)
178var exprType = thrown.Type;
252var nonConstType = nonConstOp.Type;
530var receiverType = receiver.Type;
589Debug.Assert((object)operand.Type != null);
590if (!operand.Type.IsVerifierReference())
593EmitBox(operand.Type, operand.Syntax);
610var conditionType = condition.Type;
925_module.Translate(expressionOpt.Type, boundReturnStatement.Syntax, _diagnostics.DiagnosticBag);
1150if (!exceptionSourceOpt.Type.IsVerifierReference())
1152Debug.Assert(exceptionSourceOpt.Type.IsTypeParameter()); // only expecting type parameters
1154EmitSymbolToken(exceptionSourceOpt.Type, exceptionSourceOpt.Syntax);
1181Debug.Assert(!left.ReceiverOpt.Type.IsTypeParameter());
1192var temp = AllocateTemp(exceptionSource.Type, exceptionSource.Syntax);
1259Debug.Assert((object)dispatch.Expression.Type != null);
1260Debug.Assert(dispatch.Expression.Type.IsValidV6SwitchGoverningType() || dispatch.Expression.Type.IsSpanOrReadOnlySpanChar());
1263Debug.Assert(!dispatch.Expression.Type.IsNullableType());
1282Debug.Assert((object)expression.Type != null &&
1283(expression.Type.IsValidV6SwitchGoverningType() || expression.Type.IsSpanOrReadOnlySpanChar()));
1328temp = AllocateTemp(expression.Type, expression.Syntax);
1335expression.Type.SpecialType == SpecialType.System_String || expression.Type.IsSpanOrReadOnlySpanChar());
1338if (expression.Type.SpecialType == SpecialType.System_String || expression.Type.IsSpanOrReadOnlySpanChar())
1342this.EmitStringSwitchJumpTable(switchCaseLabels, fallThroughLabel, key, expression.Syntax, expression.Type);
1346this.EmitLengthBasedStringSwitchJumpTable(lengthBasedSwitchStringJumpTableOpt, fallThroughLabel, key, expression.Syntax, expression.Type);
1351_builder.EmitIntegerSwitchJumpTable(switchCaseLabels, fallThroughLabel, key, expression.Type.EnumUnderlyingTypeOrSelf().PrimitiveTypeCode, expression.Syntax);
Compilation\CSharpSemanticModel.cs (18)
2062type = boundExpr.Type;
2181convertedType = highestBoundExpr.Type;
2187convertedType = highestBoundExpr.Type;
2276static (TypeSymbol, NullabilityInfo) getTypeAndNullability(BoundExpression expr) => (expr.Type, expr.TopLevelNullability);
3388else if (expr.Type.IsDelegateType())
3705var thisParam = GetThisParameter(boundNode.Type, containingType, containingMember, out resultKind);
3834symbols = OneOrMany.Create<Symbol>(new SynthesizedIntrinsicOperatorSymbol(unaryOperator.Operand.Type.StrippedType(),
3857TypeSymbol opType = increment.Operand.Type.StrippedType();
3884((binaryOperator.Left.IsLiteralNull() && binaryOperator.Right.Type.IsNullableType()) ||
3885(binaryOperator.Right.IsLiteralNull() && binaryOperator.Left.Type.IsNullableType())) &&
3899binaryOperator.Left.Type,
3900binaryOperator.Right.Type,
4110TypeSymbol type = boundNode.Type;
4634if (node.SearchExtensions && receiver.Type is { } receiverType)
4776receiverType = call.ReceiverOpt.Type;
4780receiverType = call.Arguments[0].Type;
4810MethodSymbol reduced = method.ReduceExtensionMethod(receiver.Type, Compilation);
4825MethodSymbol reduced = method.ReduceExtensionMethod(receiverOpt.Type, Compilation);
FlowAnalysis\NullableWalker.cs (66)
436expr.Type?.Equals(result.RValueType.Type, TypeCompareKind.AllIgnoreOptions) == true ? result.RValueType.Type : expr.Type);
2171receiver.Type is object;
2218var operandType = operand.Type;
2236TypeSymbol.Equals(conv.Type, conv.Operand.Type, TypeCompareKind.IgnoreNullableModifiersForReferenceTypes):
4064collectionBuilderElementsPlaceholder.Type,
4946SetAnalyzedNullability(node.ImplicitReceiverOpt, new VisitResult(node.ImplicitReceiverOpt.Type, NullableAnnotation.NotAnnotated, NullableFlowState.NotNull));
5004SetResultType(node, TypeWithState.Create(node.Type, NullableFlowState.NotNull));
5009var resultType = TypeWithState.Create(node.Type, NullableFlowState.NotNull);
5056Debug.Assert(node.Type is object);
5057if (IsEmptyStructType(node.Type))
5062return GetOrCreatePlaceholderSlot(node, TypeWithAnnotations.Create(node.Type, NullableAnnotation.NotAnnotated));
5380Debug.Assert(!node.Expression.Type!.IsValueType);
5394Binder.IsWellKnownSystemRange(node.Indices[0].Type, compilation))
5729if (expr.Type is null)
5739TypeWithAnnotations.Create(expr.Type),
5753Debug.Assert(binary.Type!.SpecialType == SpecialType.System_Boolean);
6016var receiverType = conditional.Receiver.Type!;
6045if (slot > 0 && PossiblyNullableType(operand.Type))
6115LearnFromNullTest(slot, expressionWithoutConversion.Type, ref state, markDependentSlotsNotNull: false);
6229node.Type?.ContainsErrorType() == true ||
6230TypeSymbol.Equals(targetType.Type.GetNullableUnderlyingType(), node.Type, TypeCompareKind.AllIgnoreOptions));
6236targetType = TypeWithAnnotations.Create(node.Type, NullableAnnotation.NotAnnotated);
6528if (slot > 0 && receiver.Type?.IsNullableType() == true)
6529slot = GetNullableOfTValueSlot(receiver.Type, slot, out _);
6573TypeSymbol? refResultType = node.Type?.SetUnknownNullabilityForReferenceTypes();
6639resultType ??= node.Type?.SetUnknownNullabilityForReferenceTypes();
7878TrackAnalyzedNullabilityThroughConversionGroup(TypeWithState.Create(argument.Type, result.RValueType.State), argument as BoundConversion, argumentNoConversion);
7998completion(TypeWithAnnotations.Create(argument.Type));
8027ApplyMemberPostConditions(receiverOpt?.Type, receiverSlot, method);
9191if (value.Type is null || value.Type.IsDynamic() || value.ConstantValueOpt != null)
9201value.Type.HasInlineArrayAttribute(out _) == true &&
9202value.Type.TryGetInlineArrayElementField() is not null)
9342if (TypeAllowsConditionalState(targetType.Type) && TypeAllowsConditionalState(operand.Type))
9490var tupleOpt = (NamedTypeSymbol?)node.Type;
10226if (canConvertNestedNullability && trackMembers && conversionOpt is { } && conversionOperand.Type.Equals(conversionOpt.Type, TypeCompareKind.AllIgnoreOptions))
10983case BoundExpression arg when arg.Type is { TypeKind: TypeKind.Delegate }:
11097Debug.Assert(arg.Type is not null);
11098TypeSymbol argType = arg.Type;
11116Debug.Assert(arg.Type is not null);
11117TypeSymbol argType = arg.Type;
11297var rvalueResult = TypeWithState.Create(node.Type, NullableFlowState.NotNull);
11298var lvalueResult = TypeWithAnnotations.Create(node.Type, NullableAnnotation.NotAnnotated);
11637receiverType: invocation.ReceiverOpt?.Type,
11803if (expr.Type is NamedTypeSymbol { IsTupleType: true } tupleType)
11921targetTypeOfOperandConversion = TypeWithAnnotations.Create(node.OperandConversion.Type, nullableAnnotation: NullableAnnotation.NotAnnotated);
12154SetResultType(node.Expression, TypeWithState.Create(node.Expression.Type, ResultType.State));
12265var reinferenceResult = VisitArgumentsCore(node, receiver.Type, arguments, refKindsOpt, parameters, argsToParamsOpt, defaultArguments,
12284FlowAnalysisAnnotations memberAnnotations = GetRValueAnnotations(containingSlotOpt: -1, receiverTypeForMemberAccessOpt: node.ReceiverOpt.Type, symbol: updatedProperty);
12338var resultType = ApplyUnconditionalAnnotations(indexer.TypeWithAnnotations.ToTypeWithState(), GetRValueAnnotations(containingSlotOpt: -1, receiverTypeForMemberAccessOpt: receiverOpt?.Type, symbol: indexer));
12598if (collectionExpression.Type!.SpecialType == SpecialType.System_Collections_IEnumerable)
12601targetTypeWithAnnotations = TypeWithAnnotations.Create(collectionExpression.Type);
12603else if (ForEachLoopBinder.IsIEnumerableT(collectionExpression.Type.OriginalDefinition, isAsync, compilation))
12850var type = TypeWithAnnotations.Create(node.Type);
13365SetResultType(node, TypeWithState.Create(node.Type, node.Type?.CanContainNull() != false && node.ConstantValueOpt?.IsNull == true ? NullableFlowState.MaybeDefault : NullableFlowState.NotNull));
13542SetResultType(expression, TypeWithState.Create(expression.Type, default));
13664SetResultType(node, TypeWithState.Create(node.Type, NullableFlowState.NotNull));
13697Debug.Assert(node.Type is null || node.Type.IsErrorType() || node.Type.IsRefLikeType);
13713SetResultType(node, TypeWithState.Create(node.Type, NullableFlowState.NotNull));
13717Debug.Assert(node.Type is not null);
13718var type = VisitArrayInitialization(node.Type, initialization, node.HasErrors);
13808if (argument is { Type: null, ConstantValueOpt.IsNull: true, IsSuppressed: false } && !compilation.FeatureStrictEnabled)
Generated\BoundNodes.xml.Generated.cs (194)
474if (!TypeSymbol.Equals(type, this.Type, TypeCompareKind.ConsiderEverything))
502if (receiver != this.Receiver || !TypeSymbol.Equals(type, this.Type, TypeCompareKind.ConsiderEverything))
534public new TypeSymbol Type => base.Type!;
571public new TypeSymbol Type => base.Type!;
600public new TypeSymbol? Type => base.Type;
635public new TypeSymbol Type => base.Type!;
672public new TypeSymbol Type => base.Type!;
708public new TypeSymbol Type => base.Type!;
738public new TypeSymbol Type => base.Type!;
775public new TypeSymbol Type => base.Type!;
810public new TypeSymbol Type => base.Type!;
845public new TypeSymbol Type => base.Type!;
880public new TypeSymbol Type => base.Type!;
915if (!TypeSymbol.Equals(type, this.Type, TypeCompareKind.ConsiderEverything))
949if (refKind != this.RefKind || isAlive != this.IsAlive || !TypeSymbol.Equals(type, this.Type, TypeCompareKind.ConsiderEverything))
977if (expression != this.Expression || !TypeSymbol.Equals(type, this.Type, TypeCompareKind.ConsiderEverything))
1014if (resultKind != this.ResultKind || symbols != this.Symbols || childBoundNodes != this.ChildBoundNodes || !TypeSymbol.Equals(type, this.Type, TypeCompareKind.ConsiderEverything))
1097public new TypeSymbol Type => base.Type!;
1145public new TypeSymbol Type => base.Type!;
1186public new TypeSymbol? Type => base.Type;
1223public new TypeSymbol Type => base.Type!;
1268public new TypeSymbol Type => base.Type!;
1308public new TypeSymbol Type => base.Type!;
1339public new TypeSymbol? Type => base.Type;
1382public new TypeSymbol Type => base.Type!;
1411public new TypeSymbol Type => base.Type!;
1444public new TypeSymbol Type => base.Type!;
1480public new TypeSymbol Type => base.Type!;
1514public new TypeSymbol Type => base.Type!;
1545public new TypeSymbol Type => base.Type!;
1576public new TypeSymbol Type => base.Type!;
1608public new TypeSymbol Type => base.Type!;
1640public new TypeSymbol Type => base.Type!;
1674public new TypeSymbol Type => base.Type!;
1734public new TypeSymbol Type => base.Type!;
1829public new TypeSymbol Type => base.Type!;
1869public new TypeSymbol Type => base.Type!;
1904public new TypeSymbol Type => base.Type!;
1942public new TypeSymbol Type => base.Type!;
1986if (leftOperand != this.LeftOperand || rightOperand != this.RightOperand || !TypeSymbol.Equals(type, this.Type, TypeCompareKind.ConsiderEverything))
2013public new TypeSymbol? Type => base.Type;
2055public new TypeSymbol Type => base.Type!;
2093public new TypeSymbol Type => base.Type!;
2125public new TypeSymbol Type => base.Type!;
2156public new TypeSymbol Type => base.Type!;
2230public new TypeSymbol Type => base.Type!;
2270public new TypeSymbol Type => base.Type!;
2361public new TypeSymbol Type => base.Type!;
2403public new TypeSymbol Type => base.Type!;
2446public new TypeSymbol Type => base.Type!;
2483public new TypeSymbol Type => base.Type!;
2518public new TypeSymbol Type => base.Type!;
2556public new TypeSymbol Type => base.Type!;
2591public new TypeSymbol Type => base.Type!;
2626public new TypeSymbol Type => base.Type!;
2661public new TypeSymbol Type => base.Type!;
2696public new TypeSymbol Type => base.Type!;
2735public new TypeSymbol Type => base.Type!;
2777public new TypeSymbol Type => base.Type!;
2820public new TypeSymbol Type => base.Type!;
2851public new TypeSymbol? Type => base.Type;
2874public new TypeSymbol Type => base.Type!;
2908public new TypeSymbol Type => base.Type!;
2944public new TypeSymbol Type => base.Type!;
2978public new TypeSymbol Type => base.Type!;
3020public new TypeSymbol Type => base.Type!;
3059public new TypeSymbol Type => base.Type!;
3096public new TypeSymbol Type => base.Type!;
3125public new TypeSymbol? Type => base.Type;
3161public new TypeSymbol Type => base.Type!;
4359if (constantValueOpt != this.ConstantValueOpt || !TypeSymbol.Equals(type, this.Type, TypeCompareKind.ConsiderEverything))
4391public new TypeSymbol Type => base.Type!;
4427public new TypeSymbol Type => base.Type!;
4462public new TypeSymbol Type => base.Type!;
4497public new TypeSymbol Type => base.Type!;
4526public new TypeSymbol? Type => base.Type;
4571public new TypeSymbol Type => base.Type!;
4618public new TypeSymbol Type => base.Type!;
4651public new TypeSymbol Type => base.Type!;
4692public new TypeSymbol Type => base.Type!;
4837if (!Symbols.SymbolEqualityComparer.ConsiderEverything.Equals(label, this.Label) || !TypeSymbol.Equals(type, this.Type, TypeCompareKind.ConsiderEverything))
5000if (expression != this.Expression || switchArms != this.SwitchArms || reachabilityDecisionDag != this.ReachabilityDecisionDag || !Symbols.SymbolEqualityComparer.ConsiderEverything.Equals(defaultLabel, this.DefaultLabel) || reportedNotExhaustive != this.ReportedNotExhaustive || !TypeSymbol.Equals(type, this.Type, TypeCompareKind.ConsiderEverything))
5025public new TypeSymbol Type => base.Type!;
5802public new TypeSymbol? Type => base.Type;
5825if (expression != this.Expression || !TypeSymbol.Equals(type, this.Type, TypeCompareKind.ConsiderEverything))
5851public new TypeSymbol Type => base.Type!;
5887public new TypeSymbol Type => base.Type!;
5924public new TypeSymbol Type => base.Type!;
5979public new TypeSymbol Type => base.Type!;
6013public new TypeSymbol Type => base.Type!;
6050public new TypeSymbol Type => base.Type!;
6093public new TypeSymbol Type => base.Type!;
6125public new TypeSymbol Type => base.Type!;
6242public new TypeSymbol Type => base.Type!;
6289public new TypeSymbol Type => base.Type!;
6331public new TypeSymbol Type => base.Type!;
6372public new TypeSymbol? Type => base.Type;
6412public new TypeSymbol Type => base.Type!;
6495public new TypeSymbol? Type => base.Type;
6569public new TypeSymbol Type => base.Type!;
6612if (!TypeSymbol.Equals(type, this.Type, TypeCompareKind.ConsiderEverything))
6690public new TypeSymbol? Type => base.Type;
6727if (sourceTuple != this.SourceTuple || wasTargetTyped != this.WasTargetTyped || arguments != this.Arguments || argumentNamesOpt != this.ArgumentNamesOpt || inferredNamesOpt != this.InferredNamesOpt || !TypeSymbol.Equals(type, this.Type, TypeCompareKind.ConsiderEverything))
6826public new TypeSymbol Type => base.Type!;
6881public new TypeSymbol Type => base.Type!;
6934public new TypeSymbol Type => base.Type!;
7001public new TypeSymbol Type => base.Type!;
7040public new TypeSymbol Type => base.Type!;
7076public new TypeSymbol Type => base.Type!;
7109public new TypeSymbol Type => base.Type!;
7151public new TypeSymbol Type => base.Type!;
7214public new TypeSymbol Type => base.Type!;
7248public new TypeSymbol Type => base.Type!;
7279public new TypeSymbol? Type => base.Type;
7334if (!TypeSymbol.Equals(elementType, this.ElementType, TypeCompareKind.ConsiderEverything) || count != this.Count || initializerOpt != this.InitializerOpt || !TypeSymbol.Equals(type, this.Type, TypeCompareKind.ConsiderEverything))
7356public new TypeSymbol Type => base.Type!;
7390public new TypeSymbol Type => base.Type!;
7435public new TypeSymbol Type => base.Type!;
7469public new TypeSymbol Type => base.Type!;
7506public new TypeSymbol Type => base.Type!;
7550public new TypeSymbol Type => base.Type!;
7604public new TypeSymbol Type => base.Type!;
7647public new TypeSymbol Type => base.Type!;
7686public new TypeSymbol Type => base.Type!;
7728public new TypeSymbol? Type => base.Type;
7772public new TypeSymbol? Type => base.Type;
7810public new TypeSymbol Type => base.Type!;
7877public new TypeSymbol Type => base.Type!;
7928if (parts != this.Parts || constantValueOpt != this.ConstantValueOpt || !TypeSymbol.Equals(type, this.Type, TypeCompareKind.ConsiderEverything))
7956if (!interpolationData.Equals(this.InterpolationData) || parts != this.Parts || constantValueOpt != this.ConstantValueOpt || !TypeSymbol.Equals(type, this.Type, TypeCompareKind.ConsiderEverything))
7984if (!TypeSymbol.Equals(type, this.Type, TypeCompareKind.ConsiderEverything))
8014public new TypeSymbol Type => base.Type!;
8046public new TypeSymbol? Type => base.Type;
8101if (expression != this.Expression || pattern != this.Pattern || hasUnionMatching != this.HasUnionMatching || isNegated != this.IsNegated || reachabilityDecisionDag != this.ReachabilityDecisionDag || !Symbols.SymbolEqualityComparer.ConsiderEverything.Equals(whenTrueLabel, this.WhenTrueLabel) || !Symbols.SymbolEqualityComparer.ConsiderEverything.Equals(whenFalseLabel, this.WhenFalseLabel) || !TypeSymbol.Equals(type, this.Type, TypeCompareKind.ConsiderEverything))
8761public new TypeSymbol? Type => base.Type;
8798if (expression != this.Expression || !TypeSymbol.Equals(type, this.Type, TypeCompareKind.ConsiderEverything))
8820public new TypeSymbol? Type => base.Type;
8893public new TypeSymbol? Type => base.Type;
8991public new TypeSymbol? Type => base.Type;
9024if (originalExpression != this.OriginalExpression || !TypeSymbol.Equals(type, this.Type, TypeCompareKind.ConsiderEverything))
9049public new TypeSymbol Type => base.Type!;
11130TypeSymbol? type = this.VisitType(node.Type);
11136TypeSymbol? type = this.VisitType(node.Type);
11198TypeSymbol? type = this.VisitType(node.Type);
11203TypeSymbol? type = this.VisitType(node.Type);
11209TypeSymbol? type = this.VisitType(node.Type);
11216TypeSymbol? type = this.VisitType(node.Type);
11412TypeSymbol? type = this.VisitType(node.Type);
11832TypeSymbol? type = this.VisitType(node.Type);
11906TypeSymbol? type = this.VisitType(node.Type);
11935TypeSymbol? type = this.VisitType(node.Type);
12088TypeSymbol? type = this.VisitType(node.Type);
12230TypeSymbol? type = this.VisitType(node.Type);
12253TypeSymbol? type = this.VisitType(node.Type);
12364TypeSymbol? type = this.VisitType(node.Type);
12475TypeSymbol? type = this.VisitType(node.Type);
12481TypeSymbol? type = this.VisitType(node.Type);
12486TypeSymbol? type = this.VisitType(node.Type);
12509TypeSymbol? type = this.VisitType(node.Type);
12644TypeSymbol? type = this.VisitType(node.Type);
12690TypeSymbol? type = this.VisitType(node.Type);
12764updatedNode = node.Update(receiver, node.Type);
12947updatedNode = node.Update(expression, node.Type);
12965updatedNode = node.Update(node.ResultKind, node.Symbols, childBoundNodes, node.Type);
13342updatedNode = node.Update(leftOperand, rightOperand, node.Type);
14143updatedNode = node.Update(expression, switchArms, reachabilityDecisionDag, node.DefaultLabel, node.ReportedNotExhaustive, node.Type);
14238updatedNode = node.Update(expression, node.Type);
14600updatedNode = node.Update(sourceTuple, node.WasTargetTyped, arguments, node.ArgumentNamesOpt, node.InferredNamesOpt, node.Type);
14883updatedNode = node.Update(elementType, count, initializerOpt, node.Type);
15121updatedNode = node.Update(parts, node.ConstantValueOpt, node.Type);
15138updatedNode = node.Update(node.InterpolationData, parts, node.ConstantValueOpt, node.Type);
15200updatedNode = node.Update(expression, pattern, node.HasUnionMatching, node.IsNegated, reachabilityDecisionDag, node.WhenTrueLabel, node.WhenFalseLabel, node.Type);
15351updatedNode = node.Update(expression, node.Type);
15447updatedNode = node.Update(originalExpression, node.Type);
15510new TreeDumperNode("type", node.Type, null),
15518new TreeDumperNode("type", node.Type, null),
15607new TreeDumperNode("type", node.Type, null),
15616new TreeDumperNode("type", node.Type, null),
15624new TreeDumperNode("type", node.Type, null),
15634new TreeDumperNode("type", node.Type, null),
15905new TreeDumperNode("type", node.Type, null),
16472new TreeDumperNode("type", node.Type, null),
16574new TreeDumperNode("type", node.Type, null),
16611new TreeDumperNode("type", node.Type, null),
16805new TreeDumperNode("type", node.Type, null),
17031new TreeDumperNode("type", node.Type, null),
17065new TreeDumperNode("type", node.Type, null),
17231new TreeDumperNode("type", node.Type, null),
17398new TreeDumperNode("type", node.Type, null),
17408new TreeDumperNode("type", node.Type, null),
17415new TreeDumperNode("type", node.Type, null),
17448new TreeDumperNode("type", node.Type, null),
17618new TreeDumperNode("type", node.Type, null),
17678new TreeDumperNode("type", node.Type, null),
Lowering\ClosureConversion\ExpressionLambdaRewriter.cs (28)
119if (!node.Type.Equals(result.Type, TypeCompareKind.IgnoreNullableModifiersForReferenceTypes))
305if (!TypeSymbol.Equals(index.Type, _int32Type, TypeCompareKind.ConsiderEverything2))
307index = ConvertIndex(index, arg.Type, _int32Type);
323if (!TypeSymbol.Equals(index.Type, _int32Type, TypeCompareKind.ConsiderEverything2))
325index = ConvertIndex(index, arg.Type, _int32Type);
374if (node.Operand.IsLiteralNull() && (object)node.Operand.Type == null)
500if ((object)left.Type == null && left.IsLiteralNull())
502left = _bound.Default(right.Type);
504if ((object)right.Type == null && right.IsLiteralNull())
506right = _bound.Default(left.Type);
517var promotedType = PromotedType(enumOperand.Type.StrippedType().GetEnumUnderlyingType());
570return Convert(loweredOperand, operand.Type, promotedType, isChecked, false);
710var operandType = node.Operand.Type;
719? Convert(Visit(node.Operand), node.Operand.Type, method.Parameters[0].Type, node.Checked, false)
735if (node.Operand.Type.IsNullableType())
737return Convert(Visit(node.Operand), node.Operand.Type, node.Type, node.Checked, node.ExplicitCastInCode);
744var e1 = Convert(Visit(node.Operand), node.Operand.Type, intermediate, node.Checked, false);
750return Convert(Visit(node.Operand), node.Operand.Type, node.Type, node.Checked, node.ExplicitCastInCode);
774else if (!receiver.Type.IsReferenceType)
818var d = node.Argument.Type as NamedTypeSymbol;
839if ((object)operand.Type == null && operand.ConstantValueOpt != null && operand.ConstantValueOpt.IsNull)
910var fromType = leftPlaceholder.Type;
1111Debug.Assert(args.Type.IsSZArray());
1169if (node.ReceiverOpt?.Type.IsTypeParameter() == true &&
1170!node.ReceiverOpt.Type.IsReferenceType)
1240var promotedType = PromotedType(arg.Type.StrippedType().GetEnumUnderlyingType());
1242loweredArg = Convert(loweredArg, arg.Type, promotedType, isChecked, false);
1262_bound.Typeof(node.Type, _bound.WellKnownType(WellKnownType.System_Type)));
Lowering\DiagnosticsPass_Warnings.cs (18)
228Debug.Assert(TypeSymbol.Equals(expr1.Type, expr2.Type, TypeCompareKind.ConsiderEverything2));
329if (node.Left.Type.SpecialType == SpecialType.System_Object && !IsExplicitCast(node.Left) && !(node.Left.ConstantValueOpt != null && node.Left.ConstantValueOpt.IsNull) && ConvertedHasEqual(node.OperatorKind, node.Right, out t))
334else if (node.Right.Type.SpecialType == SpecialType.System_Object && !IsExplicitCast(node.Right) && !(node.Right.ConstantValueOpt != null && node.Right.ConstantValueOpt.IsNull) && ConvertedHasEqual(node.OperatorKind, node.Left, out t))
355NamedTypeSymbol nt = conv.Operand.Type as NamedTypeSymbol;
446if (!conversion.Operand.Type.SpecialType.IsIntegralType() || !conversion.Type.SpecialType.IsIntegralType())
451if (!Binder.CheckConstantBounds(conversion.Operand.Type.SpecialType, constantValue, out _))
453Error(ErrorCode.WRN_VacuousIntegralComp, tree, conversion.Operand.Type);
611TypeSymbol from = conv.Operand.Type;
769Error(ErrorCode.WRN_NubExprIsConstBool, node, always, node.Left.Type.GetNullableUnderlyingType(), node.Left.Type);
773Error(ErrorCode.WRN_NubExprIsConstBool, node, always, node.Right.Type.GetNullableUnderlyingType(), node.Right.Type);
817Error(node.OperatorKind.IsUserDefined() ? ErrorCode.WRN_NubExprIsConstBool2 : ErrorCode.WRN_NubExprIsConstBool, node, always, node.Left.Type.GetNullableUnderlyingType(), GetTypeForLiftedComparisonWarning(node.Right));
821Error(node.OperatorKind.IsUserDefined() ? ErrorCode.WRN_NubExprIsConstBool2 : ErrorCode.WRN_NubExprIsConstBool, node, always, node.Right.Type.GetNullableUnderlyingType(), GetTypeForLiftedComparisonWarning(node.Left));
857if ((object)node.Type == null || !node.Type.IsNullableType())
873return type ?? node.Type;
Lowering\LocalRewriter\LocalRewriter_BinaryOperator.cs (55)
340Debug.Assert(loweredLeft.Type is { });
341Debug.Assert(loweredRight.Type is { });
343return MakeUnaryOperator(UnaryOperatorKind.BoolLogicalNegation, syntax, method: null, constrainedToTypeOpt: null, loweredRight, loweredRight.Type);
346return MakeUnaryOperator(UnaryOperatorKind.BoolLogicalNegation, syntax, method: null, constrainedToTypeOpt: null, loweredLeft, loweredLeft.Type);
354Debug.Assert(loweredLeft.Type is { });
355Debug.Assert(loweredRight.Type is { });
357return MakeUnaryOperator(UnaryOperatorKind.BoolLogicalNegation, syntax, method: null, constrainedToTypeOpt: null, loweredRight, loweredRight.Type);
360return MakeUnaryOperator(UnaryOperatorKind.BoolLogicalNegation, syntax, method: null, constrainedToTypeOpt: null, loweredLeft, loweredLeft.Type);
368Debug.Assert(loweredLeft.Type is { });
369Debug.Assert(loweredRight.Type is { });
371return MakeUnaryOperator(UnaryOperatorKind.BoolLogicalNegation, syntax, method: null, constrainedToTypeOpt: null, loweredRight, loweredRight.Type);
374return MakeUnaryOperator(UnaryOperatorKind.BoolLogicalNegation, syntax, method: null, constrainedToTypeOpt: null, loweredLeft, loweredLeft.Type);
577Debug.Assert(loweredLeft.Type is { });
578whenNullOpt = RewriteLiftedBinaryOperator(syntax, operatorKind, _factory.Default(loweredLeft.Type), loweredRight, type, method, constrainedToTypeOpt);
588type: result.Type!
771conversion = _compilation.Conversions.ClassifyConversionFromType(loweredLeft.Type, parameterType, isChecked: operatorKind.IsChecked(), ref useSiteInfo);
909Debug.Assert(expression.Type is { });
913if (expression.Type.IsNullableType())
919UnsafeGetNullableMethod(syntax, expression.Type, SpecialMember.System_Nullable_T_GetValueOrDefault));
932Debug.Assert(expression.Type is { });
936if (expression.Type.IsNullableType())
946Debug.Assert(expression.Type is { });
951UnsafeGetNullableMethod(syntax, expression.Type, SpecialMember.System_Nullable_T_get_HasValue));
1634Debug.Assert(TypeSymbol.Equals(conditional.Type, conditional.Consequence.Type, TypeCompareKind.ConsiderEverything2));
1635Debug.Assert(TypeSymbol.Equals(conditional.Type, conditional.Alternative.Type, TypeCompareKind.ConsiderEverything2));
1708Debug.Assert(alwaysNull.Type is { });
1709BoundExpression nullBool = new BoundDefaultExpression(syntax, alwaysNull.Type);
1721rewrittenType: alwaysNull.Type,
1748rewrittenType: alwaysNull.Type,
1750Debug.Assert(conditionalExpression.Type is { });
1756type: conditionalExpression.Type);
1810rewrittenType: newNullBool.Type!,
1817type: conditionalExpression.Type!);
1897rewrittenType: alternative.Type!,
1905type: conditionalExpression.Type!);
2003return conditionalAccess.Update(conditionalAccess.Receiver, conditionalAccess.HasValueMethodOpt, whenNotNull, whenNull, conditionalAccess.Id, conditionalAccess.ForceCopyOfNullableValueType, whenNotNull.Type!);
2059Debug.Assert(loweredLeft.Type is { SpecialType: SpecialType.System_Decimal });
2060Debug.Assert(loweredRight.Type is { SpecialType: SpecialType.System_Decimal });
2093TypeSymbol? exprType = rewrittenExpr.Type;
2156Debug.Assert(loweredRight.Type is { });
2157TypeSymbol rightType = loweredRight.Type;
2223Debug.Assert(loweredLeft.Type is { });
2224TypeSymbol leftType = loweredLeft.Type;
2228Debug.Assert(loweredRight.Type is { });
2229TypeSymbol rightType = loweredRight.Type;
2279Debug.Assert(loweredLeft.Type is { TypeKind: TypeKind.Pointer });
2280loweredRight = MakeSizeOfMultiplication(loweredRight, (PointerTypeSymbol)loweredLeft.Type, kind.IsChecked());
2284Debug.Assert(loweredRight.Type is { TypeKind: TypeKind.Pointer });
2285loweredLeft = MakeSizeOfMultiplication(loweredLeft, (PointerTypeSymbol)loweredRight.Type, kind.IsChecked());
2324Debug.Assert(sizeOfExpression.Type is { SpecialType: SpecialType.System_Int32 });
2334Debug.Assert(numericOperand.Type is { });
2335var numericSpecialType = numericOperand.Type.SpecialType;
2471Debug.Assert(loweredLeft.Type is { TypeKind: TypeKind.Pointer });
2472Debug.Assert(loweredRight.Type is { TypeKind: TypeKind.Pointer });
2475PointerTypeSymbol pointerType = (PointerTypeSymbol)loweredLeft.Type;
Lowering\LocalRewriter\LocalRewriter_CollectionExpression.cs (29)
180Debug.Assert(singleSpread.Expression.Type is not null);
182if (!ShouldUseIEnumerableBulkAddMethod(singleSpread.Expression.Type, toListOfElementType.Parameters[0].Type, singleSpread.EnumeratorInfoOpt?.GetEnumeratorInfo.Method))
228Elements: [BoundCollectionExpressionSpreadElement { Expression: { Type: NamedTypeSymbol spreadType } expr }],
409Debug.Assert(list.Type is { });
410Debug.Assert((object)list.Type.OriginalDefinition == _compilation.GetWellKnownType(WellKnownType.System_Collections_Generic_List_T));
432var listToArray = ((MethodSymbol)_factory.WellKnownMember(WellKnownMember.System_Collections_Generic_List_T__ToArray)).AsMember((NamedTypeSymbol)list.Type);
445assertTypesAreCompatible(_compilation, arrayValue.Type!, spanConstructor.Parameters[0].Type, isReadOnlySpan);
473Debug.Assert(list.Type is { });
474Debug.Assert((object)list.Type.OriginalDefinition == _compilation.GetWellKnownType(WellKnownType.System_Collections_Generic_List_T));
476var listToArray = ((MethodSymbol)_factory.WellKnownMember(WellKnownMember.System_Collections_Generic_List_T__ToArray)).AsMember((NamedTypeSymbol)list.Type);
836var spreadTypeOriginalDefinition = spreadExpression.Type!.OriginalDefinition;
842return _factory.Call(rewrittenSpreadExpression, listToArrayMethod.AsMember((NamedTypeSymbol)spreadExpression.Type!));
852&& ShouldUseIEnumerableBulkAddMethod(spreadExpression.Type!, linqToArrayMethod.Parameters[0].Type, spreadElement.EnumeratorInfoOpt?.GetEnumeratorInfo.Method))
859&& TryGetSpanConversion(spreadExpression.Type, writableOnly: false, out var asSpanMethod))
861var spanType = CallAsSpanMethod(spreadExpression, asSpanMethod).Type!.OriginalDefinition;
866return _factory.Call(rewrittenSpreadExpression, toArrayMethod.AsMember((NamedTypeSymbol)rewrittenSpreadExpression.Type!));
969Debug.Assert(arrayTemp.Type is ArrayTypeSymbol);
972var elementType = ((ArrayTypeSymbol)arrayTemp.Type).ElementType;
1100var type = expression.Type;
1167if (spreadOperandAsSpan.Type!.OriginalDefinition.Equals(this._compilation.GetWellKnownType(wellKnownSpanType))
1206var spreadLength = _factory.Call(spreadOperandAsSpan, getLengthMethod.AsMember((NamedTypeSymbol)spreadOperandAsSpan.Type!));
1207var targetSlice = _factory.Call(spanTemp, spanSliceMethod.AsMember((NamedTypeSymbol)spanTemp.Type!), indexTemp, spreadLength);
1208sideEffects.Add(_factory.Call(spreadOperandAsSpan, copyToMethod.AsMember((NamedTypeSymbol)spreadOperandAsSpan.Type!), targetSlice));
1345Debug.Assert(spanTemp.Type is NamedTypeSymbol);
1348var elementType = ((NamedTypeSymbol)spanTemp.Type).TypeArgumentsWithAnnotationsNoUseSiteDiagnostics[0].Type;
1415Debug.Assert(rewrittenSpreadOperand.Type is not null);
1420if (!ShouldUseIEnumerableBulkAddMethod(rewrittenSpreadOperand.Type, addRangeMethod.Parameters[0].Type, spreadElement.EnumeratorInfoOpt?.GetEnumeratorInfo.Method))
1555_factory.Binary(BinaryOperatorKind.Addition, sum.Type!, sum, value);
1590if (convertedExpression.Operand.Type is ArrayTypeSymbol arrayType)
Lowering\LocalRewriter\LocalRewriter_CompoundAssignmentOperator.cs (40)
24Debug.Assert(TypeSymbol.Equals(node.Right.Type, node.Operator.RightType, TypeCompareKind.ConsiderEverything2));
39Debug.Assert(node.LeftConversion is null || (node.Left.Type!.IsReferenceType && node.Operator.Method.IsExtensionBlockMember()));
53TypeSymbol? leftType = node.Left.Type; // type of the target
153Debug.Assert(rewrittenAssignment.Type is { });
156var condition = _factory.Conditional(isEvent, invokeEventAccessor.ToExpression(), rewrittenAssignment, rewrittenAssignment.Type);
158rewrittenAssignment = new BoundSequence(node.Syntax, eventTemps.ToImmutableAndFree(), sequence.ToImmutableAndFree(), condition, condition.Type!);
165Debug.Assert(rewrittenAssignment.Type is { });
173rewrittenAssignment.Type);
216Debug.Assert(node.Left.Type is { });
228Debug.Assert(TypeSymbol.Equals(transformedLHS.Type, node.Left.Type, TypeCompareKind.AllIgnoreOptions));
236Debug.Assert(assignment.Type is { });
237return new BoundSequence(syntax, [binaryResult.LocalSymbol], [assignmentToTemp], assignment, assignment.Type);
293Debug.Assert(rewrittenReceiver.Type is { });
302(rewrittenReceiver.Type.IsValueType &&
303(rewrittenReceiver is not BoundArrayAccess { Expression.Type: var arrayType } || IsInvariantArray(arrayType))));
315var variableRepresentsLocation = rewrittenReceiver.Type.IsValueType || rewrittenReceiver.Type.Kind == SymbolKind.TypeParameter;
318rewrittenReceiver is BoundArrayAccess { Expression.Type: var arrayType } &&
320rewrittenReceiver.Type.IsReferenceType)
329isKnownToReferToTempIfReferenceType = !variableRepresentsLocation || rewrittenReceiver.Type.IsValueType ||
343!IsInvariantArray(arrayAccess.Expression.Type))
345Debug.Assert(!rewrittenReceiver.Type.IsReferenceType);
346Debug.Assert(!rewrittenReceiver.Type.IsValueType);
347Debug.Assert(rewrittenReceiver.Type.IsTypeParameter());
582indexerAccess.Argument.Type,
589throw ExceptionUtilities.UnexpectedValue(indexerAccess.Argument.Type);
613if (isDynamicAssignment || !IsInvariantArray(arrayAccess.Expression.Type))
641Debug.Assert(receiver is { Type: { } });
646else if (!receiver.Type.IsReferenceType)
651Debug.Assert(receiver.Type.IsReferenceType);
655Debug.Assert(rewrittenReceiver.Type is { });
656if (rewrittenReceiver.Type.IsTypeParameter())
794Debug.Assert(Binder.IsWellKnownSystemIndex(implicitIndexerAccess.Argument.Type, _compilation)
795|| Binder.IsWellKnownSystemRange(implicitIndexerAccess.Argument.Type, _compilation));
824if (isDynamicAssignment || !IsInvariantArray(arrayAccess.Expression.Type))
1006var type = expression.Type;
1022var type = expression.Type;
1078Debug.Assert(expression.Type is { });
1079if (expression.Type.IsNullableType())
Lowering\LocalRewriter\LocalRewriter_Conversion.cs (76)
82Debug.Assert(result.Type!.Equals(toType, TypeCompareKind.IgnoreDynamicAndTupleNames | TypeCompareKind.IgnoreNullableModifiersForReferenceTypes));
94Debug.Assert(node.Type is not null);
95Debug.Assert(_compilation.IsReadOnlySpanType(node.Type));
96var byteType = ((NamedTypeSymbol)node.Type).TypeArgumentsWithAnnotationsNoUseSiteDiagnostics.Single().Type;
111result = BadExpression(node.Syntax, node.Type, ImmutableArray<BoundExpression>.Empty);
115result = new BoundObjectCreationExpression(node.Syntax, ctor.AsMember((NamedTypeSymbol)node.Type), utf8Bytes, _factory.Literal(0), _factory.Literal(length));
224Debug.Assert(rewrittenNode.Type is { });
225var type = rewrittenNode.Type;
271Debug.Assert(result.Type is { } rt && rt.Equals(rewrittenType, TypeCompareKind.AllIgnoreOptions));
290type: result.Type);
313@checked = @checked && NeedsCheckedConversionInExpressionTree(rewrittenOperand.Type, rewrittenType, explicitCastInCode);
319Debug.Assert(rewrittenOperand.Type is { });
332if (_inExpressionLambda || !rewrittenOperand.Type.Equals(rewrittenType, TypeCompareKind.ConsiderEverything))
433Debug.Assert(rewrittenOperand.Type is { });
439if (rewrittenType.SpecialType == SpecialType.System_Decimal || rewrittenOperand.Type.SpecialType == SpecialType.System_Decimal)
441return RewriteDecimalConversion(syntax, rewrittenOperand, rewrittenOperand.Type, rewrittenType, @checked, conversion.Kind.IsImplicitConversion(), constantValueOpt);
448Debug.Assert(rewrittenOperand.Type is { });
451Debug.Assert(rewrittenOperand.Type.Equals(rewrittenType, TypeCompareKind.IgnoreDynamicAndTupleNames | TypeCompareKind.IgnoreNullableModifiersForReferenceTypes));
494Debug.Assert(rewrittenOperand.Type is { });
504Debug.Assert(rewrittenOperand.Type.IsEnumType());
505var underlyingTypeFrom = rewrittenOperand.Type.GetEnumUnderlyingType()!;
509else if (rewrittenOperand.Type.SpecialType == SpecialType.System_Decimal)
517var rewrittenNode = RewriteDecimalConversion(syntax, rewrittenOperand, rewrittenOperand.Type, underlyingTypeTo, @checked, isImplicit: false, constantValueOpt: constantValueOpt);
563(symbolOpt.IsAbstract || symbolOpt.IsVirtual) ? mg.ReceiverOpt?.Type : null,
602Debug.Assert(rewrittenOperand.Type is not null);
617createSpan = createSpan.Construct(rewrittenOperand.Type, spanType.TypeArgumentsWithAnnotationsNoUseSiteDiagnostics.Single().Type);
618_ = rewrittenOperand.Type.HasInlineArrayAttribute(out int length);
626var sourceType = rewrittenOperand.Type;
643Debug.Assert(rewrittenOperand.Type?.IsSZArray() == true);
670Debug.Assert(implicitOperator.ParameterTypesWithAnnotations[0].Type.Equals(rewrittenOperand.Type, TypeCompareKind.AllIgnoreOptions));
704Debug.Assert(method.ParameterTypesWithAnnotations[0].Type.Equals(rewrittenOperand.Type, TypeCompareKind.AllIgnoreOptions));
720Debug.Assert(rewrittenOperand.Type?.IsStringType() == true);
832Debug.Assert(rewrittenOperand.Type is { });
834Conversion conversion = compilation.Conversions.ClassifyConversionFromType(rewrittenOperand.Type, rewrittenType, isChecked: @checked, ref useSiteInfo);
840rewrittenOperand.Type.SpecialType != SpecialType.System_Decimal &&
841rewrittenOperand.Type.SpecialType != SpecialType.System_DateTime)
847rewrittenOperand.Type,
893if (!TypeSymbol.Equals(rewrittenOperand.Type, conversion.BestUserDefinedConversionAnalysis.FromType, TypeCompareKind.ConsiderEverything2))
903if (!TypeSymbol.Equals(rewrittenOperand.Type, conversion.Method.GetParameterType(0), TypeCompareKind.ConsiderEverything2))
916Debug.Assert(rewrittenOperand.Type is { });
917if (rewrittenOperand.Type.IsNullableType() &&
918conversion.Method.GetParameterType(0).Equals(rewrittenOperand.Type.GetNullableUnderlyingType(), TypeCompareKind.AllIgnoreOptions) &&
922userDefinedConversionRewrittenType = ((NamedTypeSymbol)rewrittenOperand.Type.OriginalDefinition).Construct(userDefinedConversionRewrittenType);
932if (!TypeSymbol.Equals(userDefined.Type, conversion.BestUserDefinedConversionAnalysis.ToType, TypeCompareKind.ConsiderEverything2))
941if (!TypeSymbol.Equals(userDefined.Type, rewrittenType, TypeCompareKind.ConsiderEverything2))
968if (!TypeSymbol.Equals(rewrittenOperand.Type, analysis.FromType, TypeCompareKind.AllIgnoreOptions))
979Debug.Assert(TypeSymbol.Equals(rewrittenOperand.Type, analysis.Operator.GetParameterType(0), TypeCompareKind.AllIgnoreOptions));
986Debug.Assert(TypeSymbol.Equals(rewrittenOperand.Type, analysis.ToType, TypeCompareKind.AllIgnoreOptions));
988if (!TypeSymbol.Equals(rewrittenOperand.Type, rewrittenType, TypeCompareKind.AllIgnoreOptions))
999Debug.Assert(TypeSymbol.Equals(rewrittenOperand.Type, rewrittenType, TypeCompareKind.AllIgnoreOptions));
1023Debug.Assert(rewrittenOperand.Type is { });
1027var tupleTypeSymbol = (NamedTypeSymbol)rewrittenOperand.Type;
1064Debug.Assert(expression.Type is { });
1065if (!expression.Type.IsNullableType())
1077when convertedArgument.Type!.Equals(expression.Type.StrippedType(), TypeCompareKind.AllIgnoreOptions):
1082when underlying.Length == 1 && underlying[0].Kind == ConversionKind.ImplicitTuple && !convertedArgument.Type!.IsNullableType():
1118TypeSymbol? rewrittenOperandType = rewrittenOperand.Type;
1168Debug.Assert(rewrittenOperand.Type is { });
1169TypeSymbol rewrittenOperandType = rewrittenOperand.Type;
1383Debug.Assert(TypeSymbol.Equals(conditional.Type, conditional.Consequence.Type, TypeCompareKind.ConsiderEverything2));
1384Debug.Assert(TypeSymbol.Equals(conditional.Type, conditional.Alternative.Type, TypeCompareKind.ConsiderEverything2));
1416Debug.Assert(rewrittenOperand.Type is { });
1417if (rewrittenOperand.Type.IsNullableType())
1420if (parameterType.Equals(rewrittenOperand.Type.GetNullableUnderlyingType(), TypeCompareKind.AllIgnoreOptions) &&
1436if ((rewrittenOperand.Type.IsArray()) && _compilation.IsReadOnlySpanType(rewrittenType))
1448Debug.Assert(TypeSymbol.Equals(result.Type, rewrittenType, TypeCompareKind.ConsiderEverything2));
1471Debug.Assert(rewrittenOperand.Type is { });
1474Conversion conv = TryMakeConversion(syntax, conversion, rewrittenOperand.Type, rewrittenType, @checked: @checked);
1488Debug.Assert(rewrittenOperand.Type.IsNullableType());
1561Debug.Assert(rewrittenOperand.Type is { });
1563Debug.Assert(conversion.Method.Parameters[0].Type.Equals(rewrittenOperand.Type, TypeCompareKind.AllIgnoreOptions));
1604Debug.Assert(rewrittenOperand.Type is { });
1607TypeSymbol source = rewrittenOperand.Type;
1830Debug.Assert(operand.Type is { });
1831return RewriteDecimalConversionCore(syntax, operand, operand.Type, toType, isImplicit, constantValueOpt);
Lowering\LocalRewriter\LocalRewriter_IndexerAccess.cs (48)
124Debug.Assert(oldNode.Type is not null);
125Debug.Assert(oldNode.Type.Equals(type, TypeCompareKind.ConsiderEverything));
220Debug.Assert(call.Type is not null);
235call.Type);
244Debug.Assert(node.Expression.Type is object);
245Debug.Assert(node.Argument.Type is object);
260_ = node.Expression.Type.HasInlineArrayAttribute(out int length);
262if (node.Argument.Type.SpecialType == SpecialType.System_Int32)
270if (Binder.IsWellKnownSystemIndex(node.Argument.Type, _compilation))
282Debug.Assert(Binder.IsWellKnownSystemRange(node.Argument.Type, _compilation));
388Debug.Assert(node.Expression.Type is object);
400return createSpan.Construct(node.Expression.Type, node.Expression.Type.TryGetInlineArrayElementField()!.Type);
405Debug.Assert(node.Expression.Type is object);
406Debug.Assert(index.Type?.SpecialType == SpecialType.System_Int32);
408var intType = (NamedTypeSymbol)index.Type;
427elementRef = elementRef.Construct(node.Expression.Type, node.Expression.Type.TryGetInlineArrayElementField()!.Type);
446elementRef = elementRef.Construct(node.Expression.Type, node.Expression.Type.TryGetInlineArrayElementField()!.Type);
500var argumentType = node.Argument.Type;
546node.Argument.Type,
563Debug.Assert(receiver.Type is { });
569RefKind refKind = receiver.Type.IsReferenceType ? RefKind.None : RefKind.Ref;
573!IsInvariantArray(arrayAccess.Expression.Type))
575Debug.Assert(!receiver.Type.IsReferenceType);
576Debug.Assert(!receiver.Type.IsValueType);
577Debug.Assert(receiver.Type.IsTypeParameter());
613Debug.Assert(capturedReceiver.Type is { IsReferenceType: false, IsValueType: false });
670Debug.Assert(integerArgument.Type!.SpecialType == SpecialType.System_Int32);
766Debug.Assert(loweredExpr.Type!.SpecialType == SpecialType.System_Int32);
777Debug.Assert(loweredExpr.Type!.SpecialType == SpecialType.System_Int32);
783Debug.Assert(Binder.IsWellKnownSystemIndex(loweredExpr.Type, _compilation));
814unloweredExpr.Type,
822Debug.Assert(hatExpression.Operand is { Type: { SpecialType: SpecialType.System_Int32 } });
826else if (unloweredExpr is BoundConversion { Operand: { Type: { SpecialType: SpecialType.System_Int32 } } operand })
835arguments[0] is { Type.SpecialType: SpecialType.System_Int32, ConstantValueOpt.Value: int _ and >= 0 } index &&
836arguments[1] is { Type.SpecialType: SpecialType.System_Boolean, ConstantValueOpt.Value: bool fromEnd })
875Debug.Assert(receiver.Type is not null);
877? !receiver.Type.IsValueType
886Debug.Assert(Binder.IsWellKnownSystemRange(node.Argument.Type, _compilation));
910Debug.Assert(receiver.Type is { });
916RefKind refKind = receiver.Type.IsReferenceType ? RefKind.None : RefKind.Ref;
920!IsInvariantArray(arrayAccess.Expression.Type))
922Debug.Assert(!receiver.Type.IsReferenceType);
923Debug.Assert(!receiver.Type.IsValueType);
924Debug.Assert(receiver.Type.IsTypeParameter());
959Debug.Assert(capturedReceiver.Type is { IsReferenceType: false, IsValueType: false });
Lowering\LocalRewriter\LocalRewriter_NullCoalescingAssignmentOperator.cs (18)
16Debug.Assert(node.Type is { });
20Debug.Assert(node.LeftOperand.Type is { });
24Debug.Assert(transformedLHS.Type is { });
41Debug.Assert(TypeSymbol.Equals(transformedLHS.Type, node.LeftOperand.Type, TypeCompareKind.AllIgnoreOptions));
50Debug.Assert(assignment.Type is { });
51assignment = new BoundSequence(syntax, [rightResult.LocalSymbol], [assignmentToTemp], assignment, assignment.Type);
59var leftPlaceholder = new BoundValuePlaceholder(lhsRead.Syntax, lhsRead.Type);
60BoundExpression conditionalExpression = MakeNullCoalescingOperator(syntax, lhsRead, assignment, leftPlaceholder: leftPlaceholder, leftConversion: leftPlaceholder, BoundNullCoalescingOperatorResultKind.LeftType, node.LeftOperand.Type);
61Debug.Assert(conditionalExpression.Type is { });
75conditionalExpression.Type);
82Debug.Assert(node.LeftOperand.Type.IsNullableType());
91leftOperand.Type,
101leftOperand.Type,
136Debug.Assert(transformedLHS.Type.GetNullableUnderlyingType().Equals(tmp.Type.StrippedType(), TypeCompareKind.AllIgnoreOptions));
140Debug.Assert(TypeSymbol.Equals(transformedLHS.Type, node.LeftOperand.Type, TypeCompareKind.AllIgnoreOptions));
145MakeConversionNode(tmp, transformedLHS.Type, @checked: false, markAsChecked: true),
Lowering\LocalRewriter\LocalRewriter_NullCoalescingOperator.cs (18)
35Debug.Assert(rewrittenRight.Type is { });
36Debug.Assert(rewrittenRight.Type.Equals(rewrittenResultType, TypeCompareKind.IgnoreDynamicAndTupleNames | TypeCompareKind.IgnoreNullableModifiersForReferenceTypes));
42Debug.Assert(rewrittenLeft.Type is { });
59var isUnconstrainedTypeParameter = rewrittenLeft.Type is { IsReferenceType: false, IsValueType: false };
90Debug.Assert(rewrittenLeft.Type is { });
91if (rewrittenLeft.Type.IsReferenceType &&
110if (whenNullOpt.Type.IsNullableType())
115if (whenNullOpt.IsDefaultValue() && whenNullOpt.Type.SpecialType != SpecialType.System_Decimal)
133if (rewrittenLeft.Type.IsNullableType() &&
134rewrittenRight.Type.Equals(rewrittenLeft.Type.GetNullableUnderlyingType(), TypeCompareKind.AllIgnoreOptions))
140TryGetNullableMethod(rewrittenLeft.Syntax, rewrittenLeft.Type, SpecialMember.System_Nullable_T_GetValueOrDefault, out MethodSymbol? getValueOrDefault, isOptional: true))
147TryGetNullableMethod(rewrittenLeft.Syntax, rewrittenLeft.Type, SpecialMember.System_Nullable_T_GetValueOrDefaultDefaultValue, out MethodSymbol? getValueOrDefaultDefaultValue, isOptional: true))
167Debug.Assert(convertedLeft.HasErrors || convertedLeft.Type!.Equals(rewrittenResultType, TypeCompareKind.IgnoreDynamicAndTupleNames | TypeCompareKind.IgnoreNullableModifiersForReferenceTypes));
180Debug.Assert(conditionalExpression.Type!.Equals(rewrittenResultType, TypeCompareKind.IgnoreDynamicAndTupleNames | TypeCompareKind.IgnoreNullableModifiersForReferenceTypes));
238Debug.Assert(rewrittenLeft.Type is { });
242TypeSymbol rewrittenLeftType = rewrittenLeft.Type;
250var conversionTakesNullableType = leftPlaceholder?.Type?.IsNullableType() == true;
Lowering\LocalRewriter\LocalRewriter_ObjectOrCollectionInitializerExpression.cs (6)
400Debug.Assert(assignment.Type.IsDynamic() || TypeSymbol.Equals(rewrittenAccess.Type, assignment.Type, TypeCompareKind.AllIgnoreOptions));
454Debug.Assert(Binder.IsWellKnownSystemRange(rangeArgument.Type, _compilation));
472Debug.Assert(TypeSymbol.Equals(rewrittenAccess.Type, assignment.Type, TypeCompareKind.AllIgnoreOptions));
505Debug.Assert(TypeSymbol.Equals(rewrittenAccess.Type, assignment.Type, TypeCompareKind.AllIgnoreOptions));
517if (TypeSymbol.Equals(implicitIndexer.Argument.Type, _compilation.GetWellKnownType(WellKnownType.System_Index), TypeCompareKind.ConsiderEverything))
540Debug.Assert(TypeSymbol.Equals(rewrittenAccess.Type, assignment.Type, TypeCompareKind.AllIgnoreOptions));
Lowering\LocalRewriter\LocalRewriter_StringConcat.cs (20)
75Debug.Assert(visitedArguments.All(arg => arg.Type!.SpecialType is SpecialType.System_String or SpecialType.System_Char or SpecialType.System_Object));
107var argumentType = arg.Type;
153bool needsImplicitConversionFromStringToSpan = visitedArguments.Any(arg => arg.Type is { SpecialType: SpecialType.System_String });
289if (argument is BoundConversion { ConversionKind: ConversionKind.Boxing, Type.SpecialType: SpecialType.System_Object, Operand: { Type.SpecialType: SpecialType.System_Char } operand })
305else if (argument is BoundNullCoalescingOperator { LeftOperand: { Type.SpecialType: SpecialType.System_String } left, RightOperand: BoundLiteral { ConstantValueOpt: { IsString: true, RopeValue.IsEmpty: true } } })
444if (call is { Arguments: [], ReceiverOpt.Type: NamedTypeSymbol { SpecialType: SpecialType.System_Char } charType, Method: { Name: "ToString" } method }
521Debug.Assert(arg.Type is not null);
523if (arg.Type.SpecialType == SpecialType.System_Char)
552Debug.Assert(arg.HasAnyErrors || arg.Type.SpecialType == SpecialType.System_String);
652Debug.Assert(expr.Type is not null);
655if (expr.Type.IsStringType())
667if (expr.Type.IsValueType && !expr.Type.IsTypeParameter())
669var type = (NamedTypeSymbol)expr.Type;
690expr.Type.SpecialType.CanOptimizeBehavior() &&
706bool callWithoutCopy = expr.Type.IsReferenceType ||
708(structToStringMethod == null && !expr.Type.IsTypeParameter()) ||
712if (expr.Type.IsValueType)
716expr = new BoundPassByCopy(syntax, expr, expr.Type);
748new BoundConditionalReceiver(syntax, currentConditionalAccessID, expr.Type),
Lowering\LocalRewriter\LocalRewriter_StringInterpolation.cs (9)
107if (actualCall.Type!.IsDynamic())
145Debug.Assert(node.Type is { SpecialType: SpecialType.System_String }); // if target-converted, we should not get here.
149return LowerPartsToString(data, node.Parts, node.Syntax, node.Type);
183_factory.Binary(BinaryOperatorKind.StringConcatenation, node.Type, result, part);
194Debug.Assert(result.Type is not null);
195Debug.Assert(result.Type.SpecialType == SpecialType.System_String || result.Type.IsErrorType());
196var placeholder = new BoundValuePlaceholder(result.Syntax, result.Type);
197result = new BoundNullCoalescingOperator(result.Syntax, result, _factory.StringLiteral(""), leftPlaceholder: placeholder, leftConversion: placeholder, BoundNullCoalescingOperatorResultKind.LeftType, @checked: false, result.Type) { WasCompilerGenerated = true };
Lowering\LocalRewriter\LocalRewriter_TupleBinaryOperator.cs (32)
54Debug.Assert(expr.Type == (object?)o.Type || expr.Type is { } && expr.Type.Equals(o.Type, TypeCompareKind.AllIgnoreOptions));
91expr.Type is { } exprType && exprType.IsNullableType() && exprType.StrippedType().Equals(o.Type, TypeCompareKind.AllIgnoreOptions):
108Debug.Assert(expr.Type is { });
109var destElementTypes = expr.Type.TupleElementTypesWithAnnotations;
111Debug.Assert(boundConversion.Operand.Type is { });
112var srcElementFields = boundConversion.Operand.Type.TupleElements;
130ImmutableArray<bool>.Empty, expr.Type, expr.HasErrors);
166ImmutableArray<bool>.Empty, tuple.Type, tuple.HasErrors);
209return new BoundLiteral(expr.Syntax, ConstantValue.Null, expr.Type);
362isNullable = !(expr is BoundTupleExpression) && expr.Type is { } && expr.Type.IsNullableType();
374Debug.Assert(expr.Type is { });
377value = new BoundDefaultExpression(expr.Syntax, expr.Type.StrippedType());
404Debug.Assert(expr.Type is { });
410when expr.Type.IsNullableType() && o.Type is { } && o.Type.IsNullableType() &&
445expr.Type is { } exprType && exprType.IsNullableType() && o.Type is { } && o.Type.IsNullableType() && nested[0] is { IsTupleConversion: true } tupleConversion:
447Debug.Assert(expr.Type is { });
450Debug.Assert(operand.Type is { });
451var types = expr.Type.GetNullableUnderlyingType().TupleElementTypesWithAnnotations;
452int tupleCardinality = operand.Type.TupleElementTypesWithAnnotations.Length;
468type: expr.Type,
531Debug.Assert(tuple.Type is { IsTupleType: true });
537return MakeTupleFieldAccessAndReportUseSiteDiagnostics(tuple, tuple.Syntax, tuple.Type.TupleElements[i]);
Lowering\LocalRewriter\LocalRewriter_UnaryOperator.cs (27)
133var underlyingType = loweredOperand.Type.GetEnumUnderlyingType();
277Debug.Assert(result.Type is { });
286type: result.Type
329Debug.Assert(TypeSymbol.Equals(conditional.Type, conditional.Consequence.Type, TypeCompareKind.ConsiderEverything2));
330Debug.Assert(TypeSymbol.Equals(conditional.Type, conditional.Alternative.Type, TypeCompareKind.ConsiderEverything2));
408Debug.Assert(node.OperandConversion is null || (node.Operand.Type!.IsReferenceType && node.MethodOpt.IsExtensionBlockMember()));
421TypeSymbol? operandType = node.Operand.Type; //type of the variable being incremented
458TypeSymbol? operandType = left.Type; //type of the variable being incremented
467Debug.Assert(TypeSymbol.Equals(operandType, transformedLHS.Type, TypeCompareKind.AllIgnoreOptions));
587TypeSymbol? operandType = transformedLHS.Type; //type of the variable being incremented
661Debug.Assert(boundTemp.Type is not null);
688type: boundTemp.Type);
701Debug.Assert(boundTemp.Type is not null);
704Debug.Assert(tempValue.Type is { });
713tempValue.Type);
727type: boundTemp.Type);
933Debug.Assert(binaryOperand.Type is { TypeKind: TypeKind.Pointer });
934Debug.Assert(boundOne.Type is { SpecialType: SpecialType.System_Int32 });
935return MakeBinaryOperator(node.Syntax, binaryOperatorKind, binaryOperand, boundOne, binaryOperand.Type, method: null, constrainedToTypeOpt: null);
987Debug.Assert(operand.Type is { SpecialType: SpecialType.System_Decimal });
994Debug.Assert(operand.Type is { } && operand.Type.IsNullableType() && operand.Type.GetNullableUnderlyingType().SpecialType == SpecialType.System_Decimal);
998MethodSymbol getValueOrDefault = UnsafeGetNullableMethod(syntax, operand.Type, SpecialMember.System_Nullable_T_GetValueOrDefault);
999MethodSymbol ctor = UnsafeGetNullableMethod(syntax, operand.Type, SpecialMember.System_Nullable_T__ctor);
1010BoundExpression alternative = new BoundDefaultExpression(syntax, operand.Type);
1013return RewriteConditionalOperator(syntax, condition, consequence, alternative, ConstantValue.NotAvailable, operand.Type, isRef: false);
Lowering\LocalRewriter\LocalRewriter.PatternLocalRewriter.cs (23)
214TypeSymbol inputType = input.Type;
228Conversion conversion = _factory.Compilation.Conversions.ClassifyBuiltInConversion(inputType, output.Type, isChecked: false, ref useSiteInfo);
237inputType.GetNullableUnderlyingType().Equals(output.Type, TypeCompareKind.AllIgnoreOptions) &&
369Debug.Assert(input.Type is { });
373return MakeNullCheck(d.Syntax, input, input.Type.IsNullableType() ? BinaryOperatorKind.NullableNullNotEqual : BinaryOperatorKind.NotEqual);
380return MakeNullCheck(d.Syntax, input, input.Type.IsNullableType() ? BinaryOperatorKind.NullableNullEqual : BinaryOperatorKind.Equal);
383Debug.Assert(!input.Type.IsNullableType());
387Debug.Assert(!input.Type.IsNullableType());
388Debug.Assert(input.Type.IsValueType);
398Debug.Assert(!rewrittenExpr.Type.IsSpanOrReadOnlySpanChar());
400if (rewrittenExpr.Type.IsPointerOrFunctionPointer())
418if (value.IsString && input.Type.IsSpanOrReadOnlySpanChar())
423TypeSymbol comparisonType = input.Type.EnumUnderlyingTypeOrSelf();
432if (input.Type.SpecialType == SpecialType.System_Double && double.IsNaN(value.DoubleValue) ||
433input.Type.SpecialType == SpecialType.System_Single && float.IsNaN(value.SingleValue))
439BoundExpression literal = _localRewriter.MakeLiteral(syntax, value, input.Type);
440TypeSymbol comparisonType = input.Type.EnumUnderlyingTypeOrSelf();
468var isReadOnlySpan = input.Type.IsReadOnlySpanChar();
510Debug.Assert(output.Type is { });
512testExpression = _factory.ObjectNotEqual(output, _factory.Null(output.Type));
546Debug.Assert(loweredInput.Type is { });
587if (loweredInput.Type.IsTupleType &&
588!loweredInput.Type.OriginalDefinition.Equals(_factory.Compilation.GetWellKnownType(WellKnownType.System_ValueTuple_TRest)) &&
Lowering\SpillSequenceSpiller.cs (20)
45: base(SpillSequenceBuilderKind, syntax, value?.Type)
337if (refKind != RefKind.None || expression.Type?.IsRefLikeOrAllowsRefLikeType() == true)
380if (refKind != RefKind.None || expression.Type.IsReferenceType)
497if (expression.Type.IsVoidType() || sideEffectsOnly)
564&& valueTypeReceiver.Type.Equals(receiverRefLocal.Type, TypeCompareKind.AllIgnoreOptions)
1104Debug.Assert(refKind == RefKind.None || !receiver.Type.IsReferenceType);
1108!LocalRewriter.IsInvariantArray(arrayAccess.Expression.Type))
1124var receiverType = receiver.Type;
1158if (!receiver.Type.IsReferenceType && LocalRewriter.CanBePassedByReference(receiver))
1160result = receiver.Type.IsReadOnly ? RefKind.In : RefKind.Ref;
1231Debug.Assert(condition.Type.SpecialType == SpecialType.System_Boolean);
1234var tmp = _F.SynthesizedLocal(condition.Type, kind: SynthesizedLocalKind.Spill, syntax: _F.Syntax);
1281type: node.Type));
1338_F.ObjectEqual(_F.Local(tmp), _F.Null(left.Type)),
1370if (receiver.Type.IsReferenceType || receiver.Type.IsValueType || receiverRefKind == RefKind.None)
1390var clone = _F.SynthesizedLocal(receiver.Type, _F.Syntax, refKind: RefKind.None, kind: SynthesizedLocalKind.Spill);
1394var isNotClass = _F.IsNotNullReference(_F.Default(receiver.Type));
1562return UpdateExpression(builder, node.Update(operand, node.Type));
1606return UpdateExpression(builder, node.Update(expression, node.Type));
Lowering\SyntheticBoundNodeFactory.cs (51)
272Debug.Assert(receiverOpt is null || receiverOpt.Type is { } &&
273receiverOpt.Type.GetMembers(propertySym.Name).OfType<PropertySymbol>().Single() == propertySym);
284Debug.Assert(!(receiverOpt is { Type: ArrayTypeSymbol { IsSZArray: true } } &&
444Debug.Assert(left.Type is { } && right.Type is { } &&
445(left.Type.Equals(right.Type, TypeCompareKind.AllIgnoreOptions) ||
447right.Type.IsErrorType() || left.Type.IsErrorType()));
449var assignment = new BoundAssignmentOperator(syntax, left, right, isRef, left.Type, hasErrors) { WasCompilerGenerated = wasCompilerGenerated };
574var conversion = Compilation.Conversions.ClassifyConversionFromType(expression.Type, CurrentFunction.ReturnType, isChecked: false, ref useSiteInfo);
663Conversion c = Compilation.Conversions.ClassifyBuiltInConversion(operand.Type, type, isChecked: false, ref discardedUseSiteInfo);
669Debug.Assert(left.Type?.SpecialType == CodeAnalysis.SpecialType.System_Boolean);
670Debug.Assert(right.Type?.SpecialType == CodeAnalysis.SpecialType.System_Boolean);
676Debug.Assert(left.Type?.SpecialType == CodeAnalysis.SpecialType.System_Boolean);
677Debug.Assert(right.Type?.SpecialType == CodeAnalysis.SpecialType.System_Boolean);
696if (value.Type is TypeParameterSymbol { AllowsRefLikeType: true })
717if (value.Type is TypeParameterSymbol { AllowsRefLikeType: true })
827switch (input.Type)
836throw ExceptionUtilities.UnexpectedValue(input.Type);
961Debug.Assert(valueTypeReceiver.Type is { });
962Debug.Assert(TypeSymbol.Equals(valueTypeReceiver.Type, referenceTypeReceiver.Type, TypeCompareKind.ConsiderEverything2));
963return new BoundComplexConditionalReceiver(Syntax, valueTypeReceiver, referenceTypeReceiver, valueTypeReceiver.Type) { WasCompilerGenerated = true };
968Debug.Assert(left.Type!.Equals(right.Type, TypeCompareKind.IgnoreCustomModifiersAndArraySizesAndLowerBounds | TypeCompareKind.IgnoreNullableModifiersForReferenceTypes) || left.Type.IsErrorType());
969Debug.Assert(left.Type.IsReferenceType);
971return new BoundNullCoalescingOperator(Syntax, left, right, leftPlaceholder: null, leftConversion: null, BoundNullCoalescingOperatorResultKind.LeftType, @checked: false, left.Type) { WasCompilerGenerated = true };
1079Debug.Assert(result.Type is { });
1080var resultType = type ?? result.Type;
1086Debug.Assert(result.Type is { });
1090: new BoundSequence(Syntax, locals, sideEffects, result, result.Type) { WasCompilerGenerated = true };
1095Debug.Assert(result.Type is { });
1096return new BoundSpillSequence(Syntax, locals, sideEffects, result, result.Type) { WasCompilerGenerated = true };
1125Debug.Assert(ex.Type is { SpecialType: CodeAnalysis.SpecialType.System_Int32 });
1220Debug.Assert(array.Type is { TypeKind: TypeKind.Array });
1226Debug.Assert(array.Type is { TypeKind: TypeKind.Array });
1227int rank = ((ArrayTypeSymbol)array.Type).Rank;
1239Debug.Assert(array.Type is { TypeKind: TypeKind.Array });
1240return new BoundArrayAccess(Syntax, array, indices, ((ArrayTypeSymbol)array.Type).ElementType);
1545if (TypeSymbol.Equals(type, arg.Type, TypeCompareKind.ConsiderEverything2))
1555Debug.Assert(arg.Type is { });
1642return new BoundCatchBlock(Syntax, ImmutableArray<LocalSymbol>.Empty, source, source.Type, exceptionFilterPrologueOpt: null, exceptionFilterOpt: null, body: block, isSynthesizedAsyncCatchAll: false);
1662Debug.Assert(expression is { Type: { SpecialType: CodeAnalysis.SpecialType.System_Boolean } });
1663return new BoundUnaryOperator(expression.Syntax, UnaryOperatorKind.BoolLogicalNegation, expression, null, null, constrainedToTypeOpt: null, LookupResultKind.Viable, expression.Type);
1683Debug.Assert(argument.Type is { });
1716var type = argument.Type;
1786TypeSymbol exprType = rewrittenExpr.Type;
1840LocalRewriter.UnsafeGetNullableMethod(syntax, expression.Type, CodeAnalysis.SpecialMember.System_Nullable_T_get_HasValue, Compilation, Diagnostics));
1904return conditionalAccess.Update(conditionalAccess.Receiver, conditionalAccess.HasValueMethodOpt, whenNotNull, whenNull, conditionalAccess.Id, conditionalAccess.ForceCopyOfNullableValueType, whenNotNull.Type);