-
Notifications
You must be signed in to change notification settings - Fork 763
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
Enforce AttributeTargets.Interface
#17173
Enforce AttributeTargets.Interface
#17173
Conversation
|
|
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)]
public sealed class ClassInterfaceAttribute : 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>
public ClassInterfaceAttribute(ClassInterfaceType classInterfaceType)
{
this.Value = classInterfaceType;
} [<System.Runtime.InteropServices.ClassInterface(ClassInterfaceType.None)>] // This is allowed but should not
type public IVsMicrosoftInstalledProduct =
inherit IVsInstalledProduct
abstract IdBmpSplashM : byref<uint32> -> unit
[<System.Runtime.InteropServices.ClassInterface(ClassInterfaceType.None)>]
type Foo() = class end using System.Runtime.InteropServices;
[ClassInterface(ClassInterfaceType.AutoDispatch)]
public class MyClass
{
}
[ClassInterface(ClassInterfaceType.AutoDispatch)] // This raises an error in C#
public interface IFoo {} cc @vzarytovskii seems like |
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. |
0c3c7a3
to
eeea1fc
Compare
eeea1fc
to
85d80ab
Compare
Yeah an |
Ohh Thanks my googling failed 😅 |
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 |
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.
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.Interface
AttributeTargets.Interface
should only work oninterfaces
AttributeTargets.Class
should only work onclasses
See C# version for reference sharplab
Checklist