Skip to content
Open
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
6 changes: 3 additions & 3 deletions src/MemoryPack.Generator/MemoryPackGenerator.Emitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ string WithEscape(ISymbol symbol)

if (!xmlDocument)
{
if (type.IsUnmanagedType)
if (type.IsUnmanagedType && type.GenerateType is not GenerateType.VersionTolerant and not GenerateType.CircularReference)
{
sb.Append("GenerateType unmanaged ");
}
Expand All @@ -207,7 +207,7 @@ string WithEscape(ISymbol symbol)
else
{
sb.AppendLine("/// <remarks>");
if (type.IsUnmanagedType)
if (type.IsUnmanagedType && type.GenerateType is not GenerateType.VersionTolerant and not GenerateType.CircularReference)
{
sb.AppendLine("/// MemoryPack GenerateType: unmanaged<br/>");
}
Expand Down Expand Up @@ -269,7 +269,7 @@ public void Emit(StringBuilder writer, IGeneratorContext context)

var serializeBody = "";
var deserializeBody = "";
if (IsUnmanagedType)
if (IsUnmanagedType && GenerateType is not GenerateType.VersionTolerant and not GenerateType.CircularReference)
{
serializeBody = $$"""
writer.WriteUnmanaged(value);
Expand Down
8 changes: 1 addition & 7 deletions src/MemoryPack.Generator/MemoryPackGenerator.Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,14 +292,8 @@ public bool Validate(TypeDeclarationSyntax syntax, IGeneratorContext context, bo
noError = false;
}

if (this.IsUnmanagedType)
if (this.IsUnmanagedType && GenerateType is not GenerateType.VersionTolerant and not GenerateType.CircularReference)
{
if (GenerateType is GenerateType.VersionTolerant)
{
context.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.VersionTolerantOnUnmanagedStruct, syntax.Identifier.GetLocation(), Symbol.Name));
noError = false;
}

var structLayoutFields = this.Symbol.GetAllMembers()
.OfType<IFieldSymbol>()
.Select(x =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public partial record FullName
""",
"FullName.ts");

generatedCode.Should().Contain(
generatedCode.Replace("\r\n", "\n").Should().Contain(
"""
export class FullName {
firstName: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -674,9 +674,9 @@ public Tester(int i1)
}

[Fact]
public void MEMPACK041_UnmanagedStructCannotBeVersionTolerant()
public void MEMPACK041_UnmanagedStructCanBeVersionTolerant()
{
Compile(41, """
var code = """
using MemoryPack;

[MemoryPackable(GenerateType.VersionTolerant)]
Expand All @@ -685,7 +685,9 @@ public partial struct Tester
[MemoryPackOrder(0)]
public int I1 { get; init; }
}
""");
""";
var (_, diagnostics) = CSharpGeneratorRunner.RunGenerator(code);
diagnostics.Length.Should().Be(0);
}

[Fact]
Expand Down