From a3d7b51d5ed53d49599f30418f9e6f7473e8d405 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 20 May 2025 07:45:47 +0000 Subject: [PATCH 1/9] Initial plan for issue From 0ef0d9ee41f057df458531360eb577d3d5572c73 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 20 May 2025 07:58:08 +0000 Subject: [PATCH 2/9] Fix compiler allowing setting private property on attribute (#18571) Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com> --- .../Checking/Expressions/CheckExpressions.fs | 3 ++ src/Compiler/FSComp.txt | 1 + .../Attributes/AttributePrivateSetterTests.fs | 44 +++++++++++++++++++ .../FSharp.Compiler.ComponentTests.fsproj | 1 + 4 files changed, 49 insertions(+) create mode 100644 tests/FSharp.Compiler.ComponentTests/Attributes/AttributePrivateSetterTests.fs diff --git a/src/Compiler/Checking/Expressions/CheckExpressions.fs b/src/Compiler/Checking/Expressions/CheckExpressions.fs index 567e1da0310..f0ae89a1ff8 100644 --- a/src/Compiler/Checking/Expressions/CheckExpressions.fs +++ b/src/Compiler/Checking/Expressions/CheckExpressions.fs @@ -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.tcPropertyCannotBeSet1("'" + id.idText + "' on attribute (the setter is private)"), m)) id.idText, true, pinfo.GetPropertyType(cenv.amap, m) | Item.ILField finfo -> CheckILFieldInfoAccessible g cenv.amap m ad finfo diff --git a/src/Compiler/FSComp.txt b/src/Compiler/FSComp.txt index 1d7e9d6499a..ca0a5253a4d 100644 --- a/src/Compiler/FSComp.txt +++ b/src/Compiler/FSComp.txt @@ -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" +3245,namedAttributeArgumentsMustBePublicWriteable,"The property is not settable. Named attribute arguments must be fields which are not readonly, static, or const, or read-write properties which are public and not static." 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" diff --git a/tests/FSharp.Compiler.ComponentTests/Attributes/AttributePrivateSetterTests.fs b/tests/FSharp.Compiler.ComponentTests/Attributes/AttributePrivateSetterTests.fs new file mode 100644 index 00000000000..2df1906ffd4 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Attributes/AttributePrivateSetterTests.fs @@ -0,0 +1,44 @@ +namespace FSharp.Compiler.ComponentTests + +open Xunit +open FSharp.Test.Compiler + +[] +type AttributePrivateSetterTests() = + + [] + let ``Compiler disallows setting a value of a private property on attribute``() = + // Arrange + let code = """ +using System; + +namespace AttributeTest +{ + [AttributeUsage(AttributeTargets.All)] + public class TestAttribute : Attribute + { + public TestAttribute(string name) + { + Name = name; + } + + public string Name { get; } + + public bool IsDefault { get; private set; } + } +} +""" + let mainCode = """ +module AttributeTest + +[] +type TestClass() = class end +""" + // Act & Assert + CompilerAssert.TypeCheckWithErrors mainCode [(code, "cs")] [ + FSharpDiagnostic.Create( + "tcPropertyCannotBeSet1", + "Property 'IsDefault' on attribute (the setter is private) cannot be set", + 10, 50, 10, 51) + ] + |> ignore \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj index 36754f92217..97366ff4b6b 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj +++ b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj @@ -312,6 +312,7 @@ + From 1c48b11b8275b29f152edc50df528a009f303ef0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 20 May 2025 11:01:32 +0000 Subject: [PATCH 3/9] Address PR feedback Co-authored-by: vzarytovskii <1260985+vzarytovskii@users.noreply.github.com> --- .../Checking/Expressions/CheckExpressions.fs | 2 +- src/Compiler/FSComp.txt | 2 +- .../Attributes/AttributePrivateSetterTests.fs | 12 ++++++------ 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Compiler/Checking/Expressions/CheckExpressions.fs b/src/Compiler/Checking/Expressions/CheckExpressions.fs index f0ae89a1ff8..34dc4205fea 100644 --- a/src/Compiler/Checking/Expressions/CheckExpressions.fs +++ b/src/Compiler/Checking/Expressions/CheckExpressions.fs @@ -11413,7 +11413,7 @@ and TcAttributeEx canFail (cenv: cenv) (env: TcEnv) attrTgt attrEx (synAttr: Syn 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.tcPropertyCannotBeSet1("'" + id.idText + "' on attribute (the setter is private)"), m)) + 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 diff --git a/src/Compiler/FSComp.txt b/src/Compiler/FSComp.txt index ca0a5253a4d..39ed48e949e 100644 --- a/src/Compiler/FSComp.txt +++ b/src/Compiler/FSComp.txt @@ -1523,7 +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" -3245,namedAttributeArgumentsMustBePublicWriteable,"The property is not settable. Named attribute arguments must be fields which are not readonly, static, or const, or read-write properties which are public and not static." +3245,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" diff --git a/tests/FSharp.Compiler.ComponentTests/Attributes/AttributePrivateSetterTests.fs b/tests/FSharp.Compiler.ComponentTests/Attributes/AttributePrivateSetterTests.fs index 2df1906ffd4..ee9081c3e13 100644 --- a/tests/FSharp.Compiler.ComponentTests/Attributes/AttributePrivateSetterTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Attributes/AttributePrivateSetterTests.fs @@ -35,10 +35,10 @@ module AttributeTest type TestClass() = class end """ // Act & Assert - CompilerAssert.TypeCheckWithErrors mainCode [(code, "cs")] [ - FSharpDiagnostic.Create( - "tcPropertyCannotBeSet1", - "Property 'IsDefault' on attribute (the setter is private) cannot be set", - 10, 50, 10, 51) - ] + FSharp mainCode + |> withAdditionalSources [(code, "cs")] + |> compile + |> shouldFail + |> withErrorCode "tcPropertyCannotBeSet1" + |> withSingleDiagnostic "Property 'IsDefault' on attribute (the setter is private) cannot be set" |> ignore \ No newline at end of file From bee35f3ac90be108ffc4cdaf1e13b94e354a4058 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 20 May 2025 11:18:27 +0000 Subject: [PATCH 4/9] Fix error code and test for private setter attribute issue Co-authored-by: vzarytovskii <1260985+vzarytovskii@users.noreply.github.com> --- src/Compiler/FSComp.txt | 2 +- .../Attributes/AttributePrivateSetterTests.fs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Compiler/FSComp.txt b/src/Compiler/FSComp.txt index 39ed48e949e..6868672bf60 100644 --- a/src/Compiler/FSComp.txt +++ b/src/Compiler/FSComp.txt @@ -1523,7 +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" -3245,tcPropertyCannotBeSetPrivateSetter,"Property '%s' on attribute cannot be set because the setter is private" +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" diff --git a/tests/FSharp.Compiler.ComponentTests/Attributes/AttributePrivateSetterTests.fs b/tests/FSharp.Compiler.ComponentTests/Attributes/AttributePrivateSetterTests.fs index ee9081c3e13..dfb7cf433df 100644 --- a/tests/FSharp.Compiler.ComponentTests/Attributes/AttributePrivateSetterTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Attributes/AttributePrivateSetterTests.fs @@ -39,6 +39,7 @@ type TestClass() = class end |> withAdditionalSources [(code, "cs")] |> compile |> shouldFail - |> withErrorCode "tcPropertyCannotBeSet1" - |> withSingleDiagnostic "Property 'IsDefault' on attribute (the setter is private) cannot be set" + |> withDiagnostics [ + (DiagnosticLevel.Error, 3248, "Property 'IsDefault' on attribute cannot be set because the setter is private", (4, 21, 4, 43)) + ] |> ignore \ No newline at end of file From c2b96fbf98b6931edf8175e42233f4f7acb6d24d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 20 May 2025 12:06:14 +0000 Subject: [PATCH 5/9] Update XLF files with new error message Co-authored-by: vzarytovskii <1260985+vzarytovskii@users.noreply.github.com> --- src/Compiler/xlf/FSComp.txt.cs.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.de.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.es.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.fr.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.it.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.ja.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.ko.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.pl.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.pt-BR.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.ru.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.tr.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.zh-Hans.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.zh-Hant.xlf | 5 +++++ 13 files changed, 65 insertions(+) diff --git a/src/Compiler/xlf/FSComp.txt.cs.xlf b/src/Compiler/xlf/FSComp.txt.cs.xlf index caa825a8245..713ffc8a9fd 100644 --- a/src/Compiler/xlf/FSComp.txt.cs.xlf +++ b/src/Compiler/xlf/FSComp.txt.cs.xlf @@ -5147,6 +5147,11 @@ Tato vlastnost se nedá nastavit. + + Property '%s' on attribute cannot be set because the setter is private + Property '%s' on attribute cannot be set because the setter is private + + This property or field was not found on this custom attribute type Tato vlastnost nebo pole se u tohoto typu vlastního atributu nenašla. diff --git a/src/Compiler/xlf/FSComp.txt.de.xlf b/src/Compiler/xlf/FSComp.txt.de.xlf index 2d193f09a0e..22987863267 100644 --- a/src/Compiler/xlf/FSComp.txt.de.xlf +++ b/src/Compiler/xlf/FSComp.txt.de.xlf @@ -5147,6 +5147,11 @@ Diese Eigenschaft kann nicht festgelegt werden. + + Property '%s' on attribute cannot be set because the setter is private + Property '%s' on attribute cannot be set because the setter is private + + This property or field was not found on this custom attribute type Diese Eigenschaft bzw. dieses Feld wurde in diesem benutzerdefinierten Attributtyp nicht gefunden. diff --git a/src/Compiler/xlf/FSComp.txt.es.xlf b/src/Compiler/xlf/FSComp.txt.es.xlf index 1e0f79d0124..d39664e8ac1 100644 --- a/src/Compiler/xlf/FSComp.txt.es.xlf +++ b/src/Compiler/xlf/FSComp.txt.es.xlf @@ -5147,6 +5147,11 @@ Esta propiedad no se puede establecer. + + Property '%s' on attribute cannot be set because the setter is private + Property '%s' on attribute cannot be set because the setter is private + + This property or field was not found on this custom attribute type No se encontró esta propiedad o campo en este tipo de atributo personalizado. diff --git a/src/Compiler/xlf/FSComp.txt.fr.xlf b/src/Compiler/xlf/FSComp.txt.fr.xlf index 71a14ff33f0..5c04bb3bf13 100644 --- a/src/Compiler/xlf/FSComp.txt.fr.xlf +++ b/src/Compiler/xlf/FSComp.txt.fr.xlf @@ -5147,6 +5147,11 @@ Impossible de définir cette propriété + + Property '%s' on attribute cannot be set because the setter is private + Property '%s' on attribute cannot be set because the setter is private + + This property or field was not found on this custom attribute type Impossible de trouver cette propriété ou ce champ dans ce type d'attribut personnalisé diff --git a/src/Compiler/xlf/FSComp.txt.it.xlf b/src/Compiler/xlf/FSComp.txt.it.xlf index 12f56c30e93..dd7d6624643 100644 --- a/src/Compiler/xlf/FSComp.txt.it.xlf +++ b/src/Compiler/xlf/FSComp.txt.it.xlf @@ -5147,6 +5147,11 @@ Non è possibile impostare questa proprietà + + Property '%s' on attribute cannot be set because the setter is private + Property '%s' on attribute cannot be set because the setter is private + + This property or field was not found on this custom attribute type La proprietà o il campo non è stato trovato in questo tipo di attributo personalizzato diff --git a/src/Compiler/xlf/FSComp.txt.ja.xlf b/src/Compiler/xlf/FSComp.txt.ja.xlf index d84ecad7170..8be29947a05 100644 --- a/src/Compiler/xlf/FSComp.txt.ja.xlf +++ b/src/Compiler/xlf/FSComp.txt.ja.xlf @@ -5147,6 +5147,11 @@ このプロパティは設定できません + + Property '%s' on attribute cannot be set because the setter is private + Property '%s' on attribute cannot be set because the setter is private + + This property or field was not found on this custom attribute type このカスタム属性型に、このプロパティまたはフィールドが見つかりませんでした diff --git a/src/Compiler/xlf/FSComp.txt.ko.xlf b/src/Compiler/xlf/FSComp.txt.ko.xlf index 39c3a728b37..5d123f1cedf 100644 --- a/src/Compiler/xlf/FSComp.txt.ko.xlf +++ b/src/Compiler/xlf/FSComp.txt.ko.xlf @@ -5147,6 +5147,11 @@ 이 속성은 설정할 수 없습니다. + + Property '%s' on attribute cannot be set because the setter is private + Property '%s' on attribute cannot be set because the setter is private + + This property or field was not found on this custom attribute type 이 속성 또는 필드를 이 사용자 지정 특성 형식에서 찾을 수 없습니다. diff --git a/src/Compiler/xlf/FSComp.txt.pl.xlf b/src/Compiler/xlf/FSComp.txt.pl.xlf index e5f2bda5529..dacd4c698c9 100644 --- a/src/Compiler/xlf/FSComp.txt.pl.xlf +++ b/src/Compiler/xlf/FSComp.txt.pl.xlf @@ -5147,6 +5147,11 @@ Nie można ustawić tej właściwości + + Property '%s' on attribute cannot be set because the setter is private + Property '%s' on attribute cannot be set because the setter is private + + This property or field was not found on this custom attribute type Nie odnaleziono tej właściwości pola w tym niestandardowym typie atrybutu diff --git a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf index c69f534b10e..6e64308b7c4 100644 --- a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf +++ b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf @@ -5147,6 +5147,11 @@ Esta propriedade não pode ser definida + + Property '%s' on attribute cannot be set because the setter is private + Property '%s' on attribute cannot be set because the setter is private + + This property or field was not found on this custom attribute type Esta propriedade ou campo não foram encontrados neste tipo de atributo personalizado diff --git a/src/Compiler/xlf/FSComp.txt.ru.xlf b/src/Compiler/xlf/FSComp.txt.ru.xlf index ca41d4affcc..9933c41ec9c 100644 --- a/src/Compiler/xlf/FSComp.txt.ru.xlf +++ b/src/Compiler/xlf/FSComp.txt.ru.xlf @@ -5147,6 +5147,11 @@ Это свойство задать нельзя + + Property '%s' on attribute cannot be set because the setter is private + Property '%s' on attribute cannot be set because the setter is private + + This property or field was not found on this custom attribute type Данное свойство или поле не было найдено в этом пользовательском типе атрибута diff --git a/src/Compiler/xlf/FSComp.txt.tr.xlf b/src/Compiler/xlf/FSComp.txt.tr.xlf index 17a75ffa27c..eeead0c251c 100644 --- a/src/Compiler/xlf/FSComp.txt.tr.xlf +++ b/src/Compiler/xlf/FSComp.txt.tr.xlf @@ -5147,6 +5147,11 @@ Bu özellik ayarlanamaz + + Property '%s' on attribute cannot be set because the setter is private + Property '%s' on attribute cannot be set because the setter is private + + This property or field was not found on this custom attribute type Bu özellik veya alan bu özel öznitelik türünde bulunamadı diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf index 155480c6314..52f99a62130 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf @@ -5147,6 +5147,11 @@ 无法设置此属性 + + Property '%s' on attribute cannot be set because the setter is private + Property '%s' on attribute cannot be set because the setter is private + + This property or field was not found on this custom attribute type 未在此自定义特性类型中找到此属性或字段 diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf index 3c96310c8a7..4e01679e336 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf @@ -5147,6 +5147,11 @@ 無法設定這個屬性 + + Property '%s' on attribute cannot be set because the setter is private + Property '%s' on attribute cannot be set because the setter is private + + This property or field was not found on this custom attribute type 在這個自訂屬性類型上找不到這個屬性或欄位 From 5b2b831ea4a6481bbf267e3fb11da6a072a0b036 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 20 May 2025 14:27:34 +0000 Subject: [PATCH 6/9] Automated command ran: xlf Co-authored-by: vzarytovskii <1260985+vzarytovskii@users.noreply.github.com> --- src/Compiler/xlf/FSComp.txt.cs.xlf | 4 ++-- src/Compiler/xlf/FSComp.txt.de.xlf | 4 ++-- src/Compiler/xlf/FSComp.txt.es.xlf | 4 ++-- src/Compiler/xlf/FSComp.txt.fr.xlf | 4 ++-- src/Compiler/xlf/FSComp.txt.it.xlf | 4 ++-- src/Compiler/xlf/FSComp.txt.ja.xlf | 4 ++-- src/Compiler/xlf/FSComp.txt.ko.xlf | 4 ++-- src/Compiler/xlf/FSComp.txt.pl.xlf | 4 ++-- src/Compiler/xlf/FSComp.txt.pt-BR.xlf | 4 ++-- src/Compiler/xlf/FSComp.txt.ru.xlf | 4 ++-- src/Compiler/xlf/FSComp.txt.tr.xlf | 4 ++-- src/Compiler/xlf/FSComp.txt.zh-Hans.xlf | 4 ++-- src/Compiler/xlf/FSComp.txt.zh-Hant.xlf | 4 ++-- 13 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/Compiler/xlf/FSComp.txt.cs.xlf b/src/Compiler/xlf/FSComp.txt.cs.xlf index 713ffc8a9fd..8982b80ff6c 100644 --- a/src/Compiler/xlf/FSComp.txt.cs.xlf +++ b/src/Compiler/xlf/FSComp.txt.cs.xlf @@ -5148,8 +5148,8 @@ - Property '%s' on attribute cannot be set because the setter is private - Property '%s' on attribute cannot be set because the setter is private + Property '{0}' on attribute cannot be set because the setter is private + Property '{0}' on attribute cannot be set because the setter is private diff --git a/src/Compiler/xlf/FSComp.txt.de.xlf b/src/Compiler/xlf/FSComp.txt.de.xlf index 22987863267..51550f364c0 100644 --- a/src/Compiler/xlf/FSComp.txt.de.xlf +++ b/src/Compiler/xlf/FSComp.txt.de.xlf @@ -5148,8 +5148,8 @@ - Property '%s' on attribute cannot be set because the setter is private - Property '%s' on attribute cannot be set because the setter is private + Property '{0}' on attribute cannot be set because the setter is private + Property '{0}' on attribute cannot be set because the setter is private diff --git a/src/Compiler/xlf/FSComp.txt.es.xlf b/src/Compiler/xlf/FSComp.txt.es.xlf index d39664e8ac1..23c47acecf3 100644 --- a/src/Compiler/xlf/FSComp.txt.es.xlf +++ b/src/Compiler/xlf/FSComp.txt.es.xlf @@ -5148,8 +5148,8 @@ - Property '%s' on attribute cannot be set because the setter is private - Property '%s' on attribute cannot be set because the setter is private + Property '{0}' on attribute cannot be set because the setter is private + Property '{0}' on attribute cannot be set because the setter is private diff --git a/src/Compiler/xlf/FSComp.txt.fr.xlf b/src/Compiler/xlf/FSComp.txt.fr.xlf index 5c04bb3bf13..455b2447c8c 100644 --- a/src/Compiler/xlf/FSComp.txt.fr.xlf +++ b/src/Compiler/xlf/FSComp.txt.fr.xlf @@ -5148,8 +5148,8 @@ - Property '%s' on attribute cannot be set because the setter is private - Property '%s' on attribute cannot be set because the setter is private + Property '{0}' on attribute cannot be set because the setter is private + Property '{0}' on attribute cannot be set because the setter is private diff --git a/src/Compiler/xlf/FSComp.txt.it.xlf b/src/Compiler/xlf/FSComp.txt.it.xlf index dd7d6624643..33ae7f4ece3 100644 --- a/src/Compiler/xlf/FSComp.txt.it.xlf +++ b/src/Compiler/xlf/FSComp.txt.it.xlf @@ -5148,8 +5148,8 @@ - Property '%s' on attribute cannot be set because the setter is private - Property '%s' on attribute cannot be set because the setter is private + Property '{0}' on attribute cannot be set because the setter is private + Property '{0}' on attribute cannot be set because the setter is private diff --git a/src/Compiler/xlf/FSComp.txt.ja.xlf b/src/Compiler/xlf/FSComp.txt.ja.xlf index 8be29947a05..b034bb1004d 100644 --- a/src/Compiler/xlf/FSComp.txt.ja.xlf +++ b/src/Compiler/xlf/FSComp.txt.ja.xlf @@ -5148,8 +5148,8 @@ - Property '%s' on attribute cannot be set because the setter is private - Property '%s' on attribute cannot be set because the setter is private + Property '{0}' on attribute cannot be set because the setter is private + Property '{0}' on attribute cannot be set because the setter is private diff --git a/src/Compiler/xlf/FSComp.txt.ko.xlf b/src/Compiler/xlf/FSComp.txt.ko.xlf index 5d123f1cedf..1d439c35b86 100644 --- a/src/Compiler/xlf/FSComp.txt.ko.xlf +++ b/src/Compiler/xlf/FSComp.txt.ko.xlf @@ -5148,8 +5148,8 @@ - Property '%s' on attribute cannot be set because the setter is private - Property '%s' on attribute cannot be set because the setter is private + Property '{0}' on attribute cannot be set because the setter is private + Property '{0}' on attribute cannot be set because the setter is private diff --git a/src/Compiler/xlf/FSComp.txt.pl.xlf b/src/Compiler/xlf/FSComp.txt.pl.xlf index dacd4c698c9..e91640c2673 100644 --- a/src/Compiler/xlf/FSComp.txt.pl.xlf +++ b/src/Compiler/xlf/FSComp.txt.pl.xlf @@ -5148,8 +5148,8 @@ - Property '%s' on attribute cannot be set because the setter is private - Property '%s' on attribute cannot be set because the setter is private + Property '{0}' on attribute cannot be set because the setter is private + Property '{0}' on attribute cannot be set because the setter is private diff --git a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf index 6e64308b7c4..82e5411199a 100644 --- a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf +++ b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf @@ -5148,8 +5148,8 @@ - Property '%s' on attribute cannot be set because the setter is private - Property '%s' on attribute cannot be set because the setter is private + Property '{0}' on attribute cannot be set because the setter is private + Property '{0}' on attribute cannot be set because the setter is private diff --git a/src/Compiler/xlf/FSComp.txt.ru.xlf b/src/Compiler/xlf/FSComp.txt.ru.xlf index 9933c41ec9c..6503bb5d445 100644 --- a/src/Compiler/xlf/FSComp.txt.ru.xlf +++ b/src/Compiler/xlf/FSComp.txt.ru.xlf @@ -5148,8 +5148,8 @@ - Property '%s' on attribute cannot be set because the setter is private - Property '%s' on attribute cannot be set because the setter is private + Property '{0}' on attribute cannot be set because the setter is private + Property '{0}' on attribute cannot be set because the setter is private diff --git a/src/Compiler/xlf/FSComp.txt.tr.xlf b/src/Compiler/xlf/FSComp.txt.tr.xlf index eeead0c251c..6c793f05567 100644 --- a/src/Compiler/xlf/FSComp.txt.tr.xlf +++ b/src/Compiler/xlf/FSComp.txt.tr.xlf @@ -5148,8 +5148,8 @@ - Property '%s' on attribute cannot be set because the setter is private - Property '%s' on attribute cannot be set because the setter is private + Property '{0}' on attribute cannot be set because the setter is private + Property '{0}' on attribute cannot be set because the setter is private diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf index 52f99a62130..12199c5cdd1 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf @@ -5148,8 +5148,8 @@ - Property '%s' on attribute cannot be set because the setter is private - Property '%s' on attribute cannot be set because the setter is private + Property '{0}' on attribute cannot be set because the setter is private + Property '{0}' on attribute cannot be set because the setter is private diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf index 4e01679e336..692c4cd9928 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf @@ -5148,8 +5148,8 @@ - Property '%s' on attribute cannot be set because the setter is private - Property '%s' on attribute cannot be set because the setter is private + Property '{0}' on attribute cannot be set because the setter is private + Property '{0}' on attribute cannot be set because the setter is private From 0b587e2066d2569cfbd0f454fe094914d54a1c2e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 21 May 2025 10:16:44 +0000 Subject: [PATCH 7/9] Replace custom attribute with ConditionalAttribute for private setter test Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com> --- .../Attributes/AttributePrivateSetterTests.fs | 26 +++---------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/tests/FSharp.Compiler.ComponentTests/Attributes/AttributePrivateSetterTests.fs b/tests/FSharp.Compiler.ComponentTests/Attributes/AttributePrivateSetterTests.fs index dfb7cf433df..74fa235b843 100644 --- a/tests/FSharp.Compiler.ComponentTests/Attributes/AttributePrivateSetterTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Attributes/AttributePrivateSetterTests.fs @@ -9,37 +9,19 @@ type AttributePrivateSetterTests() = [] let ``Compiler disallows setting a value of a private property on attribute``() = // Arrange - let code = """ -using System; - -namespace AttributeTest -{ - [AttributeUsage(AttributeTargets.All)] - public class TestAttribute : Attribute - { - public TestAttribute(string name) - { - Name = name; - } - - public string Name { get; } - - public bool IsDefault { get; private set; } - } -} -""" let mainCode = """ module AttributeTest -[] +open System.Diagnostics + +[] type TestClass() = class end """ // Act & Assert FSharp mainCode - |> withAdditionalSources [(code, "cs")] |> compile |> shouldFail |> withDiagnostics [ - (DiagnosticLevel.Error, 3248, "Property 'IsDefault' on attribute cannot be set because the setter is private", (4, 21, 4, 43)) + (DiagnosticLevel.Error, 3248, "Property 'ConditionString' on attribute cannot be set because the setter is private", (5, 13, 5, 41)) ] |> ignore \ No newline at end of file From ea12c3f7e083979415b6fe7a563c023aa49c9f52 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 21 May 2025 10:22:43 +0000 Subject: [PATCH 8/9] Convert test class to module functions Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com> --- .../Attributes/AttributePrivateSetterTests.fs | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/tests/FSharp.Compiler.ComponentTests/Attributes/AttributePrivateSetterTests.fs b/tests/FSharp.Compiler.ComponentTests/Attributes/AttributePrivateSetterTests.fs index 74fa235b843..ecf2fd4ca94 100644 --- a/tests/FSharp.Compiler.ComponentTests/Attributes/AttributePrivateSetterTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Attributes/AttributePrivateSetterTests.fs @@ -1,15 +1,12 @@ -namespace FSharp.Compiler.ComponentTests +module FSharp.Compiler.ComponentTests.AttributePrivateSetter open Xunit open FSharp.Test.Compiler -[] -type AttributePrivateSetterTests() = - - [] - let ``Compiler disallows setting a value of a private property on attribute``() = - // Arrange - let mainCode = """ +[] +let ``Compiler disallows setting a value of a private property on attribute``() = + // Arrange + let mainCode = """ module AttributeTest open System.Diagnostics @@ -17,11 +14,11 @@ open System.Diagnostics [] type TestClass() = class end """ - // Act & Assert - FSharp mainCode - |> compile - |> shouldFail - |> withDiagnostics [ - (DiagnosticLevel.Error, 3248, "Property 'ConditionString' on attribute cannot be set because the setter is private", (5, 13, 5, 41)) - ] - |> ignore \ No newline at end of file + // Act & Assert + FSharp mainCode + |> compile + |> shouldFail + |> withDiagnostics [ + (DiagnosticLevel.Error, 3248, "Property 'ConditionString' on attribute cannot be set because the setter is private", (5, 13, 5, 41)) + ] + |> ignore \ No newline at end of file From 8c9c0b48b3bb5206eb2c408321ef4f79277945fb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 21 May 2025 10:45:43 +0000 Subject: [PATCH 9/9] Fix withDiagnostics format in attribute private setter test Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com> --- .../Attributes/AttributePrivateSetterTests.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/FSharp.Compiler.ComponentTests/Attributes/AttributePrivateSetterTests.fs b/tests/FSharp.Compiler.ComponentTests/Attributes/AttributePrivateSetterTests.fs index ecf2fd4ca94..0c49c01a40e 100644 --- a/tests/FSharp.Compiler.ComponentTests/Attributes/AttributePrivateSetterTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Attributes/AttributePrivateSetterTests.fs @@ -19,6 +19,6 @@ type TestClass() = class end |> compile |> shouldFail |> withDiagnostics [ - (DiagnosticLevel.Error, 3248, "Property 'ConditionString' on attribute cannot be set because the setter is private", (5, 13, 5, 41)) + (Error, 3248, Line 5, Col 13, Line 5, Col 41, "Property 'ConditionString' on attribute cannot be set because the setter is private") ] |> ignore \ No newline at end of file