Browse Source

more nullability updates focus CS8619

pull/3287/head
apmoskevitz 9 months ago
parent
commit
b652648db3
  1. 4
      ICSharpCode.BamlDecompiler/Baml/BamlContext.cs
  2. 4
      ICSharpCode.Decompiler/CSharp/CallBuilder.cs
  3. 2
      ICSharpCode.Decompiler/CSharp/Resolver/MemberLookup.cs
  4. 6
      ICSharpCode.Decompiler/CSharp/StatementBuilder.cs
  5. 2
      ICSharpCode.Decompiler/CSharp/Syntax/Roles.cs
  6. 2
      ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs
  7. 4
      ICSharpCode.Decompiler/DebugInfo/IDebugInfoProvider.cs
  8. 18
      ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs
  9. 2
      ICSharpCode.Decompiler/IL/ControlFlow/AwaitInCatchTransform.cs
  10. 10
      ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs
  11. 4
      ICSharpCode.Decompiler/IL/Transforms/TransformExpressionTrees.cs

4
ICSharpCode.BamlDecompiler/Baml/BamlContext.cs

@ -37,7 +37,7 @@ namespace ICSharpCode.BamlDecompiler.Baml @@ -37,7 +37,7 @@ namespace ICSharpCode.BamlDecompiler.Baml
public IDecompilerTypeSystem TypeSystem { get; }
public KnownThings KnownThings { get; }
Dictionary<ushort, (string FullAssemblyName, IModule Assembly)> assemblyMap = new Dictionary<ushort, (string FullAssemblyName, IModule Assembly)>();
Dictionary<ushort, (string? FullAssemblyName, IModule? Assembly)> assemblyMap = new Dictionary<ushort, (string? FullAssemblyName, IModule? Assembly)>();
public Dictionary<ushort, AssemblyInfoRecord> AssemblyIdMap { get; }
public Dictionary<ushort, AttributeInfoRecord> AttributeIdMap { get; }
@ -88,7 +88,7 @@ namespace ICSharpCode.BamlDecompiler.Baml @@ -88,7 +88,7 @@ namespace ICSharpCode.BamlDecompiler.Baml
return ctx;
}
public (string FullAssemblyName, IModule Assembly) ResolveAssembly(ushort id)
public (string? FullAssemblyName, IModule? Assembly) ResolveAssembly(ushort id)
{
id &= 0xfff;
if (!assemblyMap.TryGetValue(id, out var assembly))

4
ICSharpCode.Decompiler/CSharp/CallBuilder.cs

@ -711,7 +711,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -711,7 +711,7 @@ namespace ICSharpCode.Decompiler.CSharp
return false;
tokens = new List<(TokenKind Kind, int Index, int Alignment, string? Format)>();
int i = 0;
format = (string)crr.ConstantValue;
format = (string?)crr.ConstantValue;
foreach (var (kind, data) in TokenizeFormatString(format))
{
int index;
@ -1827,7 +1827,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1827,7 +1827,7 @@ namespace ICSharpCode.Decompiler.CSharp
{
ExpressionBuilder expressionBuilder = this.expressionBuilder;
ExpressionWithResolveResult targetExpression;
(TranslatedExpression target, bool addTypeArguments, string methodName, ResolveResult result) = DisambiguateDelegateReference(method, invokeMethod, expectedTargetDetails, thisArg);
(TranslatedExpression target, bool addTypeArguments, string? methodName, ResolveResult result) = DisambiguateDelegateReference(method, invokeMethod, expectedTargetDetails, thisArg);
if (target.Expression != null)
{
var mre = new MemberReferenceExpression(target, methodName);

2
ICSharpCode.Decompiler/CSharp/Resolver/MemberLookup.cs

@ -189,7 +189,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -189,7 +189,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
{
var nestedTypes = type.GetNestedTypes(options: GetMemberOptions.IgnoreInheritedMembers | GetMemberOptions.ReturnMemberDefinitions);
// GetDefinition() might return null if some IType has a strange implementation of GetNestedTypes.
entities.AddRange(nestedTypes.Select(t => t.GetDefinition()).Where(td => td != null));
entities.AddRange(nestedTypes.Select(t => t.GetDefinition()).OfType<ITypeDefinition>());
}
foreach (var entityGroup in entities.GroupBy(e => e.Name))

6
ICSharpCode.Decompiler/CSharp/StatementBuilder.cs

@ -152,7 +152,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -152,7 +152,7 @@ namespace ICSharpCode.Decompiler.CSharp
return new IfElseStatement(condition, trueStatement, falseStatement).WithILInstruction(inst);
}
internal IEnumerable<ConstantResolveResult> CreateTypedCaseLabel(long i, IType type, List<(string Key, int Value)>? map = null)
internal IEnumerable<ConstantResolveResult> CreateTypedCaseLabel(long i, IType type, List<(string? Key, int Value)>? map = null)
{
object value;
// unpack nullable type, if necessary:
@ -204,7 +204,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -204,7 +204,7 @@ namespace ICSharpCode.Decompiler.CSharp
return TranslateSwitch(null, inst).WithILInstruction(inst);
}
SwitchStatement TranslateSwitch(BlockContainer switchContainer, SwitchInstruction inst)
SwitchStatement TranslateSwitch(BlockContainer? switchContainer, SwitchInstruction inst)
{
var oldBreakTarget = breakTarget;
breakTarget = switchContainer; // 'break' within a switch would only leave the switch
@ -385,7 +385,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -385,7 +385,7 @@ namespace ICSharpCode.Decompiler.CSharp
}
/// <summary>Target container that a 'break;' statement would break out of</summary>
BlockContainer breakTarget;
BlockContainer? breakTarget;
/// <summary>Dictionary from BlockContainer to label name for 'goto of_container';</summary>
readonly Dictionary<BlockContainer, string> endContainerLabels = new Dictionary<BlockContainer, string>();

2
ICSharpCode.Decompiler/CSharp/Syntax/Roles.cs

@ -29,7 +29,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -29,7 +29,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
{
public static class Roles
{
public static readonly Role<AstNode> Root = AstNode.RootRole;
public static readonly Role<AstNode?> Root = AstNode.RootRole;
// some pre defined constants for common roles
public static readonly Role<Identifier> Identifier = new Role<Identifier>("Identifier", Syntax.Identifier.Null);

2
ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs

@ -1291,7 +1291,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -1291,7 +1291,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
}
return new CastExpression(ConvertType(type), new PrimitiveExpression(CSharpPrimitiveCast.Cast(enumBaseTypeCode, val, false)));
(long value, IField field) PrepareConstant(IField field)
(long value, IField? field) PrepareConstant(IField field)
{
if (!field.IsConst)
return (-1, null);

4
ICSharpCode.Decompiler/DebugInfo/IDebugInfoProvider.cs

@ -20,8 +20,8 @@ namespace ICSharpCode.Decompiler.DebugInfo @@ -20,8 +20,8 @@ namespace ICSharpCode.Decompiler.DebugInfo
public struct PdbExtraTypeInfo
{
public string[] TupleElementNames;
public bool[] DynamicFlags;
public string?[]? TupleElementNames;
public bool[]? DynamicFlags;
}
public interface IDebugInfoProvider

18
ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs

@ -475,7 +475,7 @@ namespace ICSharpCode.Decompiler.Disassembler @@ -475,7 +475,7 @@ namespace ICSharpCode.Decompiler.Disassembler
}
}
class SecurityDeclarationDecoder : ICustomAttributeTypeProvider<(PrimitiveTypeCode, string)>
class SecurityDeclarationDecoder : ICustomAttributeTypeProvider<(PrimitiveTypeCode, string?)>
{
readonly ITextOutput output;
readonly IAssemblyResolver resolver;
@ -488,32 +488,32 @@ namespace ICSharpCode.Decompiler.Disassembler @@ -488,32 +488,32 @@ namespace ICSharpCode.Decompiler.Disassembler
this.module = module;
}
public (PrimitiveTypeCode, string) GetPrimitiveType(PrimitiveTypeCode typeCode)
public (PrimitiveTypeCode, string?) GetPrimitiveType(PrimitiveTypeCode typeCode)
{
return (typeCode, null);
}
public (PrimitiveTypeCode, string) GetSystemType()
public (PrimitiveTypeCode, string?) GetSystemType()
{
return (0, "type");
}
public (PrimitiveTypeCode, string) GetSZArrayType((PrimitiveTypeCode, string) elementType)
public (PrimitiveTypeCode, string?) GetSZArrayType((PrimitiveTypeCode, string?) elementType)
{
return (elementType.Item1, (elementType.Item2 ?? PrimitiveTypeCodeToString(elementType.Item1)) + "[]");
}
public (PrimitiveTypeCode, string) GetTypeFromDefinition(MetadataReader reader, TypeDefinitionHandle handle, byte rawTypeKind)
public (PrimitiveTypeCode, string?) GetTypeFromDefinition(MetadataReader reader, TypeDefinitionHandle handle, byte rawTypeKind)
{
throw new NotImplementedException();
}
public (PrimitiveTypeCode, string) GetTypeFromReference(MetadataReader reader, TypeReferenceHandle handle, byte rawTypeKind)
public (PrimitiveTypeCode, string?) GetTypeFromReference(MetadataReader reader, TypeReferenceHandle handle, byte rawTypeKind)
{
throw new NotImplementedException();
}
public (PrimitiveTypeCode, string) GetTypeFromSerializedName(string name)
public (PrimitiveTypeCode, string?) GetTypeFromSerializedName(string name)
{
if (resolver == null)
throw new EnumUnderlyingTypeResolveException();
@ -525,12 +525,12 @@ namespace ICSharpCode.Decompiler.Disassembler @@ -525,12 +525,12 @@ namespace ICSharpCode.Decompiler.Disassembler
return (0, name);
}
public PrimitiveTypeCode GetUnderlyingEnumType((PrimitiveTypeCode, string) type)
public PrimitiveTypeCode GetUnderlyingEnumType((PrimitiveTypeCode, string?) type)
{
return type.Item1;
}
public bool IsSystemType((PrimitiveTypeCode, string) type)
public bool IsSystemType((PrimitiveTypeCode, string?) type)
{
return "type" == type.Item2;
}

2
ICSharpCode.Decompiler/IL/ControlFlow/AwaitInCatchTransform.cs

@ -420,7 +420,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow @@ -420,7 +420,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
// =>
// throw(ldloc result.Handler.Variable)
internal static bool MatchExceptionCaptureBlock(ILTransformContext context, Block block,
ref ILVariable? objectVariable, out StLoc? typedExceptionVariableStore, out Block? captureBlock, out Block? throwBlock)
[NotNullWhen(true)] ref ILVariable? objectVariable, [NotNullWhen(true)] out StLoc? typedExceptionVariableStore, [NotNullWhen(true)] out Block? captureBlock, [NotNullWhen(true)] out Block? throwBlock)
{
bool DerivesFromException(IType t) => t.GetAllBaseTypes().Any(ty => ty.IsKnownType(KnownTypeCode.Exception));

10
ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs

@ -422,8 +422,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -422,8 +422,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms
return false;
switchValueVar = switchValueVarCopy;
int conditionOffset = 1;
Block currentCaseBlock = isInternedBlock;
var values = new List<(string, ILInstruction)>();
Block? currentCaseBlock = isInternedBlock;
var values = new List<(string?, ILInstruction)>();
if (!switchValueVarCopy.IsSingleDefinition)
return false;
@ -440,9 +440,9 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -440,9 +440,9 @@ namespace ICSharpCode.Decompiler.IL.Transforms
break;
if (!left.MatchLdLoc(switchValueVar))
break;
if (!right.MatchLdStr(out string value))
if (!right.MatchLdStr(out string? value))
break;
if (!(caseBlockJump.MatchBranch(out var caseBlock) || caseBlockJump.MatchLeave((BlockContainer)currentCaseBlock.Parent)))
if (!(caseBlockJump.MatchBranch(out var caseBlock) || caseBlockJump.MatchLeave((BlockContainer?)currentCaseBlock.Parent)))
break;
if (!currentCaseBlock.Instructions[conditionOffset + 1].MatchBranch(out currentCaseBlock))
break;
@ -705,7 +705,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -705,7 +705,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
return true;
}
bool FixCasesWithoutValue(List<SwitchSection> sections, List<(string, int)> stringValues)
bool FixCasesWithoutValue(List<SwitchSection> sections, List<(string?, int)> stringValues)
{
bool HasLabel(SwitchSection section)
{

4
ICSharpCode.Decompiler/IL/Transforms/TransformExpressionTrees.cs

@ -398,7 +398,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -398,7 +398,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
{
if (function.Kind == ILFunctionKind.ExpressionTree)
{
function.DelegateType = UnwrapExpressionTree(function.DelegateType);
function.DelegateType = UnwrapExpressionTree(function.DelegateType!);
function.Kind = ILFunctionKind.Delegate;
}
return function;
@ -536,7 +536,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -536,7 +536,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
}
}
(Func<ILVariable, ILInstruction>, IType) ConvertBind(CallInstruction invocation)
(Func<ILVariable, ILInstruction>?, IType) ConvertBind(CallInstruction invocation)
{
if (invocation.Arguments.Count != 2)
return (null, SpecialType.UnknownType);

Loading…
Cancel
Save