Repository navigation
Don't share members between types with the same full name - #529
Draft
alexanderlinne wants to merge 1 commit into
Draft
alexanderlinne wants to merge 1 commit into
alexanderlinne wants to merge 1 commit into
Conversation
DomainResolver cached methods and fields by their full name, while types are cached by assembly-qualified name. With the same full name in two assemblies, the second type received the first type's members, so they reported the wrong declaring type and assembly. Members also compared equal by full name alone, so rule evaluation could not tell them apart either. Cache members per declaring type's assembly, and compare method, field and property members by their assembly-qualified name, like types. The duplicate test fixtures gain a field so that both caches are covered. Signed-off-by: Alexander Linne <alexander.linne@tngtech.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## fix/frozen-rule-stores #529 +/- ##
==========================================================
+ Coverage 87.02% 87.04% +0.01%
==========================================================
Files 261 261
Lines 12691 12694 +3
Branches 1232 1233 +1
==========================================================
+ Hits 11044 11049 +5
+ Misses 1300 1297 -3
- Partials 347 348 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This was referenced Nov 28, 2026
This branch has not been deployed
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.
Why
ArchUnitNET loads types with the same full name from different assemblies as separate types:
DomainResolvercaches types by assembly-qualified name. Methods and fields, however, were cached by full name only. The secondNs.Duptherefore received the firstNs.Dup's members: its.ctor()reported the other type asDeclaringTypeand the other assembly asAssembly. On top of that,MethodMember,FieldMemberandPropertyMembercompared equal by full name alone, so rule evaluation couldn't tell such members apart either. A member rule failing for both types reported one violation.#531 needs this to tell frozen members apart by assembly, not only types. This PR doesn't use anything from #528; it is based on it only so that #531 contains both.
What changes
Member cache.
DomainResolvercaches methods and fields per declaring type's assembly (Assembly.CreateQualifiedName(declaringType.Assembly.FullName, memberFullName)), the same key scheme as types.Member equality.
MethodMember,FieldMemberandPropertyMemberimplementEqualsandGetHashCodeonAssemblyQualifiedName, which they already had, likeTypedoes.Tests. The
DuplicateClassfixtures in both duplicate test assemblies gain a field, so both the method and the field cache are covered.ArchLoaderTestschecks that each duplicate type owns its own constructor and field, and that the four members are distinct.Behaviour change
Members of types that share a full name across assemblies now report the correct declaring type and assembly, and are no longer equal to each other.