Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Compiler/Checking/Expressions/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11411,6 +11411,9 @@ and TcAttributeEx canFail (cenv: cenv) (env: TcEnv) attrTgt attrEx (synAttr: Syn
| Item.Property (info = [pinfo]) ->
if not pinfo.HasSetter then
errorR(Error(FSComp.SR.tcPropertyCannotBeSet0(), m))
// Check if the setter is accessible
if not (IsPropInfoAccessible g cenv.amap m ad pinfo) then
errorR(Error(FSComp.SR.tcPropertyCannotBeSetPrivateSetter(id.idText), m))
id.idText, true, pinfo.GetPropertyType(cenv.amap, m)
| Item.ILField finfo ->
CheckILFieldInfoAccessible g cenv.amap m ad finfo
Expand Down
1 change: 1 addition & 0 deletions src/Compiler/FSComp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1523,6 +1523,7 @@ notAFunctionButMaybeDeclaration,"This value is not a function and cannot be appl
3242,tcTypeDoesNotInheritAttribute,"This type does not inherit Attribute, it will not work correctly with other .NET languages."
3243,parsInvalidAnonRecdExpr,"Invalid anonymous record expression"
3244,parsInvalidAnonRecdType,"Invalid anonymous record type"
3248,tcPropertyCannotBeSetPrivateSetter,"Property '%s' on attribute cannot be set because the setter is private"
3245,tcCopyAndUpdateNeedsRecordType,"The input to a copy-and-update expression that creates an anonymous record must be either an anonymous record or a record"
3246,tcAugmentationsCannotHaveAttributes,"Attributes cannot be applied to type extensions."
3247,couldNotLoadDependencyManagerExtension,"The dependency manager extension %s could not be loaded. Message: %s"
Expand Down
5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.pl.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.pt-BR.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.ru.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.tr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.zh-Hans.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.zh-Hant.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module FSharp.Compiler.ComponentTests.AttributePrivateSetter

open Xunit
open FSharp.Test.Compiler

[<Fact>]
let ``Compiler disallows setting a value of a private property on attribute``() =
// Arrange
let mainCode = """
module AttributeTest

open System.Diagnostics

[<Conditional("DEBUG", ConditionString = "RELEASE")>]
type TestClass() = class end
"""
// Act & Assert
FSharp mainCode
|> compile
|> shouldFail
|> withDiagnostics [
(Error, 3248, Line 5, Col 13, Line 5, Col 41, "Property 'ConditionString' on attribute cannot be set because the setter is private")

Check failure on line 22 in tests/FSharp.Compiler.ComponentTests/Attributes/AttributePrivateSetterTests.fs

View check run for this annotation

Azure Pipelines / fsharp-ci (Build Linux)

tests/FSharp.Compiler.ComponentTests/Attributes/AttributePrivateSetterTests.fs#L22

tests/FSharp.Compiler.ComponentTests/Attributes/AttributePrivateSetterTests.fs(22,10): error FS0001: (NETCORE_ENGINEERING_TELEMETRY=Build) Type mismatch. Expecting a tuple of length 6 of type� ErrorType * Line * Col * Line * Col * string �but given a tuple of length 7 of type� (int -> ErrorType) * int * Line * Col * Line * Col * string

Check failure on line 22 in tests/FSharp.Compiler.ComponentTests/Attributes/AttributePrivateSetterTests.fs

View check run for this annotation

Azure Pipelines / fsharp-ci (Build MacOS)

tests/FSharp.Compiler.ComponentTests/Attributes/AttributePrivateSetterTests.fs#L22

tests/FSharp.Compiler.ComponentTests/Attributes/AttributePrivateSetterTests.fs(22,10): error FS0001: (NETCORE_ENGINEERING_TELEMETRY=Build) Type mismatch. Expecting a tuple of length 6 of type� ErrorType * Line * Col * Line * Col * string �but given a tuple of length 7 of type� (int -> ErrorType) * int * Line * Col * Line * Col * string

Check failure on line 22 in tests/FSharp.Compiler.ComponentTests/Attributes/AttributePrivateSetterTests.fs

View check run for this annotation

Azure Pipelines / fsharp-ci

tests/FSharp.Compiler.ComponentTests/Attributes/AttributePrivateSetterTests.fs#L22

tests/FSharp.Compiler.ComponentTests/Attributes/AttributePrivateSetterTests.fs(22,10): error FS0001: (NETCORE_ENGINEERING_TELEMETRY=Build) Type mismatch. Expecting a tuple of length 6 of type� ErrorType * Line * Col * Line * Col * string �but given a tuple of length 7 of type� (int -> ErrorType) * int * Line * Col * Line * Col * string
]
|> ignore
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@
<Compile Include="CompilerService\AsyncMemoize.fs" />
<Compile Include="CompilerService\FSharpWorkspace.fs" />
<Compile Include="CompilerService\DependencyGraph.fs" />
<Compile Include="Attributes\AttributePrivateSetterTests.fs" />
<Compile Include="Debugger\PortablePdbs.fs" />
<Compile Include="Diagnostics\async.fs" />
<Compile Include="Diagnostics\General.fs" />
Expand Down
Loading