-
Notifications
You must be signed in to change notification settings - Fork 830
Closed
Labels
Area-Compiler-CheckingType checking, attributes and all aspects of logic checkingType checking, attributes and all aspects of logic checkingBreaking-changeDescribes a bug which is also a breaking change.Describes a bug which is also a breaking change.BugImpact-Low(Internal MS Team use only) Describes an issue with limited impact on existing code.(Internal MS Team use only) Describes an issue with limited impact on existing code.
Milestone
Description
F# delegates should only be able to target AttributeTargets.Delegate and show compiler error Error 842, "This attribute is not valid for use on this language element" otherwise.
Repro steps
open System
[<AttributeUsage(AttributeTargets.Class)>]
type CustomClassAttribute() =
inherit Attribute()
[<AttributeUsage(AttributeTargets.Struct)>]
type CustomStructAttribute() =
inherit Attribute()
[<AttributeUsage(AttributeTargets.Interface)>]
type CustomInterfaceAttribute() =
inherit Attribute()
[<CustomClass>]
[<CustomStruct>]
[<CustomInterface>]
type Delegate1 = delegate of int -> intCompiles downs to
[CompilationMapping(SourceConstructFlags.Module)]
public static class @_
{
[Serializable]
[AttributeUsage(AttributeTargets.Class)]
[CompilationMapping(SourceConstructFlags.ObjectType)]
public class CustomClassAttribute : Attribute
{
}
[Serializable]
[AttributeUsage(AttributeTargets.Struct)]
[CompilationMapping(SourceConstructFlags.ObjectType)]
public class CustomStructAttribute : Attribute
{
}
[Serializable]
[AttributeUsage(AttributeTargets.Interface)]
[CompilationMapping(SourceConstructFlags.ObjectType)]
public class CustomInterfaceAttribute : Attribute
{
}
[Serializable]
[CustomClass]
[CustomStruct]
[CustomInterface]
[CompilationMapping(SourceConstructFlags.ObjectType)]
public delegate int Delegate1(int);
}Expected behavior
Not compile and show (Error 842, Line 17, Col 16, Line 17, Col 28, "This attribute is not valid for use on this language element")
Actual behavior
Compiles
Known workarounds
Provide a description of any known workarounds.
Related information
Provide any related information (optional):
- Operating system
- .NET Runtime kind (.NET Core, .NET Framework, Mono)
- Editing Tools (e.g. Visual Studio Version, Visual Studio)
Metadata
Metadata
Assignees
Labels
Area-Compiler-CheckingType checking, attributes and all aspects of logic checkingType checking, attributes and all aspects of logic checkingBreaking-changeDescribes a bug which is also a breaking change.Describes a bug which is also a breaking change.BugImpact-Low(Internal MS Team use only) Describes an issue with limited impact on existing code.(Internal MS Team use only) Describes an issue with limited impact on existing code.
Type
Projects
Status
Done