Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nullability #3287

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
  •  
  •  
  •  
60 changes: 60 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,63 @@ dotnet_naming_rule.private_fields_rule.symbols = private_fields_symbols

# MEF006: No importing constructor
dotnet_diagnostic.MEF006.severity = silent


dotnet_diagnostic.IDE2003.severity = silent

#nullability diagnostics
dotnet_diagnostic.CS8597.severity = error
dotnet_diagnostic.CS8600.severity = warning
dotnet_diagnostic.CS8601.severity = warning
dotnet_diagnostic.CS8602.severity = warning
dotnet_diagnostic.CS8603.severity = warning
dotnet_diagnostic.CS8604.severity = warning
dotnet_diagnostic.CS8605.severity = warning
dotnet_diagnostic.CS8606.severity = error
dotnet_diagnostic.CS8607.severity = error
dotnet_diagnostic.CS8608.severity = error
dotnet_diagnostic.CS8609.severity = error
dotnet_diagnostic.CS8610.severity = error
dotnet_diagnostic.CS8611.severity = error
dotnet_diagnostic.CS8612.severity = error
dotnet_diagnostic.CS8613.severity = error
dotnet_diagnostic.CS8614.severity = error
dotnet_diagnostic.CS8615.severity = error
dotnet_diagnostic.CS8617.severity = warning
dotnet_diagnostic.CS8618.severity = warning
dotnet_diagnostic.CS8619.severity = warning
dotnet_diagnostic.CS8620.severity = warning
dotnet_diagnostic.CS8621.severity = error
dotnet_diagnostic.CS8622.severity = error
dotnet_diagnostic.CS8624.severity = error
dotnet_diagnostic.CS8625.severity = error
dotnet_diagnostic.CS8629.severity = warning
dotnet_diagnostic.CS8631.severity = warning
dotnet_diagnostic.CS8633.severity = error
dotnet_diagnostic.CS8634.severity = error
dotnet_diagnostic.CS8643.severity = error
dotnet_diagnostic.CS8644.severity = error
dotnet_diagnostic.CS8645.severity = error
dotnet_diagnostic.CS8655.severity = error
dotnet_diagnostic.CS8667.severity = error
dotnet_diagnostic.CS8670.severity = error
dotnet_diagnostic.CS8714.severity = error
dotnet_diagnostic.CS8762.severity = error
dotnet_diagnostic.CS8763.severity = error
dotnet_diagnostic.CS8764.severity = error
dotnet_diagnostic.CS8765.severity = error
dotnet_diagnostic.CS8766.severity = error
dotnet_diagnostic.CS8767.severity = error
dotnet_diagnostic.CS8768.severity = error
dotnet_diagnostic.CS8769.severity = error
dotnet_diagnostic.CS8770.severity = error
dotnet_diagnostic.CS8773.severity = error
dotnet_diagnostic.CS8774.severity = error
dotnet_diagnostic.CS8775.severity = error
dotnet_diagnostic.CS8776.severity = error
dotnet_diagnostic.CS8775.severity = error
dotnet_diagnostic.CS8777.severity = error

#nullable error types still not cleaned up


