Skip to content

Attribute targets on records#17207

Merged
vzarytovskii merged 24 commits into
dotnet:mainfrom
edgarfgp:attribute-targets-on-records
Jul 8, 2024
Merged

Attribute targets on records#17207
vzarytovskii merged 24 commits into
dotnet:mainfrom
edgarfgp:attribute-targets-on-records

Conversation

@edgarfgp

@edgarfgp edgarfgp commented May 21, 2024

Copy link
Copy Markdown
Contributor

Follow up: #17173

Records compiles down to a class or struct sharplab.

This PR enforces the new rules on records.

Old rules

  • AttributeTargets.Class
  • AttributeTargets.Interface
  • AttributeTargets.Delegate
  • AttributeTargets.Struct
  • AttributeTargets.Enum

New Rules

  • AttributeTargets.Class
  • AttributeTargets.Struct when using [<Struct>]

Before sharplab

[<AttributeUsage(AttributeTargets.Class)>]
 type ClassTargetAttribute() =
     inherit Attribute()

 [<AttributeUsage(AttributeTargets.Interface)>]
 type InterfaceTargetAttribute() =
     inherit Attribute()

 [<AttributeUsage(AttributeTargets.Struct)>]
 type StructTargetAttribute() =
     inherit Attribute()

 [<InterfaceTarget>] // Does not fail. It should
 [<StructTarget>] // Does not fail. It should
 [<ClassTarget>]
 type Record = { Prop: string }

 [<ClassTarget>] // Does not fail. It should
 [<InterfaceTarget>] // Does not fail. It should
 [<Struct>]
type StructRecord = { Prop: string }

After

[<AttributeUsage(AttributeTargets.Class)>]
 type ClassTargetAttribute() =
     inherit Attribute()

 [<AttributeUsage(AttributeTargets.Interface)>]
 type InterfaceTargetAttribute() =
     inherit Attribute()

 [<AttributeUsage(AttributeTargets.Struct)>]
 type StructTargetAttribute() =
     inherit Attribute()

 [<InterfaceTarget>] // Fails as expected
 [<StructTarget>] // Fails as expected
 [<ClassTarget>]
 type Record = { Prop: string }

 [<ClassTarget>] // Fails as expected
 [<InterfaceTarget>] // Fails as expected
 [<Struct>]
type StructRecord = { Prop: string }

Checklist

  • Test cases added
  • Release notes entry updated

@github-actions

github-actions Bot commented May 21, 2024

Copy link
Copy Markdown
Contributor

❗ 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.400.md
src/Compiler docs/release-notes/.FSharp.Compiler.Service/8.0.400.md

@edgarfgp edgarfgp closed this May 23, 2024
@edgarfgp edgarfgp reopened this May 23, 2024
@edgarfgp edgarfgp marked this pull request as ready for review June 11, 2024 14:38
@edgarfgp edgarfgp requested a review from a team as a code owner June 11, 2024 14:38
@edgarfgp

Copy link
Copy Markdown
Contributor Author

Ready for review

Comment thread src/Compiler/Checking/CheckDeclarations.fs Outdated
Comment thread src/Compiler/Checking/CheckDeclarations.fs
Comment thread src/FSharp.Core/prim-types.fs
@psfinaki

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 2 pipeline(s).

@T-Gro T-Gro left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you explain the RequireQualifiedAccess reasoning here, maybe even in the comment as part of code?

Is it only a temporary need caused by new compiler + old FSharp.Core combination, eventually to be removed?

@github-actions

github-actions Bot commented Jul 3, 2024

Copy link
Copy Markdown
Contributor

Caution

Repository is on lockdown for maintenance, all merges are on hold.

@edgarfgp edgarfgp closed this Jul 3, 2024
@edgarfgp edgarfgp reopened this Jul 3, 2024
@edgarfgp

edgarfgp commented Jul 4, 2024

Copy link
Copy Markdown
Contributor Author

Can you explain the RequireQualifiedAccess reasoning here, maybe even in the comment as part of code?

Is it only a temporary need caused by new compiler + old FSharp.Core combination, eventually to be removed?

@T-Gro So the check for RequireQualifiedAccess is not needed at all. Turns out that when you use dotnet build on FSharp.Compiler.Service it uses the FSharp.Core nuget as opposed to the project reference and that is why my unit test was failing locally.

Thanks for the review

@psfinaki psfinaki left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks! Appreciate your consistent and meticulous approach.
Do you see the light at the end of the attributes tunnel?

@edgarfgp

edgarfgp commented Jul 4, 2024

Copy link
Copy Markdown
Contributor Author

Thanks! Appreciate your consistent and meticulous approach. Do you see the light at the end of the attributes tunnel?

Yes. I have 2 more PRs and then a RFC

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.

4 participants