提交 bda48318 编写于 作者: C Cyrus Najmabadi

Use simpler null checks

上级 32149eb8
......@@ -3072,7 +3072,7 @@ internal enum AddressKind
bool peVerifyCompatEnabled,
HashSet<LocalSymbol> stackLocalsOpt)
{
Debug.Assert(!(method is null));
Debug.Assert(method is object);
switch (expression.Kind)
{
......@@ -3199,7 +3199,7 @@ internal enum AddressKind
bool peVerifyCompatEnabled,
HashSet<LocalSymbol> stackLocalsOpt)
{
Debug.Assert(!(method is null));
Debug.Assert(method is object);
FieldSymbol field = fieldAccess.FieldSymbol;
......
......@@ -166,7 +166,7 @@ private BoundAttribute BindAttributeCore(AttributeSyntax node, NamedTypeSymbol a
}
diagnostics.Add(node, useSiteDiagnostics);
if (!(attributeConstructor is null))
if (attributeConstructor is object)
{
ReportDiagnosticsIfObsolete(diagnostics, attributeConstructor, node, hasBaseReceiver: false);
......
......@@ -2052,7 +2052,7 @@ private BoundExpression BindRangeExpression(RangeExpressionSyntax node, Diagnost
memberOpt = WellKnownMember.System_Range__StartAt;
}
if (!(memberOpt is null))
if (memberOpt is object)
{
symbolOpt = (MethodSymbol)GetWellKnownTypeMember(
Compilation,
......@@ -7048,7 +7048,7 @@ private BoundExpression ConvertToArrayIndex(BoundExpression index, SyntaxNode no
if (result is null)
{
result = TryImplicitConversionToArrayIndex(index, WellKnownType.System_Range, node, diagnostics);
if (!(result is null))
if (result is object)
{
// This member is needed for lowering and should produce an error if not present
_ = GetWellKnownTypeMember(
......@@ -7097,7 +7097,7 @@ private BoundExpression TryImplicitConversionToArrayIndex(BoundExpression expr,
var attemptDiagnostics = DiagnosticBag.GetInstance();
var result = TryImplicitConversionToArrayIndex(expr, type, node, attemptDiagnostics);
if (!(result is null))
if (result is object)
{
diagnostics.AddRange(attemptDiagnostics);
}
......@@ -7113,7 +7113,7 @@ private BoundExpression TryImplicitConversionToArrayIndex(BoundExpression expr,
var result = TryImplicitConversionToArrayIndex(expr, type, node, attemptDiagnostics);
if (!(result is null))
if (result is object)
{
diagnostics.AddRange(attemptDiagnostics);
}
......
......@@ -689,7 +689,7 @@ private BoundStatement BindDeclarationStatementParts(LocalDeclarationStatementSy
/// <returns>The <see cref="MethodSymbol"/> of the Dispose method if one is found, otherwise null.</returns>
internal MethodSymbol TryFindDisposePatternMethod(BoundExpression expr, SyntaxNode syntaxNode, bool hasAwait, DiagnosticBag diagnostics)
{
Debug.Assert(!(expr is null));
Debug.Assert(expr is object);
Debug.Assert(!(expr.Type is null));
Debug.Assert(expr.Type.IsRefLikeType || hasAwait); // pattern dispose lookup is only valid on ref structs or asynchronous usings
......
......@@ -868,7 +868,7 @@ private void GetDisposalInfoForEnumerator(ref ForEachEnumeratorInfo.Builder buil
var patternDisposeDiags = new DiagnosticBag();
var receiver = new BoundDisposableValuePlaceholder(_syntax, enumeratorType);
MethodSymbol disposeMethod = TryFindDisposePatternMethod(receiver, _syntax, isAsync, patternDisposeDiags);
if (!(disposeMethod is null))
if (disposeMethod is object)
{
builder.NeedsDisposal = true;
builder.DisposeMethod = disposeMethod;
......
......@@ -62,7 +62,7 @@ internal static class AccessCheck
/// </summary>
internal static bool IsEffectivelyPublicOrInternal(Symbol symbol, out bool isInternal)
{
Debug.Assert(!(symbol is null));
Debug.Assert(symbol is object);
switch (symbol.Kind)
{
......@@ -101,7 +101,7 @@ internal static bool IsEffectivelyPublicOrInternal(Symbol symbol, out bool isInt
symbol = symbol.ContainingType;
}
while (!(symbol is null));
while (symbol is object);
return true;
}
......
......@@ -125,7 +125,7 @@ private TypeSymbol InferResultType(ImmutableArray<BoundSwitchExpressionArm> swit
foreach (var @case in switchCases)
{
var type = @case.Value.Type;
if (!(type is null) && seenTypes.Add(type))
if (type is object && seenTypes.Add(type))
{
typesInOrder.Add(type);
}
......
......@@ -189,14 +189,14 @@ bool populateDisposableConversionOrDisposeMethod(bool fromExpression)
// If this is a ref struct, or we're in a valid asynchronous using, try binding via pattern.
// We won't need to try and bind a second time if it fails, as async dispose can't be pattern based (ref structs are not allowed in async methods)
if (!(type is null) && (type.IsRefLikeType || hasAwait))
if (type is object && (type.IsRefLikeType || hasAwait))
{
BoundExpression receiver = fromExpression
? expressionOpt
: new BoundLocal(syntax, declarationsOpt[0].LocalSymbol, null, type) { WasCompilerGenerated = true };
disposeMethodOpt = originalBinder.TryFindDisposePatternMethod(receiver, syntax, hasAwait, diagnostics);
if (!(disposeMethodOpt is null))
if (disposeMethodOpt is object)
{
if (hasAwait)
{
......
......@@ -3326,7 +3326,7 @@ internal bool EmitNullablePublicOnly
internal bool ShouldEmitNullableAttributes(Symbol symbol)
{
Debug.Assert(!(symbol is null));
Debug.Assert(symbol is object);
Debug.Assert(symbol.IsDefinition);
if (symbol.ContainingModule != SourceModule)
......
......@@ -36,7 +36,7 @@ private static void GetRawDiagnosticInfos(bool isNullableEnabled, CSharpParseOpt
{
const MessageID featureId = MessageID.IDS_FeatureNullableReferenceTypes;
var info = featureId.GetFeatureAvailabilityDiagnosticInfoOpt(options);
if (!(info is null))
if (info is object)
{
infos.Add(info);
}
......
......@@ -233,7 +233,7 @@ internal static string RequiredFeature(this MessageID feature)
internal static bool CheckFeatureAvailability(this MessageID feature, DiagnosticBag diagnostics, Location errorLocation)
{
var diag = GetFeatureAvailabilityDiagnosticInfoOpt(feature, (CSharpParseOptions)errorLocation.SourceTree.Options);
if (!(diag is null))
if (diag is object)
{
diagnostics.Add(diag, errorLocation);
return false;
......
......@@ -412,7 +412,7 @@ protected override ImmutableArray<PendingBranch> Scan(ref bool badRegion)
{
ParameterSymbol methodThisParameter = MethodThisParameter;
EnterParameters(); // assign parameters
if (!(methodThisParameter is null))
if (methodThisParameter is object)
{
EnterParameter(methodThisParameter, methodThisParameter.TypeWithAnnotations);
}
......@@ -1869,7 +1869,7 @@ public override BoundNode VisitAnonymousObjectCreationExpression(BoundAnonymousO
TrackNullableStateForAssignment(argument, property.TypeWithAnnotations, GetOrCreateSlot(property, receiverSlot), argumentType, MakeSlot(argument));
var currentDeclaration = getDeclaration(node, property, ref currentDeclarationIndex);
if (!(currentDeclaration is null))
if (currentDeclaration is object)
{
TakeIncrementalSnapshot(currentDeclaration);
SetAnalyzedNullability(currentDeclaration, new VisitResult(argumentType, property.TypeWithAnnotations));
......@@ -2509,7 +2509,7 @@ public override BoundNode VisitNullCoalescingOperator(BoundNullCoalescingOperato
TypeSymbol getLeftResultType(TypeSymbol leftType, TypeSymbol rightType)
{
Debug.Assert(!(rightType is null));
Debug.Assert(rightType is object);
// If there was an identity conversion between the two operands (in short, if there
// is no implicit conversion on the right operand), then check nullable conversions
// in both directions since it's possible the right operand is the better result type.
......
......@@ -424,7 +424,7 @@ private BoundExpression GenerateDisposeCall(SyntaxNode syntax, BoundExpression d
{
disposeCall = MakeCallWithNoExplicitArgument(syntax, disposedExpression, methodOpt);
if (!(awaitOpt is null))
if (awaitOpt is object)
{
// await local.DisposeAsync()
_sawAwaitInExceptionHandler = true;
......
......@@ -711,7 +711,7 @@ internal IEnumerable<NamedTypeSymbol> GetForwardedTypes()
internal bool ShouldDecodeNullableAttributes(Symbol symbol)
{
Debug.Assert(!(symbol is null));
Debug.Assert(symbol is object);
Debug.Assert(symbol.IsDefinition);
Debug.Assert((object)symbol.ContainingModule == this);
......
......@@ -434,7 +434,7 @@ private NamedTypeSymbol GetDeclaredBaseType(bool skipTransformsIfNecessary)
if (ReferenceEquals(_lazyDeclaredBaseType, ErrorTypeSymbol.UnknownResultType))
{
var baseType = MakeDeclaredBaseType();
if (!(baseType is null))
if (baseType is object)
{
if (skipTransformsIfNecessary)
{
......
......@@ -229,7 +229,7 @@ internal void ComputeReturnType()
// Skip some diagnostics when the local function is not associated with a compilation
// (specifically, local functions nested in expressions in the EE).
if (!(compilation is null))
if (compilation is object)
{
if (this.IsAsync)
{
......
......@@ -3339,7 +3339,7 @@ private void AddAccessorIfAvailable(ArrayBuilder<Symbol> symbols, MethodSymbol a
var builder = new MostCommonNullableValueBuilder();
var baseType = BaseTypeNoUseSiteDiagnostics;
if (!(baseType is null))
if (baseType is object)
{
builder.AddValue(TypeWithAnnotations.Create(baseType));
}
......@@ -3366,7 +3366,7 @@ internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, r
var compilation = DeclaringCompilation;
NamedTypeSymbol baseType = this.BaseTypeNoUseSiteDiagnostics;
if (!(baseType is null))
if (baseType is object)
{
if (baseType.ContainsDynamic())
{
......@@ -3386,7 +3386,7 @@ internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, r
AddSynthesizedAttribute(ref attributes, moduleBuilder.SynthesizeNullableContextAttribute(this, nullableContextValue));
}
if (!(baseType is null))
if (baseType is object)
{
AddSynthesizedAttribute(ref attributes, moduleBuilder.SynthesizeNullableAttributeIfNecessary(this, nullableContextValue, TypeWithAnnotations.Create(baseType)));
}
......
......@@ -593,7 +593,7 @@ private static void AssertNullablePublicOnlyAttribute(ModuleSymbol module, bool
type = attribute.AttributeClass;
}
}
if (!(type is null))
if (type is object)
{
Assert.Equal(publicDefinition ? Accessibility.Public : Accessibility.Internal, type.DeclaredAccessibility);
}
......
......@@ -37,7 +37,7 @@ private static void RunInThread(Action action)
thread.Start();
thread.Join();
if (!(exception is null))
if (exception is object)
{
throw exception;
}
......
......@@ -1261,7 +1261,7 @@ public bool HasImplicitConversion(ITypeSymbol fromType, ITypeSymbol toType)
checkInCompilationReferences(symbol, nameof(symbol));
checkInCompilationReferences(within, nameof(within));
if (!(throughType is null))
if (throughType is object)
{
checkInCompilationReferences(throughType, nameof(throughType));
}
......
......@@ -181,7 +181,7 @@ protected void SetParentOperation(IOperation parent)
[Conditional("DEBUG")]
internal static void VerifyParentOperation(IOperation parent, IOperation child)
{
if (!(child is null))
if (child is object)
{
Debug.Assert((object)child.Parent == parent);
}
......
......@@ -32,7 +32,7 @@ internal struct SyntaxTreeInfo
int length,
ImmutableDictionary<string, ReportDiagnostic> diagnosticOptions)
{
Debug.Assert(!(diagnosticOptions is null));
Debug.Assert(diagnosticOptions is object);
FilePath = filePath ?? string.Empty;
Options = options;
......@@ -86,7 +86,7 @@ internal SyntaxTreeInfo WithOptionsAndLength(ParseOptions options, int length)
internal SyntaxTreeInfo WithDiagnosticOptions(ImmutableDictionary<string, ReportDiagnostic> options)
{
Debug.Assert(!(options is null));
Debug.Assert(options is object);
return new SyntaxTreeInfo(
FilePath,
Options,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册