Skip to content

AttributeTargets.Method can be targeted in a constructor incorrectly #16794

@edgarfgp

Description

@edgarfgp

AttributeTargets.Method can be targeted in a constructor incorrectly.

Repro steps

open System
[<AttributeUsage(AttributeTargets.Method)>]
type CustomMethodAttribute() =
    inherit Attribute()

type Class [<CustomMethod>] () = class end

type Struct [<CustomMethod>] (x: int) = struct end

Expected behavior
Should not compile and Error 842 "This attribute is not valid for use on this language element" should be reported.

Actual behavior
Compiles

Provide a description of the actual behaviour observed.

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 checkingBugImpact-Low(Internal MS Team use only) Describes an issue with limited impact on existing code.help wanted

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions