fsharp
fsharp copied to clipboard
`AttributeUsage` doesn't distinguish `AttributeTargets.Class` and `AttributeTargets.Struct`
open System
[<AttributeUsage(AttributeTargets.Class)>]
type CustomClassAttribute() =
inherit Attribute()
[<AttributeUsage(AttributeTargets.Struct)>]
type CustomStructAttribute() =
inherit Attribute()
[<AttributeUsage(AttributeTargets.Method)>]
type CustomMethodAttribute() =
inherit Attribute()
[<CustomClass; CustomStruct; CustomMethod>]
type Class() = class end
[<CustomClass; CustomStruct; CustomMethod>]
type Struct(x: int) = struct end
Struct and class attributes seem to be allowed to be used interchangeably:
@auduchinok Could you check the title of this bug please? It says .Constructor but doesn't mention that in the description?
Seems there are three problems:
- CustomStruct can be targeted at class incorrectly
- CustomClass can be targeted at struct incorrectly
- CustomMethod can be targeted at a constructor incorrectly
This seem ok:
- CustomConstructor can't be targeted at a method
Example this works but shouldn't:
open System
[<AttributeUsage(AttributeTargets.Method)>]
type CustomMethodAttribute() =
inherit Attribute()
type Class [<CustomMethod>] () = class end
type Struct [<CustomMethod>] (x: int) = struct end```
and this works (as expected:
```fsharp
[<AttributeUsage(AttributeTargets.Constructor)>]
type CustomConstructorAttribute() =
inherit Attribute()
type Class [<CustomConstructor>] () = class end
type Struct [<CustomConstructor>] (x: int) = struct end
@dsyme Yes, I think it was about structs.