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
dotnet_diagnostic.IDE2003.severity = silent dotnet_diagnostic.IDE2003.severity = silent
#cleared null error types #cleared null error types
dotnet_diagnostic.CS8714.severity = error
dotnet_diagnostic.CS8765.severity = error dotnet_diagnostic.CS8765.severity = error
dotnet_diagnostic.CS8766.severity = error dotnet_diagnostic.CS8766.severity = error
dotnet_diagnostic.CS8767.severity = error dotnet_diagnostic.CS8767.severity = error

3
ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

@ -1799,7 +1799,8 @@ namespace ICSharpCode.Decompiler.CSharp
internal static void AddAnnotationsToDeclaration(IMethod method, EntityDeclaration entityDecl, ILFunction function) internal static void AddAnnotationsToDeclaration(IMethod method, EntityDeclaration entityDecl, ILFunction function)
{ {
int i = 0; 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)) foreach (var parameter in entityDecl.GetChildrenByRole(Roles.Parameter))
{ {
if (parameters.TryGetValue(i, out var v)) if (parameters.TryGetValue(i, out var v))

3
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -2544,7 +2544,8 @@ namespace ICSharpCode.Decompiler.CSharp
IEnumerable<ParameterDeclaration> MakeParameters(IReadOnlyList<IParameter> parameters, ILFunction function) 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; int i = 0;
foreach (var parameter in parameters) foreach (var parameter in parameters)
{ {

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

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

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

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

Loading…
Cancel
Save