Uh oh!
There was an error while loading. Please reload this page.
Enforce AttributeTargets.Interface - #17173
Conversation
|
edgarfgp
commented
May 17, 2024
|
edgarfgp
commented
May 18, 2024
Interesting. VS Integration is using /// <summary>Indicates the type of class interface to be generated for a class exposed to COM, if an interface is generated at all.</summary>[AttributeUsage(AttributeTargets.Assembly|AttributeTargets.Class,Inherited=false)]publicsealedclassClassInterfaceAttribute:Attribute{/// <summary>Initializes a new instance of the <see cref="T:System.Runtime.InteropServices.ClassInterfaceAttribute" /> class with the specified <see cref="T:System.Runtime.InteropServices.ClassInterfaceType" /> enumeration member.</summary>/// <param name="classInterfaceType">One of the <see cref="T:System.Runtime.InteropServices.ClassInterfaceType" /> values that describes the type of interface that is generated for a class.</param>publicClassInterfaceAttribute(ClassInterfaceTypeclassInterfaceType){this.Value=classInterfaceType;}[<System.Runtime.InteropServices.ClassInterface(ClassInterfaceType.None)>]// This is allowed but should nottypepublicIVsMicrosoftInstalledProduct=inherit IVsInstalledProduct
abstractIdBmpSplashM :byref<uint32>->unit[<System.Runtime.InteropServices.ClassInterface(ClassInterfaceType.None)>]typeFoo()=classendusingSystem.Runtime.InteropServices;[ClassInterface(ClassInterfaceType.AutoDispatch)]publicclassMyClass{}[ClassInterface(ClassInterfaceType.AutoDispatch)]// This raises an error in C#publicinterfaceIFoo{}cc @vzarytovskii seems like |
vzarytovskii
commented
May 18, 2024
Not sure what to do with it, it'll probably need to be an abstract class. This is legacy project system, so won't be able to test it that easy, and we have to support it. |
edgarfgp
commented
May 18, 2024
Yeah an |
Ohh Thanks my googling failed 😅 |
majocha
commented
May 18, 2024
edgarfgp
commented
May 19, 2024
If it is not longer used/needed we could just comment out / remove this code. ideally enforcing the right attribute targets in the compiler should not depend on the use of this interface |
I'd really like this change and for the compiler to enforce attribute targets, but technically this would be a backward incompatible change, right? Do we have a lang suggestion or bug or issue report (I believe this has come up several times)? Ah, wait, found it: #8547. And related are all these: #16692, #16764, #16845, #16790. I assume my point above has already been discussed before then ;). And there's mention of an RFC by you (@edgarfgp), can we link that from the original post above, or is that TODO? #8547 (comment) |
@abelbraaksma Once I have addressed all the |
psfinaki
left a comment
There was a problem hiding this comment.
Thanks for your continuous work here, Edgar :)
Yeah so the VS change looks a bit risky, but since Jakub tested the related functionality, I don't think we should block the fix by that thing. Also, this is a well-isolated PR, so can be reverted quickly if needed.

Description
Enforce
AttributeTargets.InterfaceAttributeTargets.Interfaceshould only work oninterfacesAttributeTargets.Classshould only work onclassesSee C# version for reference sharplab
Checklist