-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Create analyzer in ComInterfaceGenerator to enforce the generator is used with IUnknown only #78189
Conversation
Tagging subscribers to this area: @dotnet/interop-contrib Issue DetailsCreates an analyzer that warns if the GeneratedComInterfaceAttribute is
|
Creates an analyzer that warns if the GeneratedComInterfaceAttribute is used with InterfaceTypeAttribute that has an argument that is not 'InterfaceIsIUnknown'
ca80aec
to
0cdeb34
Compare
src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratorDiagnostics.cs
Outdated
Show resolved
Hide resolved
....Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratedComInterfaceAttributeAnalyzer.cs
Outdated
Show resolved
Hide resolved
....Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratedComInterfaceAttributeAnalyzer.cs
Outdated
Show resolved
Hide resolved
...InteropServices/tests/ComInterfaceGenerator.Unit.Tests/GeneratedComInterfaceAnalyzerTests.cs
Outdated
Show resolved
Hide resolved
…enerator/GeneratorDiagnostics.cs Co-authored-by: Jeremy Koritzinsky <[email protected]>
- Use test harness from LibraryImportGenerator.Unit.Tests - Don't check for assembly name when matching attribute - Undo changes from TestUtils
...teropServices/tests/ComInterfaceGenerator.Unit.Tests/ComInterfaceGenerator.Unit.Tests.csproj
Outdated
Show resolved
Hide resolved
...InteropServices/tests/ComInterfaceGenerator.Unit.Tests/GeneratedComInterfaceAnalyzerTests.cs
Outdated
Show resolved
Hide resolved
...InteropServices/tests/ComInterfaceGenerator.Unit.Tests/GeneratedComInterfaceAnalyzerTests.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the expected behaviour of the generator if it encounters this case? Will it just generate code for IUnknown
/ completely ignore InterfaceType
? If we might put the user in an unexpectedly bad state, would it make sense to be an error diagnostic in the generator instead?
src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratorDiagnostics.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/Strings.resx
Outdated
Show resolved
Hide resolved
src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/Strings.resx
Outdated
Show resolved
Hide resolved
src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratorDiagnostics.cs
Outdated
Show resolved
Hide resolved
....Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratedComInterfaceAttributeAnalyzer.cs
Outdated
Show resolved
Hide resolved
....Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratedComInterfaceAttributeAnalyzer.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratorDiagnostics.cs
Outdated
Show resolved
Hide resolved
....Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratedComInterfaceAttributeAnalyzer.cs
Outdated
Show resolved
Hide resolved
....Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratedComInterfaceAttributeAnalyzer.cs
Outdated
Show resolved
Hide resolved
....Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratedComInterfaceAttributeAnalyzer.cs
Outdated
Show resolved
Hide resolved
The This attribute would allow users to explicitly state that they want an |
If a project has an interface with
I know we hit the 'analyzers disabled, generator enabled' case with |
I think the generator would just skip generating what is not supported. I know that @CyrusNajmabadi was pushing for diagnostics like these to be moved to analyzers for better performance in the IDE. I'd be curious to hear his thoughts on the "analyzers disabled, generator enabled" scenario. |
…enerator/Resources/Strings.resx Co-authored-by: Elinor Fung <[email protected]>
…time into GenComIntAnalyzer
Move Analyzer and related diagnostics to Analayzers/ folder Change diagnostic to "InvalidUse of GeneratedComInterfaceAttribute" Add diagnostic to list-of-diagnostics.md Add and organize tests using all variations of ComInterfaceType
...InteropServices/tests/ComInterfaceGenerator.Unit.Tests/GeneratedComInterfaceAnalyzerTests.cs
Show resolved
Hide resolved
Failure was a known issue with our usage of homebrew. This is ready to be merged. |
Creates an analyzer that warns if the GeneratedComInterfaceAttribute is
used with InterfaceTypeAttribute that has an argument that is not
'InterfaceIsIUnknown'