You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
F# compiler does not enforce attribute targets #8547
So this one is kinda funky. F# functions emit as methods, so it's technically correct that you can use MethodOnly on an F# function.
However, in F# semantics there is a very loose distinction (often no distinction) between F# functions and values. F# supports "normal" functions like let add x y = x + y, but also function values like this to support partial application:
letadd x =fun y -> x + y
letadd' x y = x + y
And you can apply the attribute to that as well. The typechecker doesn't distinguish between the two functions (at least not how you might expect). The consequence of that is you can apply the attribute to something that emits as a property.
I would argue that this is a bug, but fixing it would also be a breaking change, so the best we can do is emit a warning.
Does the same funkiness apply for AttributeTargets that target types?
Such as:
AttributeTargets.Class
AttributeTargets.Interface
AttributeTargets.Struct
I ran into this while consuming a C# library (I only have limited F# experience) that had attributes with these targets.
E.g. the following situations compile but some wouldn't in C#:
Yes, this should give a warning or error that the attribute is not applicable to def.
I will also list this as a spec clarification issue in fsharp/fsharp.org#841 - we should indicate for each language element exactly which attribute targets are allowed. Some parts of the spec do record this but not all.
Yes, this should give a warning or error that the attribute is not applicable to def.
I will also list this as a spec clarification issue in fsharp/fsfoundation#841 - we should indicate for each language element exactly which attribute targets are allowed. Some parts of the spec do record this but not all.
Im adding the warning for this. @vzarytovskii@dsyme any plans on updating the lang specification about this? Want to help fixing all this inconsistencies but it is hard without knowing this
Yes, this should give a warning or error that the attribute is not applicable to def.
I will also list this as a spec clarification issue in fsharp/fsfoundation#841 - we should indicate for each language element exactly which attribute targets are allowed. Some parts of the spec do record this but not all.
Im adding the warning for this. @vzarytovskii@dsyme any plans on updating the lang specification about this? Want to help fixing all this inconsistencies but it is hard without knowing this
It should be an rfc, since we treat those as additions to specification.
Yes, this should give a warning or error that the attribute is not applicable to def.
I will also list this as a spec clarification issue in fsharp/fsfoundation#841 - we should indicate for each language element exactly which attribute targets are allowed. Some parts of the spec do record this but not all.
Im adding the warning for this. @vzarytovskii@dsyme any plans on updating the lang specification about this? Want to help fixing all this inconsistencies but it is hard without knowing this
It should be an rfc, since we treat those as additions to specification.
Yes RFC would be good to have that documented there . I can see 10+ issues related to AttributesTargets
Activity
cartermp commentedon Feb 11, 2020
So this one is kinda funky. F# functions emit as methods, so it's technically correct that you can use
MethodOnlyon an F# function.However, in F# semantics there is a very loose distinction (often no distinction) between F# functions and values. F# supports "normal" functions like
let add x y = x + y, but also function values like this to support partial application:And you can apply the attribute to that as well. The typechecker doesn't distinguish between the two functions (at least not how you might expect). The consequence of that is you can apply the attribute to something that emits as a property.
I would argue that this is a bug, but fixing it would also be a breaking change, so the best we can do is emit a warning.
twaalewijn commentedon Jul 4, 2020
Does the same funkiness apply for AttributeTargets that target types?
Such as:
I ran into this while consuming a C# library (I only have limited F# experience) that had attributes with these targets.
E.g. the following situations compile but some wouldn't in C#:
dsyme commentedon Aug 31, 2020
Yes, this should give a warning or error that the attribute is not applicable to
def.I will also list this as a spec clarification issue in fsharp/fsharp.org#841 - we should indicate for each language element exactly which attribute targets are allowed. Some parts of the spec do record this but not all.
ly29 commentedon Jun 9, 2022
This trips us from time to time while writing tests in xunit where people forget to put unit after the let function
vs
Would be very helpful with a compiler warning/error.
edgarfgp commentedon Feb 19, 2024
Im adding the warning for this. @vzarytovskii @dsyme any plans on updating the lang specification about this? Want to help fixing all this inconsistencies but it is hard without knowing this
vzarytovskii commentedon Feb 19, 2024
It should be an rfc, since we treat those as additions to specification.
edgarfgp commentedon Feb 19, 2024
Yes RFC would be good to have that documented there . I can see 10+ issues related to AttributesTargets