-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type comparison fails on two imported types with different scope but forward to the same type #546
Comments
I'd think this is actually explicitly expected behavior, no? Type-forwards or no, as far as the module owning the reference is concerned, they're different types from different assemblies. At any rate, I don't think the default comparer should consider them equivalent. An option to consider them equivalent may make sense (though I'd propose it would only make sense in the context of a workspace or similar). Strictly speaking, assemblies aren't supposed to reference The conceptual distinction I think I'm making here is "building" versus "analyzing". When building, one should only ever reference
Under non-workspace rules, the two |
While that is true, what binaries are supposed to do and what could happen are two separate problems. While forwarded types currently only really exist in corlib-like assemblies, that does not exclude the possibility of this happening in the future for other DLLs, or even for (maliciously crafted) input binaries. Special-casing on corlib members is therefore more of a band-aid solution rather than solving the core problem.
I agree, but I would also argue the main purpose of |
I suppose my concern boils down to my own mental model of the metadata: there,
I'm not recommending special casing them. Rather, I'm suggesting a tool which could (for instance) take a collection of reference assemblies, and be used to map references to the underlying definition (like the def in I also wouldn't expect to see both a Perhaps the solution I'm imagining is that everything related to detailed analysis, where you might care about runtime behavior, you load up a workspace (perhaps with a name reminiscent of the runtime's own |
This is a fair concern. We could add a flag to the SignatureComparisonFlags enumeration that distinguishes between the two modes. The question then becomes, which one should
True, but these comparisons happen more often than you may think. Member resolution heavily depends on this, in particular, the reading and writing of custom attribute signatures. These may contain enum values for which the underlying integer types needs to be resolved. Without considering forwarded types we would not be able to deserialize and serialize accurately here.
This is the exact direction #471 and #537 are taking and I plan on it being part of 6.0 as well. |
AsmResolver Version
5.5.1
.NET Version
.NET 6.0
Operating System
Windows
Describe the Bug
When using the
SignatureComparer
class to compare an imported type reference A with another imported type reference B that both resolve to the same type definition T, but A points directly to T while B indirectly references T via an exported type, the signature comparison fails even though the same types are effectively referenced.Resolving before comparing does work.
How To Reproduce
Expected Behavior
Actual Behavior
Additional Context
This is likely because of the recursion protection that is done in
SignatureComparer::SimpleTypeEquals
. Because the parent modules of both references are the same, the signature comparer does not try to resolve the references.AsmResolver/src/AsmResolver.DotNet/Signatures/SignatureComparer.TypeDefOrRef.cs
Lines 63 to 70 in 78ce89a
The text was updated successfully, but these errors were encountered: