Skip to content

Serialization.V2: pin cross-assembly generator behavior, fix AKKASG023 mislabel, add fix-it hints - #8512

Merged
Aaronontheweb merged 3 commits into
akkadotnet:devfrom
Aaronontheweb:feature/serialization-v2-cross-assembly-baseline
Sep 5, 2026
Merged

Aaronontheweb merged 3 commits into
akkadotnet:devfrom
Aaronontheweb:feature/serialization-v2-cross-assembly-baseline

Conversation

@Aaronontheweb

Copy link
Copy Markdown
Member

Summary

Part of #8384. First of several small PRs.

The V2 source generator reads [AkkaSerializable] schemas only from the syntax of the current compilation. This PR pins what that means for types declared in a referenced assembly, fixes one mislabeled diagnostic, and makes three diagnostics say how to fix the problem.

Changes

  • New CrossAssemblyBaselineSpec. It compiles two assemblies in memory, runs the generator on the second, and pins six cases:
    • a nested [AkkaSerializable] type from a referenced assembly: AKKASG007 with a cross-assembly hint. Before this PR it was a mislabeled AKKASG023 that called a plain record a "closed generic"
    • a union member from a referenced assembly: AKKASG015 with the same hint
    • a generic definition from a referenced assembly, registered with [AkkaSerializable<T>]: works, typed helpers emitted. Without the registration: AKKASG023
    • a registration that neither implements the protocol nor is reachable: AKKASG034, which also suppresses emission of the whole serializer
    • [AkkaEnvelopePayload] on a generic property, substituted through a referenced definition: honored
    • a protocol implementor declared only in a referenced assembly: no dispatch arm, no diagnostic
  • Generator: a non-generic [AkkaSerializable] type missing from the message table now reports AKKASG007, not AKKASG023. AKKASG023 stays for real closed generic constructions.
  • Diagnostic hints. Same ids, titles, and severities.
    • AKKASG003 on an interface, abstract class, or type parameter: "Mark the property [AkkaEnvelopePayload], or declare a closed member set with [AkkaUnion]."
    • AKKASG007 and AKKASG015 for a type from another assembly: name the type and its assembly, say the generator cannot read a schema from a referenced assembly yet, and name the fixes that work today. Same-assembly messages are unchanged.
  • openspec/changes/messagepack-sourcegen-validation/design.md line 199 corrected. It claimed a closed-generic registration over a referenced-assembly definition does not work. It does.

Testing

dotnet test src/core/Akka.Serialization.V2.Tests -c Release: 269 passed, 0 failed. No generated code changed. Golden-output tests are untouched.

Next

Schema extraction from referenced-assembly metadata, Decision 16 in the OpenSpec design record, as a separate PR. That turns the "cannot read a schema from a referenced assembly yet" case into a working one.

…3 mislabel, add fix-it hints

Part of akkadotnet#8384.

- CrossAssemblyBaselineSpec: six two-assembly characterization tests for
  types declared in a referenced assembly
- A non-generic [AkkaSerializable] type missing from the message table now
  reports AKKASG007, not AKKASG023 (which stays for real closed generics)
- AKKASG003, AKKASG007, and AKKASG015 now say how to fix the problem; the
  cross-assembly variants name the type and its assembly
- design.md line 199 corrected: a closed-generic registration over a
  definition from a referenced assembly already works
@Aaronontheweb
Aaronontheweb force-pushed the feature/serialization-v2-cross-assembly-baseline branch from 9269194 to 5e41604 Compare September 5, 2026 14:12
…tic changes

Review follow-up on PR akkadotnet#8512. No behavior change: same diagnostics, same
message text, same 269 passing tests, no golden or snapshot changes.

AkkaSerializerGenerator.cs:
- Replace the objectTypeName.Contains('<') string test with an explicit
  TypeMapping.IsGenericConstruction bool, set once from
  INamedTypeSymbol.IsGenericType where the Object mapping is created, and
  threaded through equality/hash/With* like the other mapping flags.
- Merge CollectObjectTypeNames and CollectObjectMappings into one
  EnumerateObjectMappings traversal that yields mappings; callers that
  only need names project TypeFullName themselves.
- Collapse the three report sites that each chose between a same-assembly
  and cross-assembly descriptor (or AKKASG023 vs AKKASG007) into two
  helpers, ReportMissingNestedSchema and ReportUnionMemberNotSerializable,
  each carrying a short plain-English comment for its decision table. No
  report site branches more than once now.
- Trim several overlong XML doc comments picked up along the way.

CrossAssemblyBaselineSpec.cs:
- Rewrite the case comments in plain, short-sentence English. Case 1 gets
  an ASCII diagram of the symbol-vs-syntax mechanism that produces
  AKKASG007 instead of AKKASG023; the other five cases get short prose.

Generator diff against akkadotnet/dev: 175 insertions / 32 deletions
(net +143), down from 173 / 22 (net +151) before this pass.
@Aaronontheweb Aaronontheweb added serialization akka.net v1.6 Akka.NET v1.6-related issues tests labels Sep 5, 2026

@Aaronontheweb Aaronontheweb left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

public sealed class CrossAssemblyBaselineSpec
{
[Fact(DisplayName = "Cross-assembly baseline: nested field type declared and [AkkaSerializable] in a referenced assembly fails AKKASG007 with a cross-assembly hint naming the type and its assembly, never the AKKASG023 closed-generic mislabel")]
public void Nested_field_type_from_referenced_assembly()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is going to turn green later as we introduce cross assembly scanning. Right now it's meant to basically be a failure test.

@Aaronontheweb
Aaronontheweb enabled auto-merge (squash) September 5, 2026 18:00
@Aaronontheweb
Aaronontheweb merged commit bc6695b into akkadotnet:dev Sep 5, 2026
14 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

akka.net v1.6 Akka.NET v1.6-related issues serialization tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant