Repository navigation
fix: CMTK0006 counts an assignment through a cast of this - #243
Merged
CaffeinatedCoder merged 3 commits intoOct 31, 2026
Merged
CaffeinatedCoder merged 3 commits into
CaffeinatedCoder merged 3 commits into
Conversation
…the class's implementation Assignments.Collect recorded a property assignment only on a bare IInstanceReferenceOperation and added the referenced property. A class reaches its own explicit interface implementation only through a cast, ((IHasId)this).Id = id, whose Instance is a conversion over this and whose property is the interface's, not the candidate. So a member every constructor assigned was reported, failing a warnings-as-errors build. Collect now strips conversions down to this, for fields and properties alike, and maps an interface's property to the analysed type's implementation (FindImplementationForInterfaceMember). Tuple elements and ref/out arguments go through the same Collect. A local holding this is not followed: IHasId self = this; self.Id = id stays reported, as the README now says. Input class (AIS): the forms that assign a member in a constructor. Plain and this. (silent before and after), a cast of this to an interface the member implements explicitly, implicitly, to the second of two it implements and to a generic one, a cast to the class itself for a field, deconstruction through the cast, and out through the cast: all seven were reported, the same cause, and are silent now. Two constructors where one assigns through the cast still name the other, and a cast of another instance assigns nothing. Reverting the source fails both rows; mapping nothing (casts stripped, the interface's property kept) fails both as well. Closes #231 Defect-Class: AIS Found-By: CA Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…signing this one
Collect took any IInstanceReferenceOperation as this. An object
initializer's receiver and a with expression's are instance references
too, of the object they create. So a constructor whose only assignment
was _ = new Twin(0) { Id = x } counted as assigning its own Id, and the
member nothing set on this instance was not reported. Only the
containing type's instance counts now.
Found running #231's input class (the forms that assign a member in a
constructor) across what the receiver is: this, a cast of it, another
instance, a local alias, an object initializer and a with. The last two
were silent; both report now.
Reverting the source fails the row: 0 reports where 2 are expected.
Refs #231
Defect-Class: AIS
Found-By: VA
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # CHANGELOG.md # test/oracles/claims.json
CaffeinatedCoder
deleted the
fix/explicit-interface-assignment-silent-2-3-1
branch
October 31, 2026 08:16
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.
Closes #231
Problem
UnassignedNoDefaultMemberAnalyzer.Assignments.Collectrecorded a property assignment only on a bareIInstanceReferenceOperationand added the referenced property. A class reaches its own explicit interface implementation only through a cast,((IHasId)this).Id = id: itsInstanceis a conversion overthis, and its property isIHasId.Id, not the class's implementation that is the candidate. So CMTK0006 reported a member every constructor assigns, which fails a warnings-as-errors build.Change
UnassignedNoDefaultMemberAnalyzer.cs:Collectstrips conversions down tothis, for fields and properties, and maps an interface's property to the analysed type's implementation (FindImplementationForInterfaceMember). Tuple elements andref/outarguments go through the sameCollect. A local holdingthisis not followed:IHasId self = this; self.Id = id;stays reported (the issue left this to the fix; the README says so).Found-By: VA, its own commit):Collecttook any instance reference asthis, so a constructor whose only assignment wasnew Twin(0) { Id = x }orother with { Id = x }counted as assigning its ownId, and CMTK0006 was silent. Only the containing instance counts now.K06-an-explicit-implementation-through-a-castholds it. Remarks on the analyzer updated.### Fixed, the sibling under### Changedsince a warnings-as-errors build can now fail. Both are a Warning, so no exception to decision 34.Tests
A_member_assigned_through_a_cast_of_this_stays_silent, across the forms that assign a member in a constructor:this., a cast ofthisto an interface the member implements explicitly, implicitly, to the second of two, to a generic one, a cast to the class itself (field), deconstruction through the cast, andoutthrough the cast. All seven were reported before.A_cast_assigns_only_the_member_it_reaches_on_this: two constructors where only one assigns through the cast name the other; a cast of another instance assigns nothing; a local alias stays reported.An_initializer_of_another_instance_assigns_nothing_on_this: an object initializer and awithof another instance report.tools/BuildVerdict; the solution builds clean.🤖 Generated with Claude Code