Binder\Binder.ValueChecks.cs (32)
944Debug.Assert(!checkingReceiver || expr.Type.IsValueType || expr.Type.IsTypeParameter());
971if ((expr.ConstantValueOpt != null) || (expr.Type.GetSpecialTypeSafe() == SpecialType.System_Void))
1161getItemOrSliceHelper = getItemOrSliceHelper.AsMember(getItemOrSliceHelper.ContainingType.Construct(ImmutableArray.Create(elementAccess.Expression.Type.TryGetInlineArrayElementField().TypeWithAnnotations)));
1233indices[0].Type,
1271Error(diagnostics, ErrorCode.ERR_BadSKunknown, expr.Syntax, expr.Type, MessageID.IDS_SK_TYPE.Localize());
1932&& receiver?.Type?.IsValueType == true;
2164if (receiver is BoundObjectOrCollectionValuePlaceholder && receiver.Type.IsAnonymousType)
2326if (methodInvocationInfo.MethodInfo.Method?.RequiresInstanceReceiver == true && methodInvocationInfo.Receiver?.Type?.IsRefLikeOrAllowsRefLikeType() == true)
2549if (receiver?.Type?.IsRefLikeOrAllowsRefLikeType() == true)
2660Debug.Assert(receiver.Type is { });
2665Debug.Assert(receiver is not BoundValuePlaceholderBase && method is not null && receiver.Type?.IsReferenceType == false);
2670receiver = new BoundCapturedReceiverPlaceholder(receiver.Syntax, receiver, receiver.Type).MakeCompilerGenerated();
2789if (receiver.Type is TypeParameterSymbol typeParameter)
3028if (argument.Type?.IsRefLikeOrAllowsRefLikeType() == true)
3088if (argument.Type?.IsRefLikeOrAllowsRefLikeType() == true)
3224&& argument.Type?.IsRefLikeOrAllowsRefLikeType() == true)
3685Debug.Assert(expr.Type is not null);
3717if (expr.Type?.GetSpecialTypeSafe() == SpecialType.System_Void)
3987Debug.Assert(!checkingReceiver || expr.Type.IsValueType || expr.Type.IsTypeParameter());
4002if (expr.Type?.GetSpecialTypeSafe() == SpecialType.System_Void)
4363if (expr.Type?.IsRefLikeOrAllowsRefLikeType() != true)
4770RoslynDebug.Assert(false, $"{expr.Kind} expression of {expr.Type} type");
5002Debug.Assert(!checkingReceiver || expr.Type.IsValueType || expr.Type.IsTypeParameter());
5023if (expr.Type?.IsRefLikeOrAllowsRefLikeType() != true)
5090Error(diagnostics, inUnsafeRegion ? ErrorCode.WRN_EscapeStackAlloc : ErrorCode.ERR_EscapeStackAlloc, node, expr.Type);
5345Error(diagnostics, ErrorCode.ERR_CollectionExpressionEscape, node, expr.Type);
5531RoslynDebug.Assert(false, $"{expr.Kind} expression of {expr.Type} type");
5704TypeWithAnnotations.Create(elementAccess.Expression.Type),
5744TypeWithAnnotations.Create(inlineArray.Type),
Binder\Binder_Await.cs (15)
32var placeholder = new BoundAwaitableValuePlaceholder(expression.Syntax, expression.Type);
87var type = expression.Type;
281Debug.Assert(TypeSymbol.Equals(expression.Type, getAwaiterArgument.Type, TypeCompareKind.ConsiderEverything));
317TypeSymbol awaiterType = getAwaiter.Type!;
318return GetIsCompletedProperty(awaiterType, node, expression.Type!, diagnostics, out isCompleted)
320&& GetGetResultMethod(getAwaiter, node, expression.Type!, diagnostics, out getResult, out getAwaiterGetResultCall)
345if (expression.Type is not NamedTypeSymbol { Arity: 0 or 1 } exprType)
372placeholder = new BoundAwaitableValuePlaceholder(expression.Syntax, expression.Type);
562if (expression.Type is null)
584RoslynDebug.Assert(expression.Type is object);
585if (expression.Type.IsVoidType())
601Error(diagnostics, ErrorCode.ERR_BadAwaitArg, node, expression.Type);
614Error(diagnostics, ErrorCode.ERR_BadAwaitArg, node, expression.Type);
698var awaiterType = awaiterExpression.Type;
Binder\Binder_Conversions.cs (39)
77else if (source.Type is not null && filterConversion(conversion))
79var placeholder2 = new BoundValuePlaceholder(source.Syntax, source.Type);
123RoslynDebug.Assert(source.Type is object);
127if (!isCast && source.Type.Equals(destination, TypeCompareKind.IgnoreNullableModifiersForReferenceTypes))
217TypeSymbol? type = source.Type;
262Debug.Assert(source.Type is null);
289source.Type is { } sourceType &&
337switch (source.Type?.IsNullableType())
342new BoundValuePlaceholder(source.Syntax, source.Type.GetNullableUnderlyingType()),
369else if (source.Type?.IsNullableType() == true)
373new BoundValuePlaceholder(source.Syntax, source.Type.GetNullableUnderlyingType()),
391if (source.Type?.TryGetElementTypesWithAnnotationsIfTupleType(out sourceTypes) == true &&
465Debug.Assert(source.Type is { });
467FieldSymbol? elementField = source.Type.TryGetInlineArrayElementField();
500CheckInlineArrayTypeIsSupported(syntax, source.Type, elementField.Type, diagnostics);
504Debug.Assert(source.Type is not null);
513if (source.Type is ArrayTypeSymbol)
524if (source.Type.IsSpan())
528TryFindImplicitOperatorFromSpan(source.Type.OriginalDefinition, destination.OriginalDefinition),
529source.Type.OriginalDefinition,
536if (source.Type.IsSpan() || source.Type.IsReadOnlySpan())
539if (NeedsSpanCastUp(source.Type, destination))
544TypeSymbol sourceForCastUp = source.Type.IsSpan()
546: source.Type.OriginalDefinition;
557.Construct([((NamedTypeSymbol)source.Type).TypeArgumentsWithAnnotationsNoUseSiteDiagnostics[0]])
563if (source.Type.IsStringType())
741unconvertedSource.Type,
1878Debug.Assert(methodGroup.ReceiverOpt.Type is not null);
1948diagnostics.Add(ErrorCode.ERR_CollectionExpressionMissingAdd, syntax, methodGroup.ReceiverOpt.Type);
2012TypeSymbol? receiverType = methodGroup.ReceiverOpt.Type;
2417Debug.Assert(targetTyped || destination.IsErrorType() || destination.Equals(source.Type, TypeCompareKind.ConsiderEverything));
2436source.Syntax, source.Type, targetTyped, source.Expression, newSwitchArms, source.ReachabilityDecisionDag,
2522Conversion toParameterTypeConversion = Conversions.ClassifyStandardConversion(convertedOperand.Type, conversionParameterType, ref useSiteInfo);
3178RoslynDebug.Assert(receiverOpt.Type is object);
3180diagnostics.Add(ErrorCode.ERR_QueryNoProvider, node.Location, receiverOpt.Type, memberSymbol.Name);
3198RoslynDebug.Assert(receiverOpt.Type is object);
3199diagnostics.Add(ErrorCode.ERR_BadAwaitArg, node.Location, receiverOpt.Type);
3334(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 (100)
223TypeSymbol resultType = expr.Type;
321var commonType = expr.Type;
401case BoundStackAllocArrayCreation { Type: null } boundStackAlloc:
602TypeSymbol exprType = expr.Type;
1019subExpressions.SelectAsArray(e => TypeWithAnnotations.Create(e.Type)),
1076if (boundArgument.Type?.SpecialType == SpecialType.System_Void)
1086var elementTypeWithAnnotations = TypeWithAnnotations.Create(boundArgument.Type);
1285if ((object)argument.Type != null && argument.Type.IsRestrictedType())
1288Error(diagnostics, ErrorCode.ERR_MethodArgCantBeRefAny, node, argument.Type);
1743type: expression.Type,
2665(object)operand.Type != null &&
2666!operand.Type.IsNullableType() &&
2667!TypeSymbol.Equals(targetType.GetNullableUnderlyingType(), operand.Type, TypeCompareKind.ConsiderEverything2))
2688if ((object)boundOperand.Type != null && boundOperand.Type.IsNullableType())
2767if (left?.Type.IsNullableType() == true || right?.Type.IsNullableType() == true)
2795if (boundOperand.Type?.IsNullableType() == true)
2887SymbolDistinguisher distinguisher1 = new SymbolDistinguisher(this.Compilation, operand.Type, targetType);
2936case BoundKind.UnconvertedConditionalOperator when operand.Type is null:
2937case BoundKind.UnconvertedSwitchExpression when operand.Type is null:
2961Debug.Assert((object)operand.Type != null);
2962SymbolDistinguisher distinguisher = new SymbolDistinguisher(this.Compilation, operand.Type, targetType);
3003Debug.Assert((object)operand.Type != null && !operand.Type.IsNullableType());
3009var underlyingConversion = Conversions.ClassifyBuiltInConversion(operand.Type, underlyingTargetTypeWithAnnotations.Type, isChecked: CheckOverflowAtRuntime, ref discardedUseSiteInfo);
3865Debug.Assert(receiver!.Type is not null);
3867placeholderType = receiver.Type;
4313if ((object)boundExpression.Type == null || !boundExpression.Type.IsErrorType())
4397Debug.Assert(init.Type.IsErrorType());
4807if (constantValue == null || constantValue.IsBad || expression.Type.SpecialType != SpecialType.System_Int32)
4830var type = expression.Type.SpecialType;
5403Debug.Assert(expression.Type is { });
5405var expressionPlaceholder = new BoundCollectionExpressionSpreadExpressionPlaceholder(syntax.Expression, expression.Type);
5418_ = expression.Type.HasInlineArrayAttribute(out int length);
5458if (arg.Type is { TypeKind: TypeKind.Dynamic })
5607else if ((object)argument.Type == null)
5619else if (argument.Type.TypeKind == TypeKind.Delegate)
5621var sourceDelegate = (NamedTypeSymbol)argument.Type;
5625if (ReportDelegateInvokeUseSiteDiagnostic(diagnostics, argument.Type, node: node))
5906Debug.Assert((object)boundLeft.Type != null);
5915type: boundLeft.Type,
6203type: boundMember.Type,
6617({ Type: null } or BoundLiteral or BoundUnconvertedInterpolatedString or BoundBinaryOperator { IsUnconvertedInterpolatedStringAddition: true }) &&
7741leftType = BindRangeVariable(left, (RangeVariableSymbol)leftSymbol, BindingDiagnosticBag.Discarded).Type;
7756if (TypeSymbol.Equals(boundType.Type, leftType, TypeCompareKind.AllIgnoreOptions))
7768Debug.Assert(leftType.Equals(boundValue.Type, TypeCompareKind.ConsiderEverything));
7786TypeSymbol.Equals(BindNamespaceOrType(id, BindingDiagnosticBag.Discarded).Type, type, TypeCompareKind.AllIgnoreOptions);
7896TypeSymbol leftType = boundLeft.Type;
7934leftType = boundLeft.Type;
8177Error(diagnostics, ErrorCode.WRN_DotOnDefault, node, boundLeft.Type);
8304var leftType = boundLeft.Type;
8439if ((object)boundLeft.Type == null)
8448Error(diagnostics, ErrorCode.ERR_NoSuchMember, name, boundLeft.Type, plainName);
8450else if (WouldUsingSystemFindExtension(boundLeft.Type, plainName))
8452Error(diagnostics, ErrorCode.ERR_NoSuchMemberOrExtensionNeedUsing, name, boundLeft.Type, plainName, "System");
8454else if (boundLeft.Kind == BoundKind.AwaitableValuePlaceholder && boundLeft.Type.IsIAsyncEnumerableType(Compilation))
8456Error(diagnostics, ErrorCode.ERR_NoAwaitOnAsyncEnumerable, name, boundLeft.Type, plainName);
8460Error(diagnostics, ErrorCode.ERR_NoSuchMemberOrExtension, name, boundLeft.Type, plainName);
8760Debug.Assert(left.Type is not null);
8761Debug.Assert(!left.Type.IsDynamic());
8853Debug.Assert(left.Type is not null);
8965TypeSymbol? receiverType = left.Type;
9097errorInfo = new CSDiagnosticInfo(ErrorCode.ERR_ExtensionResolutionFailed, left.Type, memberName);
9150TypeSymbol receiverType = receiver.Type;
9341if (receiverOpt is { Type: TypeParameterSymbol { AllowsRefLikeType: true } } &&
9383bool isUsableAsField = eventSymbol.HasAssociatedField && this.IsAccessible(eventSymbol.AssociatedField, ref useSiteInfo, (receiver != null) ? receiver.Type : null);
9623if ((object)expr.Type == null)
9644expr.Type.HasInlineArrayAttribute(out int length) && expr.Type.TryGetPossiblyUnsupportedByLanguageInlineArrayElementField() is FieldSymbol elementField)
9656Debug.Assert(expr.Type.TryGetInlineArrayElementField() is not null);
9676{ Code: (int)ErrorCode.ERR_BadIndexLHS, Arguments: [TypeSymbol type] } && type.Equals(expr.Type, TypeCompareKind.ConsiderEverything))
9803CheckInlineArrayTypeIsSupported(node, expr.Type, elementField.Type, diagnostics);
9854if (TypeSymbol.Equals(convertedIndex.Type, compilation.GetWellKnownType(WellKnownType.System_Index), TypeCompareKind.AllIgnoreOptions))
9902Debug.Assert((object)expr.Type != null);
9905var exprType = expr.Type;
9948var arrayType = (ArrayTypeSymbol)expr.Type;
9995var receiverPlaceholder = new BoundImplicitIndexerReceiverPlaceholder(expr.Syntax, isEquivalentToThisReference: expr.IsEquivalentToThisReference, expr.Type) { WasCompilerGenerated = true };
10159Debug.Assert(expr.Type.IsPointerType());
10160PointerTypeSymbol pointerType = (PointerTypeSymbol)expr.Type;
10206Debug.Assert((object)expr.Type != null);
10212this.LookupMembersWithFallback(lookupResult, expr.Type, WellKnownMemberNames.Indexer, arity: 0, useSiteInfo: ref useSiteInfo, options: lookupOptions);
10527var argType = argument.Type;
10533Debug.Assert(receiver.Type is not null);
10540var receiverPlaceholder = new BoundImplicitIndexerReceiverPlaceholder(receiver.Syntax, isEquivalentToThisReference: receiver.IsEquivalentToThisReference, receiver.Type) { WasCompilerGenerated = true };
10549Debug.Assert(indexerOrSliceAccess.Type is not null);
10559indexerOrSliceAccess.Type);
10773Debug.Assert(receiverPlaceholder.Type is not null);
10774if (TryLookupLengthOrCount(syntax, receiverPlaceholder.Type, lookupResult, out var lengthOrCountProperty, diagnostics))
11133Debug.Assert(node.ReceiverOpt!.Type is not null); // extensions are only considered on member access
11164var substituted = (MethodSymbol?)extensionMember.GetReducedAndFilteredSymbol(typeArguments, receiver.Type, Compilation, checkFullyInferred: true);
11170else if (m.ReduceExtensionMethod(receiver.Type, Compilation) is { } reduced)
11349Debug.Assert(node.ReceiverOpt!.Type is not null); // extensions are only considered on member access
11375var substituted = (MethodSymbol?)extensionMember.GetReducedAndFilteredSymbol(typeArguments, receiver.Type, Compilation, checkFullyInferred: true);
11624var receiverType = receiver.Type;
11633var accessType = access.Type;
11772var receiverType = receiver.Type;
11803var 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);
856Debug.Assert(methodGroup.ReceiverOpt != null && (object)methodGroup.ReceiverOpt.Type != null);
858Error(diagnostics, ErrorCode.ERR_BadArgTypeDynamicExtension, syntax, methodGroup.ReceiverOpt.Type, methodGroup.Name);
1085if (!call.HasAnyErrors && call.ReceiverOpt != null && (object)call.ReceiverOpt.Type != null && !call.Method.IsExtensionBlockMember())
1090if (call.ReceiverOpt.Type.IsRestrictedType() && !call.Method.ContainingType.IsInterface && !TypeSymbol.Equals(call.Method.ContainingType, call.ReceiverOpt.Type, TypeCompareKind.ConsiderEverything2))
1092SymbolDistinguisher distinguisher = new SymbolDistinguisher(compilation, call.ReceiverOpt.Type, call.Method.ContainingType);
1108(object)dynInvoke.Expression.Type != null &&
1109dynInvoke.Expression.Type.IsRestrictedType())
1113Error(diagnostics, ErrorCode.ERR_BadDynamicMethodArg, dynInvoke.Expression.Syntax, dynInvoke.Expression.Type);
1400if (receiver is BoundValuePlaceholderBase || receiver?.Type is null or { IsReferenceType: true })
1911receiver.Type.IsValueType &&
1982Debug.Assert(typeOrValue.Type.Equals(boundValue.Type, TypeCompareKind.ConsiderEverything));
2029var type = expr.Type as NamedTypeSymbol;
2084var methodContainer = (object)receiver != null && (object)receiver.Type != null
2085? receiver.Type
2327var methodContainer = expr.Type ?? this.ContainingType;
2533RoslynDebug.Assert(boundExpression.Type is FunctionPointerTypeSymbol);
2535var funcPtr = (FunctionPointerTypeSymbol)boundExpression.Type;
Binder\Binder_Operators.cs (90)
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,
271var leftType = left.Type;
344var leftType = left.Type;
387var leftType = left.Type;
438var leftType = left.Type;
782TypeSymbol type = operand.Type;
810Debug.Assert((object)left.Type != null && left.Type.IsDynamic() || (object)right.Type != null && right.Type.IsDynamic());
834Error(diagnostics, ErrorCode.ERR_InvalidDynamicCondition, node.Left, left.Type, kind == BinaryOperatorKind.LogicalAnd ? "false" : "true");
840Debug.Assert(left.Type is not TypeParameterSymbol);
954TypeSymbol leftType = left.Type;
955TypeSymbol rightType = right.Type;
990Debug.Assert(right.Type.SpecialType == SpecialType.System_String);
991var stringConstant = FoldBinaryOperator(node, BinaryOperatorKind.StringConcatenation, left, right, right.Type, diagnostics);
992return new BoundBinaryOperator(node, BinaryOperatorKind.StringConcatenation, BoundBinaryOperator.UncommonData.UnconvertedInterpolatedStringAddition(stringConstant), LookupResultKind.Empty, left, right, right.Type);
1197TypeSymbol leftType = left.Type;
1198TypeSymbol rightType = right.Type;
1315(object?)left.Type != null && left.Type.TypeKind == TypeKind.Delegate)
1319var conversion = this.Conversions.ClassifyConversionFromExpression(right, left.Type, isChecked: CheckOverflowAtRuntime, ref discardedUseSiteInfo);
1321GenerateImplicitConversionError(diagnostics, right.Syntax, conversion, right, left.Type);
1349case (BoundKind.DefaultLiteral, _) when right.Type is TypeParameterSymbol:
1350Debug.Assert(!right.Type.IsReferenceType);
1351Error(diagnostics, ErrorCode.ERR_AmbigBinaryOpsOnUnconstrainedDefault, node, operatorToken.Text, right.Type);
1353case (_, BoundKind.DefaultLiteral) when left.Type is TypeParameterSymbol:
1354Debug.Assert(!left.Type.IsReferenceType);
1355Error(diagnostics, ErrorCode.ERR_AmbigBinaryOpsOnUnconstrainedDefault, node, operatorToken.Text, left.Type);
1373case LookupResultKind.OverloadResolutionFailure when operatorToken.Kind() is SyntaxKind.PlusToken && isReadOnlySpanOfByte(left.Type) && isReadOnlySpanOfByte(right.Type):
1447if ((object)left.Type != null && left.Type.SpecialType == SpecialType.System_Boolean &&
1448(object)right.Type != null && right.Type.SpecialType == SpecialType.System_Boolean)
1450var constantValue = FoldBinaryOperator(node, kind | BinaryOperatorKind.Bool, left, right, left.Type, diagnostics);
1454resultKind: LookupResultKind.Viable, left, right, type: left.Type, hasErrors: constantValue != null && constantValue.IsBad);
1545Debug.Assert(resultLeft.Type.Equals(signature.LeftType, TypeCompareKind.IgnoreNullableModifiersForReferenceTypes));
1546var operandPlaceholder = new BoundValuePlaceholder(resultLeft.Syntax, resultLeft.Type).MakeCompilerGenerated();
1602var type = left.Type;
1619if (left.Type is not null)
1621CreateConversion(left.Syntax, new BoundValuePlaceholder(left.Syntax, left.Type).MakeCompilerGenerated(), implicitConversion, isCast: false, conversionGroupOpt: null, InConversionGroupFlags.Unspecified, booleanType, diagnostics);
2111if (left.Type is null && right.Type is null)
2369(object)operand.Type != null &&
2370(operand.Type.SpecialType == SpecialType.System_UInt64 || isNuint(operand.Type)))
2423operand.Type is null) // GetUserDefinedOperators performs this check too, let's optimize early
2656return left.Type;
2659return right.Type;
2723BinaryOperatorKind newKind = kind.Operator().WithType(newLeftOperand.Type!.SpecialType);
3283var operandType = operand.Type;
3437var operandType = operand.Type;
3484Debug.Assert(operand.Type is not null);
3490operand.Type,
3527var operandType = operand.Type;
3678Debug.Assert(operand.Type is not null);
4075var operandType = operand.Type as PointerTypeSymbol;
4130TypeSymbol operandType = operand.Type;
4209if (receiver.Type.IsReferenceType)
4335if (isOperandNullOrNew || operand.Type?.IsErrorType() == true)
4363type: operand.Type!);
4417var underlyingType = operand.Type.GetEnumUnderlyingType()!;
4776if ((object)operand.Type == null && !operand.IsLiteralNull())
4835if ((object)operand.Type == null)
4846var convertedExpression = BindExpressionForPattern(operand.Type, node.Right, ref hasErrors, isPatternDiagnostics, out var constantValueOpt, out var wasExpression, out _);
4853node.Right, convertedExpression, constantValueOpt ?? ConstantValue.Bad, operand.Type, convertedExpression.Type ?? operand.Type, hasErrors)
4873if (operandHasErrors || IsOperatorErrors(node, operand.Type, typeExpression, diagnostics))
4894operand.Type.IsVoidType())
4924var operandType = operand.Type;
5324if ((object)operand.Type == null)
5386Debug.Assert(operand.Type is null);
5387operandPlaceholder = new BoundValuePlaceholder(operand.Syntax, operand.Type).MakeCompilerGenerated();
5401var operandType = operand.Type;
5434operandPlaceholder = new BoundValuePlaceholder(operand.Syntax, operand.Type).MakeCompilerGenerated();
5613TypeSymbol optLeftType = leftOperand.Type; // "A"
5614TypeSymbol optRightType = rightOperand.Type; // "B"
5787TypeSymbol leftType = leftOperand.Type;
5805if (underlyingRightConversion.Exists && rightOperand.Type?.IsDynamic() != true)
5946TypeSymbol trueType = trueExpr.Type;
5947TypeSymbol falseType = falseExpr.Type;
Binder\Binder_Patterns.cs (20)
25TypeSymbol? expressionType = expression.Type;
38Debug.Assert(expression.Type is { });
39BoundPattern pattern = BindPattern(node.Pattern, expression.Type, permitDesignations: true, hasErrors, diagnostics, underIsPattern: true);
67Debug.Assert(expression.Type is object);
68diagnostics.Add(ErrorCode.ERR_IsPatternImpossible, node.Location, expression.Type);
85Debug.Assert(expression.Type is object);
86diagnostics.Add(ErrorCode.WRN_IsPatternAlways, node.Location, expression.Type);
260Debug.Assert(indexerAccess.Type is not null);
261sliceType = indexerAccess.Type;
334Debug.Assert(indexerAccess!.Type is not null);
335elementType = indexerAccess.Type;
439var convertedType = convertedExpression.Type ?? inputType;
527Debug.Assert(expression is { Kind: BoundKind.TypeExpression, Type: { } });
528hasErrors |= CheckValidPatternType(patternExpression, inputType, expression.Type, diagnostics: diagnostics);
590if (convertedExpression.Type is null && constantValueOpt != ConstantValue.Null)
631RoslynDebug.Assert(expression.Type is { });
632ConstantValue match = ExpressionOfTypeMatchesPatternType(Conversions, inputType, expression.Type, ref useSiteInfo, out _, operandConstantValue: null);
664if (expression.Type?.SpecialType == SpecialType.System_String && inputType.IsSpanOrReadOnlySpanChar())
719(conversion.ConversionKind == ConversionKind.NoConversion && convertedExpression.Type?.IsErrorType() == true))
1645var 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());
1628if (!hasErrors && op1.Type.IsRefLikeOrAllowsRefLikeType())
1860Debug.Assert((object)receiver.Type != null);
1861return receiver.Type;
1987this.Conversions.ClassifyConversionFromType(expression.Type, targetType, isChecked: CheckOverflowAtRuntime, ref useSiteInfo);
2019expression.Type,
2479var sourceType = operand.Type;
3090hasErrors |= arg.HasErrors || ((object)arg.Type != null && arg.Type.IsErrorType());
3165if ((object)arg?.Type != null && arg.Type.IsVoidType())
3229&& TypeSymbol.Equals(argument.Type, this.GetCurrentReturnType(out unusedRefKind), TypeCompareKind.ConsiderEverything2))
3232Error(diagnostics, ErrorCode.ERR_BadAsyncReturnExpression, argument.Syntax, returnType, argument.Type);
3566else if (expression.Type?.SpecialType == SpecialType.System_Void)
Binder\Binder_Symbols.cs (3)
1519receiver = new BoundBadExpression(receiver.Syntax, LookupResultKind.Ambiguous, ImmutableArray<Symbol>.Empty, ImmutableArray.Create(receiver), receiver.Type, hasErrors: true).MakeCompilerGenerated();
1528Error(diagnostics, ErrorCode.ERR_NoSuchMemberOrExtension, right, receiver.Type, plainName);
1529receiver = new BoundBadExpression(receiver.Syntax, LookupResultKind.Empty, ImmutableArray<Symbol>.Empty, childBoundNodes: [AdjustBadExpressionChild(receiver)], receiver.Type, hasErrors: true).MakeCompilerGenerated();
Binder\ForEachLoopBinder.cs (21)
556(builder.ElementType.IsPointerOrFunctionPointer() && collectionExpr.Type.IsArray()) ||
557(builder.ElementType.IsNullableType() && builder.ElementType.GetMemberTypeArgumentsNoUseSiteDiagnostics().Single().IsErrorType() && collectionExpr.Type.IsArray()));
593(collectionConversionClassification.Kind == ConversionKind.ExplicitReference && collectionExpr.Type.SpecialType == SpecialType.System_String));
662Debug.Assert(collectionType.Equals(collectionExpr.Type, TypeCompareKind.AllIgnoreOptions)); // Should not create an Identity conversion that changes type.
702else if (collectionExpr.Type.SpecialType == SpecialType.System_String && builder.CollectionType.SpecialType == SpecialType.System_Collections_IEnumerable)
720TypeSymbol collectionExprType = collectionExpr.Type;
797TypeSymbol collectionExprType = collectionExpr.Type;
836if (!isAsync && collectionExpr.Type?.HasInlineArrayAttribute(out _) == true && collectionExpr.Type.TryGetPossiblyUnsupportedByLanguageInlineArrayElementField() is FieldSymbol elementField)
867diagnostics.Add(ErrorCode.ERR_InlineArrayForEachNotSupported, collectionExpr.Syntax.GetLocation(), collectionExpr.Type);
890builder.CollectionType = collectionExpr.Type;
907CheckInlineArrayTypeIsSupported(collectionExpr.Syntax, collectionExpr.Type, elementField.Type, diagnostics);
915diagnostics.Add(ErrorCode.ERR_InlineArrayForEachNotSupported, collectionExpr.Syntax.GetLocation(), collectionExpr.Type);
928(originalCollectionExpr.Type?.IsNullableType() == true && originalCollectionExpr.Type.StrippedType().Equals(collectionExpr.Type, TypeCompareKind.AllIgnoreOptions)));
939TypeSymbol collectionExprType = collectionExpr.Type;
979var unwrappedCollectionExprType = unwrappedCollectionExpr.Type;
1049builder.CollectionType = collectionExpr.Type;
1346getEnumeratorInfo = FindForEachPatternMethod(syntax, collectionSyntax, collectionExpr.Type, methodName, lookupResult, warningsOnly: true, diagnostics, isAsync);
1596diagnostics.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);
1033Debug.Assert(sourceExpression == null || (object)sourceExpression.Type == (object)source);
1075var innerConversion = ClassifyImplicitBuiltInConversionFromExpression(innerExpression, innerExpression.Type, destination, ref useSiteInfo);
1353if (constantValue == null || (object)source.Type == null)
1363var specialSource = source.Type.GetSpecialTypeSafe();
1419var sourceType = sourceExpression.Type;
1462source.Type is object &&
1463IsNumericType(source.Type) &&
1923Debug.Assert(sourceExpressionOpt == null || (object)sourceExpressionOpt.Type == sourceType);
1960conversions.ClassifyImplicitExtensionMethodThisArgConversion(s, s.Type, d.Type, ref u, isMethodGroupConversion: false),
3043if (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 (50)
52if ((object)expression.Type == null ||
53(expression.Type.SpecialType != SpecialType.System_Decimal &&
54!expression.Type.IsNullableType()))
56EmitConstantExpression(expression.Type, constantValue, used, expression.Syntax);
374EmitDefaultValue(node.Type, used, node.Syntax);
409var receiverType = receiver.Type;
522Debug.Assert(receiver.Type.IsNullableType());
680EmitSymbolToken(expression.Operand.Type, expression.Operand.Syntax);
730Debug.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");
803EmitLoadIndirect(expression.Type, expression.Syntax);
812var meth = expression.MethodOpt ?? receiver.Type.DelegateInvokeMethod();
1025if (((ArrayTypeSymbol)arrayAccess.Expression.Type).IsSZArray)
1112_builder.EmitArrayElementLoad(_module.Translate((ArrayTypeSymbol)arrayAccess.Expression.Type), arrayAccess.Expression.Syntax);
1143if (!field.IsVolatile && !field.IsStatic && fieldAccess.ReceiverOpt.Type.IsVerifierValue() && field.RefKind == RefKind.None)
1182if (fieldType.IsValueType && (object)fieldType == (object)receiver.Type)
1238if (receiver == null || !receiver.Type.IsValueType)
1249EmitSymbolToken(receiver.Type, receiver.Syntax);
1278if (!receiver.Type.IsVerifierValue())
1330var type = expr.Type;
1521if (receiver.Type.IsTypeParameter())
1526Debug.Assert(receiver.Type.IsVerifierReference(), "this is not a reference");
1656Debug.Assert(TypeSymbol.Equals(method.ContainingType, receiver.Type, TypeCompareKind.ConsiderEverything2));
1691EmitSymbolToken(receiver.Type, receiver.Syntax);
1858var receiverType = receiver.Type;
1944var receiverType = receiver.Type;
2004Debug.Assert(receiver.Type.IsVerifierReference());
2015Debug.Assert(receiver.Type.IsVerifierReference());
2035EmitSymbolToken(receiver.Type, receiver.Syntax);
2050var receiverType = receiver.Type;
2113var receiverType = receiver.Type;
2630var rightType = right.Type;
2686if (left.Kind == BoundKind.ArrayAccess && left.Type.TypeKind == TypeKind.TypeParameter && !left.Type.IsValueType)
2710EmitSymbolToken(target.Type, target.Syntax);
3089assignmentOperator.Left.Type,
3136var arrayType = (ArrayTypeSymbol)array.Type;
3150EmitIndirectStore(expression.Type, expression.Syntax);
3155EmitIndirectStore(expression.Type, expression.Syntax);
3161EmitIndirectStore(expression.Type, expression.Syntax);
3173EmitIndirectStore(expression.Type, expression.Syntax);
3178EmitIndirectStore(expression.Type, expression.Syntax);
3424Debug.Assert((object)operand.Type != null);
3425if (!operand.Type.IsVerifierReference())
3428EmitBox(operand.Type, operand.Syntax);
3451var operandType = operand.Type;
3945if (!(expr.Type.IsInterfaceType() || expr.Type.IsDelegateType()))
3947return expr.Type;
3992return expr.Type;
4063temp = 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())
3698var thisParam = GetThisParameter(boundNode.Type, containingType, containingMember, out resultKind);
3827symbols = OneOrMany.Create<Symbol>(new SynthesizedIntrinsicOperatorSymbol(unaryOperator.Operand.Type.StrippedType(),
3850TypeSymbol opType = increment.Operand.Type.StrippedType();
3877((binaryOperator.Left.IsLiteralNull() && binaryOperator.Right.Type.IsNullableType()) ||
3878(binaryOperator.Right.IsLiteralNull() && binaryOperator.Left.Type.IsNullableType())) &&
3892binaryOperator.Left.Type,
3893binaryOperator.Right.Type,
4103TypeSymbol type = boundNode.Type;
4627if (node.SearchExtensions && receiver.Type is { } receiverType)
4769receiverType = call.ReceiverOpt.Type;
4773receiverType = call.Arguments[0].Type;
4803MethodSymbol reduced = method.ReduceExtensionMethod(receiver.Type, Compilation);
4818MethodSymbol reduced = method.ReduceExtensionMethod(receiverOpt.Type, Compilation);
FlowAnalysis\NullableWalker.cs (63)
436expr.Type?.Equals(result.RValueType.Type, TypeCompareKind.AllIgnoreOptions) == true ? result.RValueType.Type : expr.Type);
572Debug.Assert(AreCloseEnough(placeholder.Type, result.RValueType.Type));
2117receiver.Type is object;
2128TypeSymbol? nodeType = node.Type;
2164var operandType = operand.Type;
2182TypeSymbol.Equals(conv.Type, conv.Operand.Type, TypeCompareKind.IgnoreNullableModifiersForReferenceTypes):
3727Debug.Assert(AreCloseEnough(resultType.Type, node.Type));
3955collectionBuilderElementsPlaceholder.Type,
4784SetAnalyzedNullability(node.ImplicitReceiverOpt, new VisitResult(node.ImplicitReceiverOpt.Type, NullableAnnotation.NotAnnotated, NullableFlowState.NotNull));
4842SetResultType(node, TypeWithState.Create(node.Type, NullableFlowState.NotNull));
4847var resultType = TypeWithState.Create(node.Type, NullableFlowState.NotNull);
4894Debug.Assert(node.Type is object);
4895if (IsEmptyStructType(node.Type))
4900return GetOrCreatePlaceholderSlot(node, TypeWithAnnotations.Create(node.Type, NullableAnnotation.NotAnnotated));
5218Debug.Assert(!node.Expression.Type!.IsValueType);
5232TypeSymbol.Equals(node.Indices[0].Type, compilation.GetWellKnownType(WellKnownType.System_Range), TypeCompareKind.ConsiderEverything2))
5551if (expr.Type is null)
5561TypeWithAnnotations.Create(expr.Type),
5575Debug.Assert(binary.Type!.SpecialType == SpecialType.System_Boolean);
5838var receiverType = conditional.Receiver.Type!;
5867if (slot > 0 && PossiblyNullableType(operand.Type))
5937LearnFromNullTest(slot, expressionWithoutConversion.Type, ref state, markDependentSlotsNotNull: false);
6051node.Type?.ContainsErrorType() == true ||
6052TypeSymbol.Equals(targetType.Type.GetNullableUnderlyingType(), node.Type, TypeCompareKind.AllIgnoreOptions));
6058targetType = TypeWithAnnotations.Create(node.Type, NullableAnnotation.NotAnnotated);
6348if (slot > 0 && receiver.Type?.IsNullableType() == true)
6349slot = GetNullableOfTValueSlot(receiver.Type, slot, out _);
6393TypeSymbol? refResultType = node.Type?.SetUnknownNullabilityForReferenceTypes();
6459resultType ??= node.Type?.SetUnknownNullabilityForReferenceTypes();
7655TrackAnalyzedNullabilityThroughConversionGroup(TypeWithState.Create(argument.Type, result.RValueType.State), argument as BoundConversion, argumentNoConversion);
7773completion(TypeWithAnnotations.Create(argument.Type));
8928if (value.Type is null || value.Type.IsDynamic() || value.ConstantValueOpt != null)
8938value.Type.HasInlineArrayAttribute(out _) == true &&
8939value.Type.TryGetInlineArrayElementField() is not null)
9079if (TypeAllowsConditionalState(targetType.Type) && TypeAllowsConditionalState(operand.Type))
9227var tupleOpt = (NamedTypeSymbol?)node.Type;
10426case BoundExpression arg when arg.Type is { TypeKind: TypeKind.Delegate }:
10540Debug.Assert(arg.Type is not null);
10541TypeSymbol argType = arg.Type;
10559Debug.Assert(arg.Type is not null);
10560TypeSymbol argType = arg.Type;
10740var rvalueResult = TypeWithState.Create(node.Type, NullableFlowState.NotNull);
10741var lvalueResult = TypeWithAnnotations.Create(node.Type, NullableAnnotation.NotAnnotated);
11239if (expr.Type is NamedTypeSymbol { IsTupleType: true } tupleType)
11578SetResultType(node.Expression, TypeWithState.Create(node.Expression.Type, ResultType.State));
11954if (collectionExpression.Type!.SpecialType == SpecialType.System_Collections_IEnumerable)
11957targetTypeWithAnnotations = TypeWithAnnotations.Create(collectionExpression.Type);
11959else if (ForEachLoopBinder.IsIEnumerableT(collectionExpression.Type.OriginalDefinition, isAsync, compilation))
12216var type = TypeWithAnnotations.Create(node.Type);
12733SetResultType(node, TypeWithState.Create(node.Type, node.Type?.CanContainNull() != false && node.ConstantValueOpt?.IsNull == true ? NullableFlowState.MaybeDefault : NullableFlowState.NotNull));
12910SetResultType(expression, TypeWithState.Create(expression.Type, default));
12944Debug.Assert(receiverOpt.Type is null || AreCloseEnough(receiverOpt.Type, resultTypeSymbol));
13032SetResultType(node, TypeWithState.Create(node.Type, NullableFlowState.NotNull));
13065Debug.Assert(node.Type is null || node.Type.IsErrorType() || node.Type.IsRefLikeType);
13081SetResultType(node, TypeWithState.Create(node.Type, NullableFlowState.NotNull));
13085Debug.Assert(node.Type is not null);
13086var type = VisitArrayInitialization(node.Type, initialization, node.HasErrors);
Generated\BoundNodes.xml.Generated.cs (190)
471if (!TypeSymbol.Equals(type, this.Type, TypeCompareKind.ConsiderEverything))
499if (receiver != this.Receiver || !TypeSymbol.Equals(type, this.Type, TypeCompareKind.ConsiderEverything))
531public new TypeSymbol Type => base.Type!;
568public new TypeSymbol Type => base.Type!;
597public new TypeSymbol? Type => base.Type;
632public new TypeSymbol Type => base.Type!;
669public new TypeSymbol Type => base.Type!;
705public new TypeSymbol Type => base.Type!;
742public new TypeSymbol Type => base.Type!;
778public new TypeSymbol Type => base.Type!;
813public new TypeSymbol Type => base.Type!;
848public new TypeSymbol Type => base.Type!;
883public new TypeSymbol Type => base.Type!;
918if (!TypeSymbol.Equals(type, this.Type, TypeCompareKind.ConsiderEverything))
949if (refKind != this.RefKind || !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!;
1412public new TypeSymbol Type => base.Type!;
1447public new TypeSymbol Type => base.Type!;
1484public new TypeSymbol Type => base.Type!;
1518public new TypeSymbol Type => base.Type!;
1549public new TypeSymbol Type => base.Type!;
1580public new TypeSymbol Type => base.Type!;
1612public new TypeSymbol Type => base.Type!;
1644public new TypeSymbol Type => base.Type!;
1678public new TypeSymbol Type => base.Type!;
1738public new TypeSymbol Type => base.Type!;
1833public new TypeSymbol Type => base.Type!;
1873public new TypeSymbol Type => base.Type!;
1908public new TypeSymbol Type => base.Type!;
1946public new TypeSymbol Type => base.Type!;
1990if (leftOperand != this.LeftOperand || rightOperand != this.RightOperand || !TypeSymbol.Equals(type, this.Type, TypeCompareKind.ConsiderEverything))
2017public new TypeSymbol? Type => base.Type;
2059public new TypeSymbol Type => base.Type!;
2097public new TypeSymbol Type => base.Type!;
2127public new TypeSymbol? Type => base.Type;
2157public new TypeSymbol Type => base.Type!;
2231public new TypeSymbol Type => base.Type!;
2271public new TypeSymbol Type => base.Type!;
2362public new TypeSymbol Type => base.Type!;
2404public new TypeSymbol Type => base.Type!;
2447public new TypeSymbol Type => base.Type!;
2484public new TypeSymbol Type => base.Type!;
2519public new TypeSymbol Type => base.Type!;
2557public new TypeSymbol Type => base.Type!;
2592public new TypeSymbol Type => base.Type!;
2627public new TypeSymbol Type => base.Type!;
2662public new TypeSymbol Type => base.Type!;
2697public new TypeSymbol Type => base.Type!;
2736public new TypeSymbol Type => base.Type!;
2778public new TypeSymbol Type => base.Type!;
2821public new TypeSymbol Type => base.Type!;
2852public new TypeSymbol? Type => base.Type;
2875public new TypeSymbol Type => base.Type!;
2909public new TypeSymbol Type => base.Type!;
2945public new TypeSymbol Type => base.Type!;
2979public new TypeSymbol Type => base.Type!;
3021public new TypeSymbol Type => base.Type!;
3060public new TypeSymbol Type => base.Type!;
3097public new TypeSymbol Type => base.Type!;
3126public new TypeSymbol? Type => base.Type;
3162public new TypeSymbol Type => base.Type!;
4374if (constantValueOpt != this.ConstantValueOpt || !TypeSymbol.Equals(type, this.Type, TypeCompareKind.ConsiderEverything))
4406public new TypeSymbol Type => base.Type!;
4442public new TypeSymbol Type => base.Type!;
4477public new TypeSymbol Type => base.Type!;
4512public new TypeSymbol Type => base.Type!;
4541public new TypeSymbol? Type => base.Type;
4586public new TypeSymbol Type => base.Type!;
4633public new TypeSymbol Type => base.Type!;
4666public new TypeSymbol Type => base.Type!;
4707public new TypeSymbol Type => base.Type!;
4852if (!Symbols.SymbolEqualityComparer.ConsiderEverything.Equals(label, this.Label) || !TypeSymbol.Equals(type, this.Type, TypeCompareKind.ConsiderEverything))
5013if (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))
5038public new TypeSymbol Type => base.Type!;
5785public new TypeSymbol? Type => base.Type;
5808if (expression != this.Expression || !TypeSymbol.Equals(type, this.Type, TypeCompareKind.ConsiderEverything))
5834public new TypeSymbol Type => base.Type!;
5870public new TypeSymbol Type => base.Type!;
5907public new TypeSymbol Type => base.Type!;
5962public new TypeSymbol Type => base.Type!;
5996public new TypeSymbol Type => base.Type!;
6033public new TypeSymbol Type => base.Type!;
6076public new TypeSymbol Type => base.Type!;
6108public new TypeSymbol Type => base.Type!;
6225public new TypeSymbol Type => base.Type!;
6272public new TypeSymbol Type => base.Type!;
6314public new TypeSymbol Type => base.Type!;
6355public new TypeSymbol? Type => base.Type;
6395public new TypeSymbol Type => base.Type!;
6478public new TypeSymbol? Type => base.Type;
6552public new TypeSymbol Type => base.Type!;
6595if (!TypeSymbol.Equals(type, this.Type, TypeCompareKind.ConsiderEverything))
6673public new TypeSymbol? Type => base.Type;
6710if (sourceTuple != this.SourceTuple || wasTargetTyped != this.WasTargetTyped || arguments != this.Arguments || argumentNamesOpt != this.ArgumentNamesOpt || inferredNamesOpt != this.InferredNamesOpt || !TypeSymbol.Equals(type, this.Type, TypeCompareKind.ConsiderEverything))
6809public new TypeSymbol Type => base.Type!;
6864public new TypeSymbol Type => base.Type!;
6917public new TypeSymbol Type => base.Type!;
6984public new TypeSymbol Type => base.Type!;
7023public new TypeSymbol Type => base.Type!;
7059public new TypeSymbol Type => base.Type!;
7092public new TypeSymbol Type => base.Type!;
7134public new TypeSymbol Type => base.Type!;
7197public new TypeSymbol Type => base.Type!;
7231public new TypeSymbol Type => base.Type!;
7262public new TypeSymbol? Type => base.Type;
7317if (!TypeSymbol.Equals(elementType, this.ElementType, TypeCompareKind.ConsiderEverything) || count != this.Count || initializerOpt != this.InitializerOpt || !TypeSymbol.Equals(type, this.Type, TypeCompareKind.ConsiderEverything))
7339public new TypeSymbol Type => base.Type!;
7373public new TypeSymbol Type => base.Type!;
7418public new TypeSymbol Type => base.Type!;
7452public new TypeSymbol Type => base.Type!;
7489public new TypeSymbol Type => base.Type!;
7533public new TypeSymbol Type => base.Type!;
7587public new TypeSymbol Type => base.Type!;
7630public new TypeSymbol Type => base.Type!;
7669public new TypeSymbol Type => base.Type!;
7711public new TypeSymbol? Type => base.Type;
7755public new TypeSymbol? Type => base.Type;
7793public new TypeSymbol Type => base.Type!;
7860public new TypeSymbol Type => base.Type!;
7911if (parts != this.Parts || constantValueOpt != this.ConstantValueOpt || !TypeSymbol.Equals(type, this.Type, TypeCompareKind.ConsiderEverything))
7939if (!interpolationData.Equals(this.InterpolationData) || parts != this.Parts || constantValueOpt != this.ConstantValueOpt || !TypeSymbol.Equals(type, this.Type, TypeCompareKind.ConsiderEverything))
7967if (!TypeSymbol.Equals(type, this.Type, TypeCompareKind.ConsiderEverything))
7997public new TypeSymbol Type => base.Type!;
8029public new TypeSymbol? Type => base.Type;
8082if (expression != this.Expression || pattern != this.Pattern || 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))
8682public new TypeSymbol? Type => base.Type;
8719if (expression != this.Expression || !TypeSymbol.Equals(type, this.Type, TypeCompareKind.ConsiderEverything))
8741public new TypeSymbol? Type => base.Type;
8814public new TypeSymbol? Type => base.Type;
8912public new TypeSymbol? Type => base.Type;
8945public new TypeSymbol Type => base.Type!;
10985TypeSymbol? type = this.VisitType(node.Type);
10991TypeSymbol? type = this.VisitType(node.Type);
11052TypeSymbol? type = this.VisitType(node.Type);
11057TypeSymbol? type = this.VisitType(node.Type);
11063TypeSymbol? type = this.VisitType(node.Type);
11070TypeSymbol? type = this.VisitType(node.Type);
11266TypeSymbol? type = this.VisitType(node.Type);
11684TypeSymbol? type = this.VisitType(node.Type);
11758TypeSymbol? type = this.VisitType(node.Type);
11787TypeSymbol? type = this.VisitType(node.Type);
11935TypeSymbol? type = this.VisitType(node.Type);
12077TypeSymbol? type = this.VisitType(node.Type);
12100TypeSymbol? type = this.VisitType(node.Type);
12211TypeSymbol? type = this.VisitType(node.Type);
12322TypeSymbol? type = this.VisitType(node.Type);
12328TypeSymbol? type = this.VisitType(node.Type);
12333TypeSymbol? type = this.VisitType(node.Type);
12356TypeSymbol? type = this.VisitType(node.Type);
12481TypeSymbol? type = this.VisitType(node.Type);
12595updatedNode = node.Update(receiver, node.Type);
12773updatedNode = node.Update(expression, node.Type);
12791updatedNode = node.Update(node.ResultKind, node.Symbols, childBoundNodes, node.Type);
13168updatedNode = node.Update(leftOperand, rightOperand, node.Type);
13969updatedNode = node.Update(expression, switchArms, reachabilityDecisionDag, node.DefaultLabel, node.ReportedNotExhaustive, node.Type);
14064updatedNode = node.Update(expression, node.Type);
14426updatedNode = node.Update(sourceTuple, node.WasTargetTyped, arguments, node.ArgumentNamesOpt, node.InferredNamesOpt, node.Type);
14709updatedNode = node.Update(elementType, count, initializerOpt, node.Type);
14947updatedNode = node.Update(parts, node.ConstantValueOpt, node.Type);
14964updatedNode = node.Update(node.InterpolationData, parts, node.ConstantValueOpt, node.Type);
15026updatedNode = node.Update(expression, pattern, node.IsNegated, reachabilityDecisionDag, node.WhenTrueLabel, node.WhenFalseLabel, node.Type);
15166updatedNode = node.Update(expression, node.Type);
15308new TreeDumperNode("type", node.Type, null),
15316new TreeDumperNode("type", node.Type, null),
15404new TreeDumperNode("type", node.Type, null),
15412new TreeDumperNode("type", node.Type, null),
15420new TreeDumperNode("type", node.Type, null),
15430new TreeDumperNode("type", node.Type, null),
15703new TreeDumperNode("type", node.Type, null),
16267new TreeDumperNode("type", node.Type, null),
16369new TreeDumperNode("type", node.Type, null),
16405new TreeDumperNode("type", node.Type, null),
16591new TreeDumperNode("type", node.Type, null),
16817new TreeDumperNode("type", node.Type, null),
16851new TreeDumperNode("type", node.Type, null),
17017new TreeDumperNode("type", node.Type, null),
17184new TreeDumperNode("type", node.Type, null),
17194new TreeDumperNode("type", node.Type, null),
17201new TreeDumperNode("type", node.Type, null),
17233new TreeDumperNode("type", node.Type, null),
17387new 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);
708var operandType = node.Operand.Type;
717? Convert(Visit(node.Operand), node.Operand.Type, method.Parameters[0].Type, node.Checked, false)
733if (node.Operand.Type.IsNullableType())
735return Convert(Visit(node.Operand), node.Operand.Type, node.Type, node.Checked, node.ExplicitCastInCode);
742var e1 = Convert(Visit(node.Operand), node.Operand.Type, intermediate, node.Checked, false);
748return Convert(Visit(node.Operand), node.Operand.Type, node.Type, node.Checked, node.ExplicitCastInCode);
772else if (!receiver.Type.IsReferenceType)
816var d = node.Argument.Type as NamedTypeSymbol;
837if ((object)operand.Type == null && operand.ConstantValueOpt != null && operand.ConstantValueOpt.IsNull)
908var fromType = leftPlaceholder.Type;
1109Debug.Assert(args.Type.IsSZArray());
1167if (node.ReceiverOpt?.Type.IsTypeParameter() == true &&
1168!node.ReceiverOpt.Type.IsReferenceType)
1238var promotedType = PromotedType(arg.Type.StrippedType().GetEnumUnderlyingType());
1240loweredArg = Convert(loweredArg, arg.Type, promotedType, isChecked, false);
1260_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.PatternLocalRewriter.cs (24)
203TypeSymbol inputType = input.Type;
217Conversion conversion = _factory.Compilation.Conversions.ClassifyBuiltInConversion(inputType, output.Type, isChecked: false, ref useSiteInfo);
225inputType.GetNullableUnderlyingType().Equals(output.Type, TypeCompareKind.AllIgnoreOptions) &&
347Debug.Assert(input.Type is { });
351return MakeNullCheck(d.Syntax, input, input.Type.IsNullableType() ? BinaryOperatorKind.NullableNullNotEqual : BinaryOperatorKind.NotEqual);
358return MakeNullCheck(d.Syntax, input, input.Type.IsNullableType() ? BinaryOperatorKind.NullableNullEqual : BinaryOperatorKind.Equal);
361Debug.Assert(!input.Type.IsNullableType());
365Debug.Assert(!input.Type.IsNullableType());
366Debug.Assert(input.Type.IsValueType);
376Debug.Assert(!rewrittenExpr.Type.IsSpanOrReadOnlySpanChar());
378if (rewrittenExpr.Type.IsPointerOrFunctionPointer())
396if (value.IsString && input.Type.IsSpanOrReadOnlySpanChar())
401TypeSymbol comparisonType = input.Type.EnumUnderlyingTypeOrSelf();
410if (input.Type.SpecialType == SpecialType.System_Double && double.IsNaN(value.DoubleValue) ||
411input.Type.SpecialType == SpecialType.System_Single && float.IsNaN(value.SingleValue))
417BoundExpression literal = _localRewriter.MakeLiteral(syntax, value, input.Type);
418TypeSymbol comparisonType = input.Type.EnumUnderlyingTypeOrSelf();
446var isReadOnlySpan = input.Type.IsReadOnlySpanChar();
488Debug.Assert(output.Type is { });
490testExpression = _factory.ObjectNotEqual(output, _factory.Null(output.Type));
524Debug.Assert(loweredInput.Type is { });
565if (loweredInput.Type.IsTupleType &&
566!loweredInput.Type.OriginalDefinition.Equals(_factory.Compilation.GetWellKnownType(WellKnownType.System_ValueTuple_TRest)) &&
640var temp = new BoundDagTemp(expr.Syntax, expr.Type, fieldFetchEvaluation);
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 (25)
185Debug.Assert(singleSpread.Expression.Type is not null);
187if (!ShouldUseIEnumerableBulkAddMethod(singleSpread.Expression.Type, toListOfElementType.Parameters[0].Type, singleSpread.EnumeratorInfoOpt?.GetEnumeratorInfo.Method))
233Elements: [BoundCollectionExpressionSpreadElement { Expression: { Type: NamedTypeSymbol spreadType } expr }],
408Debug.Assert(list.Type is { });
409Debug.Assert(list.Type.OriginalDefinition.Equals(_compilation.GetWellKnownType(WellKnownType.System_Collections_Generic_List_T), TypeCompareKind.AllIgnoreOptions));
411var listToArray = ((MethodSymbol)_factory.WellKnownMember(WellKnownMember.System_Collections_Generic_List_T__ToArray)).AsMember((NamedTypeSymbol)list.Type);
771var spreadTypeOriginalDefinition = spreadExpression.Type!.OriginalDefinition;
777return _factory.Call(rewrittenSpreadExpression, listToArrayMethod.AsMember((NamedTypeSymbol)spreadExpression.Type!));
787&& ShouldUseIEnumerableBulkAddMethod(spreadExpression.Type!, linqToArrayMethod.Parameters[0].Type, spreadElement.EnumeratorInfoOpt?.GetEnumeratorInfo.Method))
794&& TryGetSpanConversion(spreadExpression.Type, writableOnly: false, out var asSpanMethod))
796var spanType = CallAsSpanMethod(spreadExpression, asSpanMethod).Type!.OriginalDefinition;
801return _factory.Call(rewrittenSpreadExpression, toArrayMethod.AsMember((NamedTypeSymbol)rewrittenSpreadExpression.Type!));
904Debug.Assert(arrayTemp.Type is ArrayTypeSymbol);
907var elementType = ((ArrayTypeSymbol)arrayTemp.Type).ElementType;
1035var type = expression.Type;
1102if (spreadOperandAsSpan.Type!.OriginalDefinition.Equals(this._compilation.GetWellKnownType(wellKnownSpanType))
1141var spreadLength = _factory.Call(spreadOperandAsSpan, getLengthMethod.AsMember((NamedTypeSymbol)spreadOperandAsSpan.Type!));
1142var targetSlice = _factory.Call(spanTemp, spanSliceMethod.AsMember((NamedTypeSymbol)spanTemp.Type!), indexTemp, spreadLength);
1143sideEffects.Add(_factory.Call(spreadOperandAsSpan, copyToMethod.AsMember((NamedTypeSymbol)spreadOperandAsSpan.Type!), targetSlice));
1275Debug.Assert(spanTemp.Type is NamedTypeSymbol);
1278var elementType = ((NamedTypeSymbol)spanTemp.Type).TypeArgumentsWithAnnotationsNoUseSiteDiagnostics[0].Type;
1345Debug.Assert(rewrittenSpreadOperand.Type is not null);
1350if (!ShouldUseIEnumerableBulkAddMethod(rewrittenSpreadOperand.Type, addRangeMethod.Parameters[0].Type, spreadElement.EnumeratorInfoOpt?.GetEnumeratorInfo.Method))
1485_factory.Binary(BinaryOperatorKind.Addition, sum.Type!, sum, value);
1520if (convertedExpression.Operand.Type is ArrayTypeSymbol arrayType)
Lowering\LocalRewriter\LocalRewriter_CompoundAssignmentOperator.cs (32)
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));
235Debug.Assert(assignment.Type is { });
236return new BoundSequence(syntax, [binaryResult.LocalSymbol], [assignmentToTemp], assignment, assignment.Type);
292Debug.Assert(rewrittenReceiver.Type is { });
312var variableRepresentsLocation = rewrittenReceiver.Type.IsValueType || rewrittenReceiver.Type.Kind == SymbolKind.TypeParameter;
315isKnownToReferToTempIfReferenceType = !variableRepresentsLocation || rewrittenReceiver.Type.IsValueType ||
544indexerAccess.Argument.Type,
551throw ExceptionUtilities.UnexpectedValue(indexerAccess.Argument.Type);
572if (isDynamicAssignment || !IsInvariantArray(arrayAccess.Expression.Type))
600Debug.Assert(receiver is { Type: { } });
605else if (!receiver.Type.IsReferenceType)
610Debug.Assert(receiver.Type.IsReferenceType);
614Debug.Assert(rewrittenReceiver.Type is { });
615if (rewrittenReceiver.Type.IsTypeParameter())
753Debug.Assert(implicitIndexerAccess.Argument.Type!.Equals(_compilation.GetWellKnownType(WellKnownType.System_Index))
754|| implicitIndexerAccess.Argument.Type!.Equals(_compilation.GetWellKnownType(WellKnownType.System_Range)));
783if (isDynamicAssignment || !IsInvariantArray(arrayAccess.Expression.Type))
964var type = expression.Type;
980var type = expression.Type;
1036Debug.Assert(expression.Type is { });
1037if (expression.Type.IsNullableType())
Lowering\LocalRewriter\LocalRewriter_Conversion.cs (69)
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))
427Debug.Assert(rewrittenOperand.Type is { });
433if (rewrittenType.SpecialType == SpecialType.System_Decimal || rewrittenOperand.Type.SpecialType == SpecialType.System_Decimal)
435return RewriteDecimalConversion(syntax, rewrittenOperand, rewrittenOperand.Type, rewrittenType, @checked, conversion.Kind.IsImplicitConversion(), constantValueOpt);
442Debug.Assert(rewrittenOperand.Type is { });
445Debug.Assert(rewrittenOperand.Type.Equals(rewrittenType, TypeCompareKind.IgnoreDynamicAndTupleNames | TypeCompareKind.IgnoreNullableModifiersForReferenceTypes));
488Debug.Assert(rewrittenOperand.Type is { });
498Debug.Assert(rewrittenOperand.Type.IsEnumType());
499var underlyingTypeFrom = rewrittenOperand.Type.GetEnumUnderlyingType()!;
503else if (rewrittenOperand.Type.SpecialType == SpecialType.System_Decimal)
511var rewrittenNode = RewriteDecimalConversion(syntax, rewrittenOperand, rewrittenOperand.Type, underlyingTypeTo, @checked, isImplicit: false, constantValueOpt: constantValueOpt);
557(symbolOpt.IsAbstract || symbolOpt.IsVirtual) ? mg.ReceiverOpt?.Type : null,
596Debug.Assert(rewrittenOperand.Type is not null);
611createSpan = createSpan.Construct(rewrittenOperand.Type, spanType.TypeArgumentsWithAnnotationsNoUseSiteDiagnostics.Single().Type);
612_ = rewrittenOperand.Type.HasInlineArrayAttribute(out int length);
620var sourceType = rewrittenOperand.Type;
637Debug.Assert(rewrittenOperand.Type?.IsSZArray() == true);
664Debug.Assert(implicitOperator.ParameterTypesWithAnnotations[0].Type.Equals(rewrittenOperand.Type, TypeCompareKind.AllIgnoreOptions));
698Debug.Assert(method.ParameterTypesWithAnnotations[0].Type.Equals(rewrittenOperand.Type, TypeCompareKind.AllIgnoreOptions));
714Debug.Assert(rewrittenOperand.Type?.IsStringType() == true);
826Debug.Assert(rewrittenOperand.Type is { });
828Conversion conversion = compilation.Conversions.ClassifyConversionFromType(rewrittenOperand.Type, rewrittenType, isChecked: @checked, ref useSiteInfo);
834rewrittenOperand.Type.SpecialType != SpecialType.System_Decimal &&
835rewrittenOperand.Type.SpecialType != SpecialType.System_DateTime)
841rewrittenOperand.Type,
887if (!TypeSymbol.Equals(rewrittenOperand.Type, conversion.BestUserDefinedConversionAnalysis.FromType, TypeCompareKind.ConsiderEverything2))
897if (!TypeSymbol.Equals(rewrittenOperand.Type, conversion.Method.GetParameterType(0), TypeCompareKind.ConsiderEverything2))
910Debug.Assert(rewrittenOperand.Type is { });
911if (rewrittenOperand.Type.IsNullableType() &&
912conversion.Method.GetParameterType(0).Equals(rewrittenOperand.Type.GetNullableUnderlyingType(), TypeCompareKind.AllIgnoreOptions) &&
916userDefinedConversionRewrittenType = ((NamedTypeSymbol)rewrittenOperand.Type.OriginalDefinition).Construct(userDefinedConversionRewrittenType);
926if (!TypeSymbol.Equals(userDefined.Type, conversion.BestUserDefinedConversionAnalysis.ToType, TypeCompareKind.ConsiderEverything2))
935if (!TypeSymbol.Equals(userDefined.Type, rewrittenType, TypeCompareKind.ConsiderEverything2))
967Debug.Assert(rewrittenOperand.Type is { });
971var tupleTypeSymbol = (NamedTypeSymbol)rewrittenOperand.Type;
1008Debug.Assert(expression.Type is { });
1009if (!expression.Type.IsNullableType())
1021when convertedArgument.Type!.Equals(expression.Type.StrippedType(), TypeCompareKind.AllIgnoreOptions):
1026when underlying.Length == 1 && underlying[0].Kind == ConversionKind.ImplicitTuple && !convertedArgument.Type!.IsNullableType():
1062TypeSymbol? rewrittenOperandType = rewrittenOperand.Type;
1112Debug.Assert(rewrittenOperand.Type is { });
1113TypeSymbol rewrittenOperandType = rewrittenOperand.Type;
1327Debug.Assert(TypeSymbol.Equals(conditional.Type, conditional.Consequence.Type, TypeCompareKind.ConsiderEverything2));
1328Debug.Assert(TypeSymbol.Equals(conditional.Type, conditional.Alternative.Type, TypeCompareKind.ConsiderEverything2));
1360Debug.Assert(rewrittenOperand.Type is { });
1361if (rewrittenOperand.Type.IsNullableType())
1364if (parameterType.Equals(rewrittenOperand.Type.GetNullableUnderlyingType(), TypeCompareKind.AllIgnoreOptions) &&
1380if ((rewrittenOperand.Type.IsArray()) && _compilation.IsReadOnlySpanType(rewrittenType))
1392Debug.Assert(TypeSymbol.Equals(result.Type, rewrittenType, TypeCompareKind.ConsiderEverything2));
1415Debug.Assert(rewrittenOperand.Type is { });
1418Conversion conv = TryMakeConversion(syntax, conversion, rewrittenOperand.Type, rewrittenType, @checked: @checked);
1432Debug.Assert(rewrittenOperand.Type.IsNullableType());
1509Debug.Assert(rewrittenOperand.Type is { });
1512TypeSymbol source = rewrittenOperand.Type;
1735Debug.Assert(operand.Type is { });
1736return RewriteDecimalConversionCore(syntax, operand, operand.Type, toType, isImplicit, constantValueOpt);
Lowering\LocalRewriter\LocalRewriter_IndexerAccess.cs (37)
121Debug.Assert(oldNode.Type is not null);
122Debug.Assert(oldNode.Type.Equals(type, TypeCompareKind.ConsiderEverything));
218Debug.Assert(call.Type is not null);
233call.Type);
242Debug.Assert(node.Expression.Type is object);
243Debug.Assert(node.Argument.Type is object);
258_ = node.Expression.Type.HasInlineArrayAttribute(out int length);
260if (node.Argument.Type.SpecialType == SpecialType.System_Int32)
268if (TypeSymbol.Equals(node.Argument.Type, _compilation.GetWellKnownType(WellKnownType.System_Index), TypeCompareKind.AllIgnoreOptions))
280Debug.Assert(TypeSymbol.Equals(node.Argument.Type, _compilation.GetWellKnownType(WellKnownType.System_Range), TypeCompareKind.AllIgnoreOptions));
362Debug.Assert(node.Expression.Type is object);
374return createSpan.Construct(node.Expression.Type, node.Expression.Type.TryGetInlineArrayElementField()!.Type);
379Debug.Assert(node.Expression.Type is object);
380Debug.Assert(index.Type?.SpecialType == SpecialType.System_Int32);
382var intType = (NamedTypeSymbol)index.Type;
401elementRef = elementRef.Construct(node.Expression.Type, node.Expression.Type.TryGetInlineArrayElementField()!.Type);
420elementRef = elementRef.Construct(node.Expression.Type, node.Expression.Type.TryGetInlineArrayElementField()!.Type);
475node.Argument.Type,
484node.Argument.Type,
522node.Argument.Type,
538Debug.Assert(receiver.Type is { });
544receiver.Type.IsReferenceType ? RefKind.None : RefKind.Ref);
602Debug.Assert(integerArgument.Type!.SpecialType == SpecialType.System_Int32);
699Debug.Assert(loweredExpr.Type!.SpecialType == SpecialType.System_Int32);
710Debug.Assert(loweredExpr.Type!.SpecialType == SpecialType.System_Int32);
717loweredExpr.Type,
750unloweredExpr.Type,
758Debug.Assert(hatExpression.Operand is { Type: { SpecialType: SpecialType.System_Int32 } });
762else if (unloweredExpr is BoundConversion { Operand: { Type: { SpecialType: SpecialType.System_Int32 } } operand })
771arguments[0] is { Type.SpecialType: SpecialType.System_Int32, ConstantValueOpt.Value: int _ and >= 0 } index &&
772arguments[1] is { Type.SpecialType: SpecialType.System_Boolean, ConstantValueOpt.Value: bool fromEnd })
815node.Argument.Type,
841Debug.Assert(receiver.Type is { });
847receiver.Type.IsReferenceType ? RefKind.None : RefKind.Ref);
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));
49Debug.Assert(assignment.Type is { });
50assignment = new BoundSequence(syntax, [rightResult.LocalSymbol], [assignmentToTemp], assignment, assignment.Type);
58var leftPlaceholder = new BoundValuePlaceholder(lhsRead.Syntax, lhsRead.Type);
59BoundExpression conditionalExpression = MakeNullCoalescingOperator(syntax, lhsRead, assignment, leftPlaceholder: leftPlaceholder, leftConversion: leftPlaceholder, BoundNullCoalescingOperatorResultKind.LeftType, node.LeftOperand.Type);
60Debug.Assert(conditionalExpression.Type is { });
69conditionalExpression.Type);
76Debug.Assert(node.LeftOperand.Type.IsNullableType());
85leftOperand.Type,
93leftOperand.Type,
125Debug.Assert(transformedLHS.Type.GetNullableUnderlyingType().Equals(tmp.Type.StrippedType(), TypeCompareKind.AllIgnoreOptions));
128Debug.Assert(TypeSymbol.Equals(transformedLHS.Type, node.LeftOperand.Type, TypeCompareKind.AllIgnoreOptions));
133MakeConversionNode(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 (9)
400Debug.Assert(assignment.Type.IsDynamic() || TypeSymbol.Equals(rewrittenAccess.Type, assignment.Type, TypeCompareKind.AllIgnoreOptions));
454Debug.Assert(TypeSymbol.Equals(rangeArgument.Type, _compilation.GetWellKnownType(WellKnownType.System_Range), TypeCompareKind.ConsiderEverything));
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))
539Debug.Assert(TypeSymbol.Equals(rewrittenAccess.Type, assignment.Type, TypeCompareKind.AllIgnoreOptions));
700Debug.Assert(_compilation.Conversions.ClassifyConversionFromType(rewrittenReceiver.Type, memberSymbol.ContainingType, isChecked: false, ref discardedUseSiteInfo).IsImplicit ||
701(memberSymbol.IsExtensionBlockMember() && !memberSymbol.IsStatic && ConversionsBase.IsValidExtensionMethodThisArgConversion(_compilation.Conversions.ClassifyConversionFromType(rewrittenReceiver.Type, memberSymbol.ContainingType.ExtensionParameter!.Type, isChecked: false, ref discardedUseSiteInfo))) ||
702_compilation.Conversions.HasImplicitConversionToOrImplementsVarianceCompatibleInterface(rewrittenReceiver.Type, memberSymbol.ContainingType, ref discardedUseSiteInfo, out _));
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);
361isNullable = !(expr is BoundTupleExpression) && expr.Type is { } && expr.Type.IsNullableType();
373Debug.Assert(expr.Type is { });
376value = new BoundDefaultExpression(expr.Syntax, expr.Type.StrippedType());
403Debug.Assert(expr.Type is { });
409when expr.Type.IsNullableType() && o.Type is { } && o.Type.IsNullableType() && !underlying[0].IsUserDefined:
443expr.Type is { } exprType && exprType.IsNullableType() && o.Type is { } && o.Type.IsNullableType() && nested[0] is { IsTupleConversion: true } tupleConversion:
445Debug.Assert(expr.Type is { });
448Debug.Assert(operand.Type is { });
449var types = expr.Type.GetNullableUnderlyingType().TupleElementTypesWithAnnotations;
450int tupleCardinality = operand.Type.TupleElementTypesWithAnnotations.Length;
466type: expr.Type,
529Debug.Assert(tuple.Type is { IsTupleType: true });
535return 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));
586TypeSymbol? operandType = transformedLHS.Type; //type of the variable being incremented
660Debug.Assert(boundTemp.Type is not null);
686type: boundTemp.Type);
699Debug.Assert(boundTemp.Type is not null);
702Debug.Assert(tempValue.Type is { });
711tempValue.Type);
725type: boundTemp.Type);
931Debug.Assert(binaryOperand.Type is { TypeKind: TypeKind.Pointer });
932Debug.Assert(boundOne.Type is { SpecialType: SpecialType.System_Int32 });
933return MakeBinaryOperator(node.Syntax, binaryOperatorKind, binaryOperand, boundOne, binaryOperand.Type, method: null, constrainedToTypeOpt: null);
985Debug.Assert(operand.Type is { SpecialType: SpecialType.System_Decimal });
992Debug.Assert(operand.Type is { } && operand.Type.IsNullableType() && operand.Type.GetNullableUnderlyingType().SpecialType == SpecialType.System_Decimal);
996MethodSymbol getValueOrDefault = UnsafeGetNullableMethod(syntax, operand.Type, SpecialMember.System_Nullable_T_GetValueOrDefault);
997MethodSymbol ctor = UnsafeGetNullableMethod(syntax, operand.Type, SpecialMember.System_Nullable_T__ctor);
1008BoundExpression alternative = new BoundDefaultExpression(syntax, operand.Type);
1011return RewriteConditionalOperator(syntax, condition, consequence, alternative, ConstantValue.NotAvailable, operand.Type, isRef: false);
Lowering\SpillSequenceSpiller.cs (19)
45: base(SpillSequenceBuilderKind, syntax, value?.Type)
174new TreeDumperNode("type", this.Type, null)
337if (refKind != RefKind.None || expression.Type?.IsRefLikeOrAllowsRefLikeType() == true)
380if (refKind != RefKind.None || expression.Type.IsReferenceType)
497if (expression.Type.IsVoidType() || sideEffectsOnly)
1047Debug.Assert(refKind == RefKind.None || !receiver.Type.IsReferenceType);
1056var receiverType = receiver.Type;
1087if (!receiver.Type.IsReferenceType && LocalRewriter.CanBePassedByReference(receiver))
1089result = receiver.Type.IsReadOnly ? RefKind.In : RefKind.Ref;
1160Debug.Assert(condition.Type.SpecialType == SpecialType.System_Boolean);
1163var tmp = _F.SynthesizedLocal(condition.Type, kind: SynthesizedLocalKind.Spill, syntax: _F.Syntax);
1210type: node.Type));
1267_F.ObjectEqual(_F.Local(tmp), _F.Null(left.Type)),
1299if (receiver.Type.IsReferenceType || receiver.Type.IsValueType || receiverRefKind == RefKind.None)
1319var clone = _F.SynthesizedLocal(receiver.Type, _F.Syntax, refKind: RefKind.None, kind: SynthesizedLocalKind.Spill);
1323var isNotClass = _F.IsNotNullReference(_F.Default(receiver.Type));
1491return UpdateExpression(builder, node.Update(operand, node.Type));
1535return UpdateExpression(builder, node.Update(expression, node.Type));
Lowering\SyntheticBoundNodeFactory.cs (50)
267Debug.Assert(receiverOpt is null || receiverOpt.Type is { } &&
268receiverOpt.Type.GetMembers(propertySym.Name).OfType<PropertySymbol>().Single() == propertySym);
279Debug.Assert(!(receiverOpt is { Type: ArrayTypeSymbol { IsSZArray: true } } &&
439Debug.Assert(left.Type is { } && right.Type is { } &&
440(left.Type.Equals(right.Type, TypeCompareKind.AllIgnoreOptions) ||
442right.Type.IsErrorType() || left.Type.IsErrorType()));
444var assignment = new BoundAssignmentOperator(syntax, left, right, isRef, left.Type, hasErrors) { WasCompilerGenerated = wasCompilerGenerated };
569var conversion = Compilation.Conversions.ClassifyConversionFromType(expression.Type, CurrentFunction.ReturnType, isChecked: false, ref useSiteInfo);
658Conversion c = Compilation.Conversions.ClassifyBuiltInConversion(operand.Type, type, isChecked: false, ref discardedUseSiteInfo);
664Debug.Assert(left.Type?.SpecialType == CodeAnalysis.SpecialType.System_Boolean);
665Debug.Assert(right.Type?.SpecialType == CodeAnalysis.SpecialType.System_Boolean);
671Debug.Assert(left.Type?.SpecialType == CodeAnalysis.SpecialType.System_Boolean);
672Debug.Assert(right.Type?.SpecialType == CodeAnalysis.SpecialType.System_Boolean);
691if (value.Type is TypeParameterSymbol { AllowsRefLikeType: true })
801switch (input.Type)
810throw ExceptionUtilities.UnexpectedValue(input.Type);
935Debug.Assert(valueTypeReceiver.Type is { });
936Debug.Assert(TypeSymbol.Equals(valueTypeReceiver.Type, referenceTypeReceiver.Type, TypeCompareKind.ConsiderEverything2));
937return new BoundComplexConditionalReceiver(Syntax, valueTypeReceiver, referenceTypeReceiver, valueTypeReceiver.Type) { WasCompilerGenerated = true };
942Debug.Assert(left.Type!.Equals(right.Type, TypeCompareKind.IgnoreCustomModifiersAndArraySizesAndLowerBounds | TypeCompareKind.IgnoreNullableModifiersForReferenceTypes) || left.Type.IsErrorType());
943Debug.Assert(left.Type.IsReferenceType);
945return new BoundNullCoalescingOperator(Syntax, left, right, leftPlaceholder: null, leftConversion: null, BoundNullCoalescingOperatorResultKind.LeftType, @checked: false, left.Type) { WasCompilerGenerated = true };
1053Debug.Assert(result.Type is { });
1054var resultType = type ?? result.Type;
1060Debug.Assert(result.Type is { });
1064: new BoundSequence(Syntax, locals, sideEffects, result, result.Type) { WasCompilerGenerated = true };
1069Debug.Assert(result.Type is { });
1070return new BoundSpillSequence(Syntax, locals, sideEffects, result, result.Type) { WasCompilerGenerated = true };
1099Debug.Assert(ex.Type is { SpecialType: CodeAnalysis.SpecialType.System_Int32 });
1194Debug.Assert(array.Type is { TypeKind: TypeKind.Array });
1200Debug.Assert(array.Type is { TypeKind: TypeKind.Array });
1201int rank = ((ArrayTypeSymbol)array.Type).Rank;
1213Debug.Assert(array.Type is { TypeKind: TypeKind.Array });
1214return new BoundArrayAccess(Syntax, array, indices, ((ArrayTypeSymbol)array.Type).ElementType);
1519if (TypeSymbol.Equals(type, arg.Type, TypeCompareKind.ConsiderEverything2))
1529Debug.Assert(arg.Type is { });
1616return new BoundCatchBlock(Syntax, ImmutableArray<LocalSymbol>.Empty, source, source.Type, exceptionFilterPrologueOpt: null, exceptionFilterOpt: null, body: block, isSynthesizedAsyncCatchAll: false);
1636Debug.Assert(expression is { Type: { SpecialType: CodeAnalysis.SpecialType.System_Boolean } });
1637return new BoundUnaryOperator(expression.Syntax, UnaryOperatorKind.BoolLogicalNegation, expression, null, null, constrainedToTypeOpt: null, LookupResultKind.Viable, expression.Type);
1657Debug.Assert(argument.Type is { });
1690var type = argument.Type;
1760TypeSymbol exprType = rewrittenExpr.Type;
1814LocalRewriter.UnsafeGetNullableMethod(syntax, expression.Type, CodeAnalysis.SpecialMember.System_Nullable_T_get_HasValue, Compilation, Diagnostics));
1878return conditionalAccess.Update(conditionalAccess.Receiver, conditionalAccess.HasValueMethodOpt, whenNotNull, whenNull, conditionalAccess.Id, conditionalAccess.ForceCopyOfNullableValueType, whenNotNull.Type);