Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions tests/Opc.Ua.MigrationAnalyzer.Tests/Analyzers/UA0003Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,42 @@ class C
Assert.That(diags.Any(d => d.Id == "UA0003"), Is.False);
}

[Test]
public async Task DoesNotReportOnNullableNodeIdEqualsNullAsync()
{
const string source = """
using Opc.Ua;
class C
{
static bool M(NodeId? n) => n == null;
}
""";

ImmutableArray<Diagnostic> diags = await AnalyzerHarness
.GetAnalyzerDiagnosticsAsync(new UA0003NullCheckOnStructTypeAnalyzer(), source)
.ConfigureAwait(false);

Assert.That(diags.Any(d => d.Id == "UA0003"), Is.False);
}

[Test]
public async Task DoesNotReportOnNullableLocalizedTextNotEqualsNullAsync()
{
const string source = """
using Opc.Ua;
class C
{
static bool M(LocalizedText? value) => null != value;
}
""";

ImmutableArray<Diagnostic> diags = await AnalyzerHarness
.GetAnalyzerDiagnosticsAsync(new UA0003NullCheckOnStructTypeAnalyzer(), source)
.ConfigureAwait(false);

Assert.That(diags.Any(d => d.Id == "UA0003"), Is.False);
}

[Test]
public async Task DoesNotReportOnEqualsMethodCallAsync()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,10 @@ private static void AnalyzeBinary(OperationAnalysisContext context, UaSymbols sy
{
return;
}
if (valueType.OriginalDefinition?.SpecialType == SpecialType.System_Nullable_T &&
valueType is INamedTypeSymbol named &&
named.TypeArguments.Length == 1)
if (valueType is INamedTypeSymbol namedType &&
namedType.OriginalDefinition.SpecialType == SpecialType.System_Nullable_T)
{
valueType = named.TypeArguments[0];
return;
}

if (!symbols.IsBuiltInStructType(valueType))
Expand Down
Loading