Skip to content

F# compiler does not enforce attribute targets #8547

@njlr

Description

@njlr

Compile this code:

open System

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

[<MethodOnly>]
let abc () =
  "abc"

[<MethodOnly>]
let def =
  "def"

Expected behavior

Compilation should fail because def is not a method; it is a string.

Actual behavior

The code compiles.

Known workarounds

Take care not to use attributes incorrectly.

Related information

#4460 is not quite the same, but a fix will probably touch the same code.

  • Operating system: Linux
  • .NET Runtime kind: .NET Core, Fable
  • Editing Tools: Visual Studio Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-Compiler-CheckingType checking, attributes and all aspects of logic checkingBugImpact-Medium(Internal MS Team use only) Describes an issue with moderate impact on existing code.

    Type

    No type

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions