Skip to content

Commit fc6a839

Browse files
SteveSyfuhsCopilot
andcommitted
Fix CS0168 warnings in generated code for unused explicitReader
Only declare the explicitReader variable in Decode methods when the type actually has fields with explicit (non-implicit) context-specific tags. Previously it was always declared, causing warnings for types like KrbAlgorithmIdentifier, KrbSubjectPublicKeyInfo, GssapiToken, etc. where all fields use implicit tags. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 6c29550 commit fc6a839

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

Tests/Tests.Asn1SourceGenerator/Tests.Asn1SourceGenerator.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<LangVersion>12.0</LangVersion>
66
<Nullable>enable</Nullable>
77
<RootNamespace>Tests.Asn1SourceGenerator</RootNamespace>
8-
<NoWarn>1701;1702</NoWarn>
8+
<NoWarn>1591;1701;1702</NoWarn>
99
</PropertyGroup>
1010

1111
<ItemGroup>

Tools/Asn1SourceGenerator/Emit/CSharpEmitter.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,13 @@ private static void EmitDecodeGenericWithTag(IndentedWriter w, ResolvedType type
497497
w.WriteLine("decoded = new T();");
498498
w.WriteLine();
499499
w.WriteLine("AsnReader sequenceReader = reader.ReadSequence(expectedTag);");
500-
w.WriteLine("AsnReader explicitReader;");
500+
501+
bool hasExplicitTags = type.Fields.Any(f => f.Encoding.TagNumber.HasValue && !f.Encoding.IsImplicit);
502+
503+
if (hasExplicitTags)
504+
{
505+
w.WriteLine("AsnReader explicitReader;");
506+
}
501507

502508
if (hasCollections)
503509
{

0 commit comments

Comments
 (0)