Skip to content

Fix not generating polyfills when using InternalsVisibleTo with EmbeddedAttribute #134

Merged
Sergio0694 merged 6 commits into
Sergio0694:mainfrom
Windows10CE:fix/embedded-attribute-internals-visible-to
May 25, 2026
Merged

Fix not generating polyfills when using InternalsVisibleTo with EmbeddedAttribute #134
Sergio0694 merged 6 commits into
Sergio0694:mainfrom
Windows10CE:fix/embedded-attribute-internals-visible-to

Conversation

@Windows10CE

@Windows10CE Windows10CE commented Oct 13, 2025

Copy link
Copy Markdown
Contributor

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.

@Sergio0694 Sergio0694 deleted the branch Sergio0694:main May 25, 2026 17:54
@Sergio0694 Sergio0694 closed this May 25, 2026
@Sergio0694 Sergio0694 reopened this May 25, 2026
@Sergio0694 Sergio0694 changed the base branch from dev/embedded-types to main May 25, 2026 17:56
@Sergio0694 Sergio0694 force-pushed the fix/embedded-attribute-internals-visible-to branch from 4c0f5a1 to e30bbfa Compare May 25, 2026 17:56
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.
@Sergio0694 Sergio0694 merged commit 59d3cf7 into Sergio0694:main May 25, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

InternalsVisibleTo from two other projects leads to not being able to use PolySharp

2 participants