Closed dlidstrom closed 4 months ago
@dlidstrom
Hi, there have been a number of recent PR's improving AttributeTarget evaluation in the F# compiler.
The definition in the Argu repo needs updating: https://github.com/fsprojects/Argu/blob/e3bc012e1ab4d122901a9a0e959943ed26bc27fe/src/Argu/Attributes.fs#L21
In order to be applied to a Union Case, it needs to be modified to include AttributeTargets.Method:
/// Demands at least one parsed result for this argument; a parse exception is raised otherwise.
[<AttributeUsage(AttributeTargets.Class ||| AttributeTargets.Method ||| AttributeTargets.Property, AllowMultiple = false)>]
type MandatoryAttribute () = inherit Attribute ()
I imagine that a few more options need adding as well.
Thanks
Kevin
Here is the text of a repro:
open System
/// Interface that must be implemented by all Argu template types
type IArgParserTemplate =
/// returns a usage string for every union case
abstract Usage : string
/// Demands at least one parsed result for this argument; a parse exception is raised otherwise.
[<AttributeUsage(AttributeTargets.Class ||| AttributeTargets.Method ||| AttributeTargets.Property, AllowMultiple = false)>]
type MandatoryAttribute () = inherit Attribute ()
type Arguments =
| [<Mandatory>] Username of string
interface IArgParserTemplate with
member this.Usage =
match this with
| Username _ -> "Specifies the username"
printfn "Hello from F#"
Hi @KevinRansom ! Thanks for letting me know. I will take this with the Argu project then :+1: Feel free to close this.
This leaves the question why FS-1076 / #7781, which was merged in November 2019, is still in preview.
This leaves the question why FS-1076 / #7781, which was merged in November 2019, is still in preview.
It's incomplete.
@Martin521 it's in preview because we don't know that there aren't bugs. Preview allows us to get it in front of developers who can try it out on their code, so that we can decide. It would be fair to say though that for this particular feature, probably not a lot of review is required.
closing this issue - as I suppose "By Design"
I've just discovered that my code doesn't build with F# 8.0.300 and preview language version.
Repro steps
This is my project file:
and this is my Program.fs:
Expected behavior
I expect this to compile cleanly.
Actual behavior
This fails to compile after I upgraded to 8.0.300 (from 8.0.204):
Program.fs(4,7): error FS0842: This attribute is not valid for use on this language element
Known workarounds
Work around is to revert back to latest language version. I am using preview language version for improved string slicing (please upgrade this feature from preview to latest).
Related information
Provide any related information (optional):