Fix not generating polyfills when using InternalsVisibleTo with EmbeddedAttribute #134
Merged
Sergio0694 merged 6 commits intoMay 25, 2026
Conversation
4c0f5a1 to
e30bbfa
Compare
Introduce an internal ISymbolExtensions class with HasEmbeddedAttribute(this ISymbol) to detect the Microsoft.CodeAnalysis.EmbeddedAttribute. The method iterates symbol attributes and uses pattern matching on AttributeData.AttributeClass and its nested ContainingNamespace chain to robustly identify EmbeddedAttribute (which may be duplicated across assemblies), returning a boolean result. Added to src/PolySharp.SourceGenerators/Extensions/ISymbolExtensions.cs.
Strip trailing .NET license headers from three extension files and refactor HasAccessibleTypeWithMetadataName. Replace the previous attribute-inspection helper with a nested IsSymbolAccessibleAndNotEmbedded helper that first uses compilation.IsSymbolAccessibleWithin, treats same-assembly symbols as accessible, and excludes types annotated with [Embedded] via symbol.HasEmbeddedAttribute(). This simplifies the accessibility logic and fixes cases where Roslyn ignores embedded types even if they appear public.
Remove the assembly-level InternalsVisibleTo attribute from LanguageFeatures.cs and add an <InternalsVisibleTo> entry to the PolySharp.Tests.csproj. The csproj now declares accessibility for PolySharp.InternalsVisibleTo.Tests (with a comment explaining it's used to validate that [Embedded] is correctly filtered when detecting accessible types), centralizing the test visibility configuration.
Remove duplicated test sources from tests/PolySharp.InternalsVisibleTo.Tests and instead link the originals from tests/PolySharp.Tests. Update the InternalsVisibleTo test project to define INTERNALS_VISIBLE_TO_TESTS and add Compile Includes that link LanguageFeatures.cs and RuntimeSupport.cs from the main tests folder. Also wrap the namespace in the shared source files with #if INTERNALS_VISIBLE_TO_TESTS so the linked copies compile under the InternalsVisibleTo test namespace. This eliminates source duplication and ensures the same code is built for both test projects.
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.
Works around dotnet/roslyn#79498 by explicitly checking if the type is not in the same assembly and is Embedded. Also (a bit lazily, but it worked) added a test project that references PolySharp.Tests in order to test this behavior. When merged as a part of #127, this should fix #50.