Skip to content

F# 9 changes the validation of attribute usage targets for union cases. #18298

Open
@eiriktsarpalis

Description

@eiriktsarpalis

I noticed the following regression when trying to build an old F# project using the .NET 9 sdk. The following code

open System.Runtime.Serialization

type CartEvent =
    | [<DataMember(Name = "cartCreated")>] CartCreated

now fails to compile with the error

error FS0842: This attribute is not valid for use on this language element

Technically, this error is correct because DataMemberAttribute specifies AttributeTarget.Field ||| AttributeTarget.Property however this is breaking a common pattern used when serializing events modelled as discriminated unions.

So I have the following questions:

  1. Was this change made intentionally rectifying lack of attribute target validation by the compiler?
  2. What attribute AttributeTarget should library authors be specifying for attributes intended for application to union cases?

cc @bartelink

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-Compiler-CheckingType checking, attributes and all aspects of logic checking

    Type

    No type

    Projects

    Status

    New

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions