Browse Source

focus on CS8714

pull/3287/head
apmoskevitz 11 months ago
parent
commit
cc6470728a
  1. 1
      .editorconfig
  2. 3
      ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs
  3. 3
      ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs
  4. 12
      ICSharpCode.Decompiler/CSharp/Syntax/AstNode.cs
  5. 12
      ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/ParameterDeclaration.cs

1
.editorconfig

@ -152,6 +152,7 @@ dotnet_diagnostic.MEF006.severity = silent @@ -152,6 +152,7 @@ dotnet_diagnostic.MEF006.severity = silent
dotnet_diagnostic.IDE2003.severity = silent
#cleared null error types
dotnet_diagnostic.CS8714.severity = error
dotnet_diagnostic.CS8765.severity = error
dotnet_diagnostic.CS8766.severity = error
dotnet_diagnostic.CS8767.severity = error

3
ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

@ -1799,7 +1799,8 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1799,7 +1799,8 @@ namespace ICSharpCode.Decompiler.CSharp
internal static void AddAnnotationsToDeclaration(IMethod method, EntityDeclaration entityDecl, ILFunction function)
{
int i = 0;
var parameters = function.Variables.Where(v => v.Kind == VariableKind.Parameter).ToDictionary(v => v.Index);
//if the variable is a parameter is a parameter then index "should not" be null, would indicate an deeper under lying problem if it is so we assert not null (!)
var parameters = function.Variables.Where(v => v.Kind == VariableKind.Parameter).ToDictionary(v => v.Index!.Value);
foreach (var parameter in entityDecl.GetChildrenByRole(Roles.Parameter))
{
if (parameters.TryGetValue(i, out var v))

3
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -2544,7 +2544,8 @@ namespace ICSharpCode.Decompiler.CSharp @@ -2544,7 +2544,8 @@ namespace ICSharpCode.Decompiler.CSharp
IEnumerable<ParameterDeclaration> MakeParameters(IReadOnlyList<IParameter> parameters, ILFunction function)
{
var variables = function.Variables.Where(v => v.Kind == VariableKind.Parameter).ToDictionary(v => v.Index);
//if the variable is a parameter is a parameter then index "should not" be null, would indicate an deeper under lying problem if it is so we assert not null (!)
var variables = function.Variables.Where(v => v.Kind == VariableKind.Parameter).ToDictionary(v => v.Index!.Value);
int i = 0;
foreach (var parameter in parameters)
{

12
ICSharpCode.Decompiler/CSharp/Syntax/AstNode.cs

@ -340,7 +340,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -340,7 +340,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// Gets the first child with the specified role.
/// Returns the role's null object if the child is not found.
/// </summary>
public T GetChildByRole<T>(Role<T> role) where T : AstNode?
public T? GetChildByRole<T>(Role<T> role) where T : AstNode
{
if (role == null)
throw new ArgumentNullException(nameof(role));
@ -348,7 +348,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -348,7 +348,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
for (var cur = firstChild; cur != null; cur = cur.nextSibling)
{
if ((cur.flags & roleIndexMask) == roleIndex)
return (T)cur;
return (T?)cur;
}
return role.NullObject;
}
@ -368,16 +368,16 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -368,16 +368,16 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
return new AstNodeCollection<T>(this, role);
}
protected void SetChildByRole<T>(Role<T> role, T newChild) where T : AstNode
protected void SetChildByRole<T>(Role<T> role, T? newChild) where T : AstNode
{
AstNode oldChild = GetChildByRole(role);
if (oldChild.IsNull)
AstNode? oldChild = GetChildByRole(role);
if (oldChild?.IsNull != false)
AddChild(newChild, role);
else
oldChild.ReplaceWith(newChild);
}
public void AddChild<T>(T child, Role<T> role) where T : AstNode
public void AddChild<T>(T? child, Role<T> role) where T : AstNode
{
if (role == null)
throw new ArgumentNullException(nameof(role));

12
ICSharpCode.Decompiler/CSharp/Syntax/TypeMembers/ParameterDeclaration.cs

@ -97,7 +97,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -97,7 +97,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
bool isParams;
bool isScopedRef;
public CSharpTokenNode ThisKeyword {
public CSharpTokenNode? ThisKeyword {
get {
if (hasThisModifier)
{
@ -141,21 +141,21 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -141,21 +141,21 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
}
}
public AstType Type {
public AstType? Type {
get { return GetChildByRole(Roles.Type); }
set { SetChildByRole(Roles.Type, value); }
}
public string Name {
get {
return GetChildByRole(Roles.Identifier).Name;
return GetChildByRole(Roles.Identifier)?.Name ?? "";
}
set {
SetChildByRole(Roles.Identifier, Identifier.Create(value));
}
}
public Identifier NameToken {
public Identifier? NameToken {
get {
return GetChildByRole(Roles.Identifier);
}
@ -164,11 +164,11 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -164,11 +164,11 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
}
}
public CSharpTokenNode AssignToken {
public CSharpTokenNode? AssignToken {
get { return GetChildByRole(Roles.Assign); }
}
public Expression DefaultExpression {
public Expression? DefaultExpression {
get { return GetChildByRole(Roles.Expression); }
set { SetChildByRole(Roles.Expression, value); }
}

Loading…
Cancel
Save