-
Notifications
You must be signed in to change notification settings - Fork 822
Fix compiler allowing setting private property on attribute #18575
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
Conversation
Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
tests/FSharp.Compiler.ComponentTests/Attributes/AttributePrivateSetterTests.fs
Outdated
Show resolved
Hide resolved
Co-authored-by: vzarytovskii <1260985+vzarytovskii@users.noreply.github.com>
tests/FSharp.Compiler.ComponentTests/Attributes/AttributePrivateSetterTests.fs
Outdated
Show resolved
Hide resolved
tests/FSharp.Compiler.ComponentTests/Attributes/AttributePrivateSetterTests.fs
Outdated
Show resolved
Hide resolved
Co-authored-by: vzarytovskii <1260985+vzarytovskii@users.noreply.github.com>
/run xlf |
❗ Release notes requiredCaution 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:
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
|
Co-authored-by: vzarytovskii <1260985+vzarytovskii@users.noreply.github.com>
Updated the XLF files with the new error message in c2b96fb Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Co-authored-by: vzarytovskii <1260985+vzarytovskii@users.noreply.github.com>
/run fantomas |
Failed to run fantomas: https://github.com/dotnet/fsharp/actions/runs/15140298466 |
[<Fact>] | ||
let ``Compiler disallows setting a value of a private property on attribute``() = | ||
// Arrange | ||
let code = """ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is too complicated.
Please use a BCL attribute which has private setter instead - you can use the System.Diagnostics.ConditionalAttribute
from BCL and its ConditionString
property - this one has a private setter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That way, you can have a standalone F# example and do not have to deal with C# and multiple sources.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've simplified the test by using System.Diagnostics.ConditionalAttribute
from BCL and its ConditionString
property as suggested in 0b587e2. This eliminates the need for the custom C# attribute and makes the test more straightforward.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've simplified the test to use System.Diagnostics.ConditionalAttribute
as suggested in commit 0b587e2. This approach is more straightforward and eliminates the need for custom C# code.
open Xunit | ||
open FSharp.Test.Compiler | ||
|
||
[<TestFixture>] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dont use a type and a testfixture. Just put tests as let testName() = ..
functions directly in a module.
On the first line, change the namespace to become a module ending with AttributePrivateSetter
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the test file structure in commit ea12c3f - changed from namespace to module AttributePrivateSetter
, removed the TestFixture and class, and made the test a direct function in the module.
… test Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
I'll run the Fantomas formatting once the test changes are approved. Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
|> compile | ||
|> shouldFail | ||
|> withDiagnostics [ | ||
(DiagnosticLevel.Error, 3248, "Property 'ConditionString' on attribute cannot be set because the setter is private", (5, 13, 5, 41)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expecting a tuple of length 6 of type ErrorType * Line * Col * Line * Col * string but given a tuple of length 4 of type 'a * int * string * (int * int * int * int).
Look at other files using the withDiagnostics
in this project and do this properly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 8c9c0b4 by updating the withDiagnostics call to use the proper format with the expected tuple structure: (Error, code, Line row1, Col col1, Line row2, Col col2, message)
Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
Humans : 1 |
This PR fixes an issue where the F# compiler was incorrectly allowing code to set a value of a property with a private setter on an attribute. This doesn't work at runtime and isn't allowed by the C# compiler.
Problem
When using attributes with named parameters, the compiler was only checking if the property has a setter (
pinfo.HasSetter
), but wasn't checking if the setter is accessible from the current context.Example:
In this example,
IsDefault
has a private setter, but the F# compiler was incorrectly allowing it to be set.Changes
TcAttributeEx
functionFixes #18571.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
crl3.digicert.com
dotnet build
(dns block)dc.services.visualstudio.com
/home/REDACTED/work/fsharp/fsharp/.dotnet/dotnet msbuild /m /nologo /clp:Summary /v:minimal /nr:true /warnaserror /p:TreatWarningsAsErrors=true /p:ContinuousIntegrationBuild=false /home/REDACTED/work/fsharp/fsharp/artifacts/toolset/restore.proj /t:__WriteToolsetLocation /clp:ErrorsOnly;NoSummary /p:__ToolsetLocationOutputFile=/home/REDACTED/work/fsharp/fsharp/artifacts/toolset/9.0.0-beta.25266.2.txt
(dns block)ocsp.digicert.com
dotnet build
(dns block)pkgs.dev.azure.com
/home/REDACTED/work/fsharp/fsharp/.dotnet/dotnet msbuild /m /nologo /clp:Summary /v:minimal /nr:true /warnaserror /p:TreatWarningsAsErrors=true /p:ContinuousIntegrationBuild=false /home/REDACTED/work/fsharp/fsharp/artifacts/toolset/restore.proj /t:__WriteToolsetLocation /clp:ErrorsOnly;NoSummary /p:__ToolsetLocationOutputFile=/home/REDACTED/work/fsharp/fsharp/artifacts/toolset/9.0.0-beta.25266.2.txt
(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.