Skip to content

Conversation

@edgarfgp
Copy link
Contributor

@edgarfgp edgarfgp commented Mar 18, 2024

Description

Fixes #16847

Before

[CompilationMapping(SourceConstructFlags.Module)]
public static class @_
{
    [Serializable]
    [AttributeUsage(AttributeTargets.Class)]
    [CompilationMapping(SourceConstructFlags.ObjectType)]
    public class CustomClassAttribute : Attribute
    {
    }


    [Serializable]
    [AttributeUsage(AttributeTargets.Struct)]
    [CompilationMapping(SourceConstructFlags.ObjectType)]
    public class CustomStructAttribute : Attribute
    {
    }


    [Serializable]
    [AttributeUsage(AttributeTargets.Interface)]
    [CompilationMapping(SourceConstructFlags.ObjectType)]
    public class CustomInterfaceAttribute : Attribute
    {
    }

    [Serializable]
    [CustomClass]
    [CustomStruct]
    [CustomInterface]
    [CompilationMapping(SourceConstructFlags.ObjectType)]
    public delegate int Delegate1(int);
}

After

(Error 842, "This attribute is not valid for use on this language element")

Checklist

  • Test cases added

  • Performance benchmarks added in case of performance changes

  • Release notes entry updated:

    Please make sure to add an entry with short succinct description of the change as well as link to this pull request to the respective release notes file, if applicable.

    Release notes files:

    • If anything under src/Compiler has been changed, please make sure to make an entry in docs/release-notes/.FSharp.Compiler.Service/<version>.md, where <version> is usually "highest" one, e.g. 42.8.200
    • If language feature was added (i.e. LanguageFeatures.fsi was changed), please add it to docs/releae-notes/.Language/preview.md
    • If a change to FSharp.Core was made, please make sure to edit docs/release-notes/.FSharp.Core/<version>.md where version is "highest" one, e.g. 8.0.200.

    Information about the release notes entries format can be found in the documentation.
    Example:

    If you believe that release notes are not necessary for this PR, please add NO_RELEASE_NOTES label to the pull request.

…truct AttributeTargets.Interface incorrectly
@edgarfgp edgarfgp requested a review from a team as a code owner March 18, 2024 14:39
@github-actions
Copy link
Contributor

github-actions bot commented Mar 18, 2024

❗ Release notes required


✅ Found changes and release notes in following paths:

Change path Release notes path Description
src/FSharp.Core docs/release-notes/.FSharp.Core/8.0.300.md
src/Compiler docs/release-notes/.FSharp.Compiler.Service/8.0.300.md

Copy link
Member

@T-Gro T-Gro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I again scanned prim-types for attributes that might need an extension.

CompiledName already supports delegates.
NoEquality;NoComparison already support them.

ReflectedDefinitionAttribute should be extended IMO, or at least a quotation relevant scenario tested.

Delegates are naturally used with regular CLI events, but I am not aware of any idiomatic .NET landscape scenario that would work with attributes on delegates (e.g. some UI framework) - if someone could find any, it would be good to add at least one more real-world looking test scenario.

@edgarfgp
Copy link
Contributor Author

ReflectedDefinitionAttribute should be extended IMO, or at least a quotation relevant scenario tested.

Yes, I think it make sense to allow ReflectedDefinitionAttribute to be used on a delegate

@edgarfgp edgarfgp requested a review from T-Gro March 19, 2024 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Delegates allowed to target AttributeTargets.Class AttributeTargets.Struct AttributeTargets.Interface incorrectly

3 participants