Skip to content

Fix access checking for properies setters in attribute arguments #18581

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

Merged
merged 4 commits into from
May 22, 2025

Conversation

evgTSV
Copy link
Contributor

@evgTSV evgTSV commented May 20, 2025

Description

Fixes #18571

I use checking from MethInfoChecks

Checklist

  • Test cases added
  • Release notes entry updated:

Copy link
Contributor

❗ Release notes required

@evgTSV,

Caution

No release notes found for the changed paths (see table below).

Please make sure to add an entry with an informative description of the change as well as link to this pull request, issue and language suggestion if applicable. Release notes for this repository are based on Keep A Changelog format.

The following format is recommended for this repository:

* <Informative description>. ([PR #XXXXX](https://github.com/dotnet/fsharp/pull/XXXXX))

See examples in the files, listed in the table below or in th full documentation at https://fsharp.github.io/fsharp-compiler-docs/release-notes/About.html.

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

You can open this PR in browser to add release notes: open in github.dev

Change path Release notes path Description
src/Compiler docs/release-notes/.FSharp.Compiler.Service/10.0.100.md No release notes found or release notes format is not correct

@T-Gro T-Gro requested a review from Copilot May 20, 2025 13:30
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances attribute argument validation by enforcing accessibility checks on property setters when used in attribute targets.

  • Retrieves the setter method and checks its accessibility using existing MethInfoChecks logic.
  • Emits a distinct error (tcPropertyCannotBeSet1) if the setter exists but isn’t accessible.
  • Integrates the new check into the Item.Property branch of TcAttributeEx.
Comments suppressed due to low confidence (2)

src/Compiler/Checking/Expressions/CheckExpressions.fs:11414

  • [nitpick] Consider renaming setterMeth to setterMethod for clarity and consistency with other method-related variables.
let setterMeth = pinfo.SetterMethod

src/Compiler/Checking/Expressions/CheckExpressions.fs:11414

  • Add unit tests covering this new setter accessibility check in attribute arguments to prevent regressions and validate both allowed and disallowed cases.
let setterMeth = pinfo.SetterMethod

@vzarytovskii
Copy link
Member

Is it the same as #18575?

@evgTSV
Copy link
Contributor Author

evgTSV commented May 20, 2025

@vzarytovskii I don't think #18575 can solve this problem, I looked into the code of the IsPropInfoAccessible function, it only defines access to the property getter, so I used the code from checking the property during the processing of the constructors args of a type that is not an attribute

@evgTSV
Copy link
Contributor Author

evgTSV commented May 20, 2025

Ok, I can close this pr and go to #18575

@vzarytovskii
Copy link
Member

Ok, I can close this pr and go to #18575

It's fine to process here, I was just curious whether it overlaps or not. I can close that one down and you can incorporate changes into one/this one. Conversing with copilot is a bit tiresome.

@evgTSV
Copy link
Contributor Author

evgTSV commented May 20, 2025

It's fine to process here, I was just curious whether it overlaps or not. I can close that one down and you can incorporate changes into one/this one. Conversing with copilot is a bit tiresome.

Yeah, I'll work on this pr then

@T-Gro
Copy link
Member

T-Gro commented May 21, 2025

For sure carry on, please consider the currently open copilot PRs more of an exercise of the capabilities - pick anything good from there and we can close it down and keep yours only :)

@evgTSV
Copy link
Contributor Author

evgTSV commented May 21, 2025

@dotnet-policy-service agree

@github-project-automation github-project-automation bot moved this from New to In Progress in F# Compiler and Tooling May 22, 2025
@T-Gro T-Gro enabled auto-merge (squash) May 22, 2025 11:48
@T-Gro T-Gro merged commit 24208f0 into dotnet:main May 22, 2025
38 of 39 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in F# Compiler and Tooling May 22, 2025
@evgTSV evgTSV deleted the fix-checking branch May 22, 2025 20:44
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.

Compiler allows setting a value of a private property on attribute
4 participants