6 changes: 3 additions & 3 deletions ICSharpCode.BamlDecompiler/Baml/BamlContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal class BamlContext
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; }
Expand Down Expand Up @@ -88,7 +88,7 @@ public static BamlContext ConstructContext(IDecompilerTypeSystem typeSystem, Bam
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))
Expand Down Expand Up @@ -116,7 +116,7 @@ public static BamlContext ConstructContext(IDecompilerTypeSystem typeSystem, Bam

private IModule FindMatchingReference(AssemblyNameReference name)
{
IModule bestMatch = null;
IModule? bestMatch = null;
foreach (var module in TypeSystem.ReferencedModules)
{
if (module.AssemblyName == name.Name)
Expand Down
2 changes: 1 addition & 1 deletion ICSharpCode.BamlDecompiler/Baml/BamlNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public static BamlNode Parse(BamlDocument document, CancellationToken token)
{
Debug.Assert(document.Count > 0 && document[0].Type == BamlRecordType.DocumentStart);

BamlBlockNode current = null;
BamlBlockNode? current = null;
var stack = new Stack<BamlBlockNode>();

for (int i = 0; i < document.Count; i++)
Expand Down
2 changes: 1 addition & 1 deletion ICSharpCode.BamlDecompiler/Baml/BamlReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static BamlDocument ReadDocument(Stream str, CancellationToken token)

long pos = str.Position;
var type = (BamlRecordType)reader.ReadByte();
BamlRecord rec = null;
BamlRecord? rec = null;
switch (type)
{
case BamlRecordType.AssemblyInfo:
Expand Down
4 changes: 2 additions & 2 deletions ICSharpCode.BamlDecompiler/BamlDecompilerSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public bool ThrowOnAssemblyResolveErrors {
}
}

public event PropertyChangedEventHandler PropertyChanged;
public event PropertyChangedEventHandler? PropertyChanged;

protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
{
if (PropertyChanged != null)
{
Expand Down
10 changes: 5 additions & 5 deletions ICSharpCode.BamlDecompiler/BamlElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@ internal readonly struct XamlNode
String = value;
}

public readonly XElement Element;
public readonly string String;
public readonly XElement? Element;
public readonly string? String;

public static implicit operator XamlNode(XElement value) => new XamlNode(value);
public static implicit operator XamlNode(string value) => new XamlNode(value);
public static implicit operator XElement(XamlNode node) => node.Element;
public static implicit operator string(XamlNode node) => node.String;
public static implicit operator XElement?(XamlNode node) => node.Element;
public static implicit operator string?(XamlNode node) => node.String;
}

internal class BamlElement
{
public BamlNode Node { get; }
public XamlNode Xaml { get; set; }

public BamlElement Parent { get; set; }
public BamlElement? Parent { get; set; }
public IList<BamlElement> Children { get; }

public BamlElement(BamlNode node)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal class ConstructorParametersStartHandler : IHandler
{
public BamlRecordType Type => BamlRecordType.ConstructorParametersStart;

public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
var doc = new BamlElement(node);
doc.Xaml = new XElement(ctx.GetPseudoName("Ctor"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal class DocumentHandler : IHandler
{
public BamlRecordType Type => BamlRecordType.DocumentStart;

public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
var doc = new BamlElement(node);
doc.Xaml = new XElement(ctx.GetPseudoName("Document"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal class ElementHandler : IHandler
{
public BamlRecordType Type => BamlRecordType.ElementStart;

public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
var record = (ElementStartRecord)((BamlBlockNode)node).Header;
var doc = new BamlElement(node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal class KeyElementStartHandler : ElementHandler, IHandler, IDeferHandler
{
BamlRecordType IHandler.Type => BamlRecordType.KeyElementStart;

BamlElement IHandler.Translate(XamlContext ctx, BamlNode node, BamlElement parent)
BamlElement? IHandler.Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
XamlResourceKey.Create(node);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal class PropertyArrayHandler : IHandler
{
public BamlRecordType Type => BamlRecordType.PropertyArrayStart;

public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
var record = (PropertyArrayStartRecord)((BamlBlockNode)node).Header;
var doc = new BamlElement(node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal class PropertyComplexHandler : IHandler
{
public BamlRecordType Type => BamlRecordType.PropertyComplexStart;

public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
var record = (PropertyComplexStartRecord)((BamlBlockNode)node).Header;
var doc = new BamlElement(node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal class PropertyDictionaryHandler : IHandler
{
public BamlRecordType Type => BamlRecordType.PropertyDictionaryStart;

public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
var record = (PropertyDictionaryStartRecord)((BamlBlockNode)node).Header;
var doc = new BamlElement(node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal class PropertyListHandler : IHandler
{
public BamlRecordType Type => BamlRecordType.PropertyListStart;

public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
var record = (PropertyListStartRecord)((BamlBlockNode)node).Header;
var doc = new BamlElement(node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ internal class AssemblyInfoHandler : IHandler
{
public BamlRecordType Type => BamlRecordType.AssemblyInfo;

public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) => null;
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent) => null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ internal class AttributeInfoHandler : IHandler
{
public BamlRecordType Type => BamlRecordType.AttributeInfo;

public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) => null;
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent) => null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal class ConnectionIdHandler : IHandler
{
public BamlRecordType Type => BamlRecordType.ConnectionId;

public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
var record = (ConnectionIdRecord)((BamlRecordNode)node).Record;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal class ConstructorParameterTypeHandler : IHandler
{
public BamlRecordType Type => BamlRecordType.ConstructorParameterType;

public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
var record = (ConstructorParameterTypeRecord)((BamlRecordNode)node).Record;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal class ContentPropertyHandler : IHandler
{
public BamlRecordType Type => BamlRecordType.ContentProperty;

public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
var record = (ContentPropertyRecord)((BamlRecordNode)node).Record;
// TODO: What to do here?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal class DefAttributeHandler : IHandler
{
public BamlRecordType Type => BamlRecordType.DefAttribute;

public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
var record = (DefAttributeRecord)((BamlRecordNode)node).Record;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal class DefAttributeStringHandler : IHandler, IDeferHandler
{
public BamlRecordType Type => BamlRecordType.DefAttributeKeyString;

public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
XamlResourceKey.Create(node);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal class DefAttributeTypeHandler : IHandler, IDeferHandler
{
public BamlRecordType Type => BamlRecordType.DefAttributeKeyType;

public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
XamlResourceKey.Create(node);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal class DeferableContentStartHandler : IHandler
{
public BamlRecordType Type => BamlRecordType.DeferableContentStart;

public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
var record = (DeferableContentStartRecord)((BamlRecordNode)node).Record;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ internal class LineNumberAndPositionHandler : IHandler
{
public BamlRecordType Type => BamlRecordType.LineNumberAndPosition;

public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) => null;
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent) => null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ internal class LinePositionHandler : IHandler
{
public BamlRecordType Type => BamlRecordType.LinePosition;

public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) => null;
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent) => null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal class LiteralContentHandler : IHandler
{
public BamlRecordType Type => BamlRecordType.LiteralContent;

public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
var record = (LiteralContentRecord)((BamlRecordNode)node).Record;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal class OptimizedStaticResourceHandler : IHandler, IDeferHandler
{
public BamlRecordType Type => BamlRecordType.OptimizedStaticResource;

public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
var record = (OptimizedStaticResourceRecord)((BamlRecordNode)node).Record;
var key = XamlResourceKey.FindKeyInSiblings(node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ internal class PIMappingHandler : IHandler
{
public BamlRecordType Type => BamlRecordType.PIMapping;

public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) => null;
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent) => null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal class PresentationOptionsAttributeHandler : IHandler
{
public BamlRecordType Type => BamlRecordType.PresentationOptionsAttribute;

public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
var record = (PresentationOptionsAttributeRecord)((BamlRecordNode)node).Record;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ private bool NeedsFullName(XamlProperty property, XamlContext ctx, XElement elem
return property.IsAttachedTo(type);
}

public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
var record = (PropertyCustomRecord)((BamlRecordNode)node).Record;
var serTypeId = ((short)record.SerializerTypeId & 0xfff);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal class PropertyHandler : IHandler
{
public virtual BamlRecordType Type => BamlRecordType.Property;

public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
var record = (PropertyRecord)((BamlRecordNode)node).Record;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,17 @@ THE SOFTWARE.

using System.Xml.Linq;

using ICSharpCode.Decompiler.TypeSystem;

using ICSharpCode.BamlDecompiler.Baml;
using ICSharpCode.BamlDecompiler.Xaml;
using ICSharpCode.Decompiler.TypeSystem;

namespace ICSharpCode.BamlDecompiler.Handlers
{
internal class PropertyTypeReferenceHandler : IHandler
{
public BamlRecordType Type => BamlRecordType.PropertyTypeReference;

public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent)
public BamlElement? Translate(XamlContext ctx, BamlNode node, BamlElement? parent)
{
var record = (PropertyTypeReferenceRecord)((BamlRecordNode)node).Record;
var attr = ctx.ResolveProperty(record.AttributeId);
Expand Down
Loading
Loading