Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Must attribute arguments be exactly as shown in Annex C? #870

Open
KalleOlaviNiemitalo opened this issue Jul 24, 2023 · 2 comments
Open
Labels
type: clarity While not technically incorrect, the Standard is potentially confusing
Milestone

Comments

@KalleOlaviNiemitalo
Copy link
Contributor

Describe the bug

From §5 and §C.1 in the C# 7.x draft, it is not clear whether a conforming implementation has to decorate the standard classes with attributes exactly as specified in Annex C, or whether it can use different values as attribute arguments — for example, adding more AttributeTargets bits to an AttributeUsageAttribute on an attribute class.

Example

§C.1 specifies this type:

[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
    public sealed class CallerFilePathAttribute : Attribute
    {
        public CallerFilePathAttribute() { }
    }

Could a conforming implementation use e.g. AttributeTargets.Parameter | AttributeTargets.Field instead? If so, would that count as an extension and have to be documented? (Independently of whether the attribute has any compile-time effect when applied to a field.)

Expected behavior

Directly specify whether this is allowed.

Additional context

§5 does not mention attributes here:

A conforming implementation of C# is permitted to provide additional types, values, objects, properties, and methods beyond those described in this specification, provided they do not alter the behavior of any strictly conforming program.

(If that paragraph were modified to allow changing attribute arguments, the "provided that" condition at the end would not be a problem, as MemberInfo.GetCustomAttributes and Attribute.GetCustomAttributes methods are not listed in Annex C and thus cannot be called by a strictly conforming program.)

§C.1 says that additional attributes are allowed, but does not mention modifications of specified attributes. Also, that text is informative.

Inspired by #858; if C# 10 specifies AttributeTargets.Method on AsyncMethodBuilderAttribute but C# 7.3 does not, and modifications of attribute arguments are not allowed, then it won't be possible for implementations using the same library to comply with both versions of C#, which would be unfortunate.

@KalleOlaviNiemitalo KalleOlaviNiemitalo changed the title Must attribut arguments be exactly as shown in Annex C? Must attribute arguments be exactly as shown in Annex C? Jul 24, 2023
@KalleOlaviNiemitalo
Copy link
Contributor Author

This text in C.1 even looks too permissive:

Adding attributes (other than the ConditionalAttribute) to existing types and members.

as adding ObsoleteAttribute to all types, especially with error: true, would make the implementation pretty useless and should not be allowed. The text is informative, though.

@jskeet jskeet added the type: clarity While not technically incorrect, the Standard is potentially confusing label Aug 7, 2023
@jskeet
Copy link
Contributor

jskeet commented Aug 7, 2023

Thanks for raising this - I don't think it's blocking for C# 7 (in that there's nothing new about the ambiguity here), but we'll discuss it once we've shipped C# 7. If you think this really must be addressed before we release C# 7, please holler :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: clarity While not technically incorrect, the Standard is potentially confusing
Projects
None yet
Development

No branches or pull requests

2 participants