Analyzer with SuppressSourceGeneration
Since 3.1.1 the analyzer is silent on types marked SuppressSourceGeneration = true. In 3.1.0 it still reported their problems.
Loading the stored receipt
You read 10 of 266 changed lines. Tests and probes cover the rest.
src/MessagePack.SourceGenerator/CodeAnalysis/TypeCollector.csHuman reads
@@ -1005,6 +1005,7 @@ public class TypeCollector
1005 if ((isIntKey && intKey == null) || (!isIntKey && stringKey == null))
1006 {
1007 this.reportDiagnostic?.Invoke(Diagnostic.Create(MsgPack00xMessagePackAnalyzer.DoNotMixStringAndIntKeys, item.DeclaringSyntaxReferences.FirstOrDefault()?.GetSyntax().GetLocation()));
Check evidence
The mixed-key crash fix. Probe B proves it. By reading: it also skips the member's own type, so that type is not checked. Not probed.
1008+ continue; // The key kind does not match the other members; the diagnostic is reported, so skip this member.
1009 }
1010 }
1011
@@ -1019,7 +1020,10 @@ public class TypeCollector
1020 {
1021 DeclaringType = GetDeclaringTypeIfColliding(item),
1022 };
1022− intMembers.Add(member.IntKey, (member, item.Type));
Human reads
First key wins, the next member is dropped. The generator runs this code too, so this guard decides what the generated formatter writes.
1023+ if (!intMembers.ContainsKey(member.IntKey))
1024+ {
1025+ intMembers.Add(member.IntKey, (member, item.Type));
1026+ }
1027 }
1028 else if (stringKey is not null)
1029 {
@@ -1032,7 +1036,10 @@ public class TypeCollector
1036 {
1037 DeclaringType = GetDeclaringTypeIfColliding(item),
1038 };
1035− stringMembers.Add(member.StringKey, (member, item.Type));
Human reads
The same guard for string keys. Same decision as H1.
1039+ if (!stringMembers.ContainsKey(member.StringKey))
1040+ {
1041+ stringMembers.Add(member.StringKey, (member, item.Type));
1042+ }
1043 }
1044
1045 var messagePackFormatter = item.GetAttributes().FirstOrDefault(x => x.AttributeClass.ApproximatelyEqual(this.typeReferences.FormatterAttribute))?.ConstructorArguments[0];
@@ -1138,6 +1145,7 @@ public class TypeCollector
1145 if ((isIntKey && intKey == null) || (!isIntKey && stringKey == null))
1146 {
1147 this.reportDiagnostic?.Invoke(Diagnostic.Create(MsgPack00xMessagePackAnalyzer.DoNotMixStringAndIntKeys, item.DeclaringSyntaxReferences.FirstOrDefault()?.GetSyntax().GetLocation()));
Check evidence
The same 'continue' for fields.
1148+ continue; // The key kind does not match the other members; the diagnostic is reported, so skip this member.
1149 }
1150 }
1151
@@ -1152,7 +1160,10 @@ public class TypeCollector
1160 {
1161 DeclaringType = GetDeclaringTypeIfColliding(item),
1162 };
1155− intMembers.Add(member.IntKey, (member, item.Type));
Skim
H1 again, for fields.
1163+ if (!intMembers.ContainsKey(member.IntKey))
1164+ {
1165+ intMembers.Add(member.IntKey, (member, item.Type));
1166+ }
1167 }
1168 else
1169 {
@@ -1165,7 +1176,10 @@ public class TypeCollector
1176 {
1177 DeclaringType = GetDeclaringTypeIfColliding(item),
1178 };
1168− stringMembers.Add(member.StringKey, (member, item.Type));
Skim
H2 again, for fields.
1179+ if (!stringMembers.ContainsKey(member.StringKey))
1180+ {
1181+ stringMembers.Add(member.StringKey, (member, item.Type));
1182+ }
1183 }
1184
1185 var messagePackFormatter = item.GetAttributes().FirstOrDefault(x => x.AttributeClass.ApproximatelyEqual(this.typeReferences.FormatterAttribute))?.ConstructorArguments[0];