Conversation
IsCopyConstructor required the copy constructor to be private on a sealed record and protected otherwise, but IsGeneratedCopyConstructor in the same class accepts protected regardless of sealedness. Since the former gates the latter, a sealed record whose copy constructor stayed protected -- what you get when a record is sealed after it was compiled -- was not recognized as one at all: it fell through to the general constructor handling, where its base call made it count as unchained, and the primary-constructor invariant then failed. Found by fuzzing nuget.org. Beyond silencing the assertion this improves the output, as the affected types now decompile to positional records. Assisted-by: Claude:claude-opus-5[1m]:Claude Code
siegfriedpammer
force-pushed
the
fix-sealed-record-copy-ctor
branch
from
August 7, 2026 04:32
44781de to
a4d2aac
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
RecordDecompilerdisagrees with itself about the accessibility of a record's copy constructor.IsCopyConstructorties it to sealedness:but
IsGeneratedCopyConstructor, twenty lines further down, accepts protected either way:IsCopyConstructorgates the call toIsGeneratedCopyConstructor, so for a sealed record with a protected copy constructor the looser check is unreachable. Such a record is not recognized as having a copy constructor at all: the constructor falls through to the general handling inTransformFieldAndConstructorInitializers, where its first statement is a base call rather than athis(...)chain, so it is counted as not chained. That makes two unchained constructors alongside the primary one and tripsThe combination arises when a record is sealed after it was compiled, which is what obfuscators do.
Fix
Align
IsCopyConstructorwith the predicateIsGeneratedCopyConstructoralready uses. The only shape whose classification changes is sealed + protected, which the latter already considered valid; sealed + private and unsealed + protected are unaffected, and unsealed + private stays rejected.Testing
New ILPretty fixture
SealedRecordProtectedCopyCtor, built by compiling an ordinary record and marking the classsealedin IL. It fails without the fix on the assertion above.The fix is not merely silencing an assertion -- it corrects the output. The affected types previously could not render as records; they now decompile to positional records:
Verified on the assembly this was found in (
Aspose.AI.LLM.dllfrom aspose.ocr 26.7.0): the whole assembly now decompiles with no assertion and no errors.Full
ILSpy.XPlat.slnfsuite: 3367 tests, 0 failed, 44 skipped (Windows-only).How it was found
Fuzzing the nuget.org catalog through the decompiler.
Written by an AI agent (Claude) on Siegfried's behalf.