diff --git a/src/Compiler/Checking/Expressions/CheckExpressions.fs b/src/Compiler/Checking/Expressions/CheckExpressions.fs
index 567e1da0310..34dc4205fea 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.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 1d7e9d6499a..6868672bf60 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"
+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/src/Compiler/xlf/FSComp.txt.cs.xlf b/src/Compiler/xlf/FSComp.txt.cs.xlf
index caa825a8245..8982b80ff6c 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 '{0}' on attribute cannot be set because the setter is private
+ Property '{0}' on attribute cannot be set because the setter is private
+
+ This property or field was not found on this custom attribute typeTato 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..51550f364c0 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 '{0}' on attribute cannot be set because the setter is private
+ Property '{0}' on attribute cannot be set because the setter is private
+
+ This property or field was not found on this custom attribute typeDiese 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..23c47acecf3 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 '{0}' on attribute cannot be set because the setter is private
+ Property '{0}' on attribute cannot be set because the setter is private
+
+ This property or field was not found on this custom attribute typeNo 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..455b2447c8c 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 '{0}' on attribute cannot be set because the setter is private
+ Property '{0}' on attribute cannot be set because the setter is private
+
+ This property or field was not found on this custom attribute typeImpossible 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..33ae7f4ece3 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 '{0}' on attribute cannot be set because the setter is private
+ Property '{0}' on attribute cannot be set because the setter is private
+
+ This property or field was not found on this custom attribute typeLa 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..b034bb1004d 100644
--- a/src/Compiler/xlf/FSComp.txt.ja.xlf
+++ b/src/Compiler/xlf/FSComp.txt.ja.xlf
@@ -5147,6 +5147,11 @@
このプロパティは設定できません
+
+ Property '{0}' on attribute cannot be set because the setter is private
+ Property '{0}' 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..1d439c35b86 100644
--- a/src/Compiler/xlf/FSComp.txt.ko.xlf
+++ b/src/Compiler/xlf/FSComp.txt.ko.xlf
@@ -5147,6 +5147,11 @@
이 속성은 설정할 수 없습니다.
+
+ Property '{0}' on attribute cannot be set because the setter is private
+ Property '{0}' 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..e91640c2673 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 '{0}' on attribute cannot be set because the setter is private
+ Property '{0}' on attribute cannot be set because the setter is private
+
+ This property or field was not found on this custom attribute typeNie 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..82e5411199a 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 '{0}' on attribute cannot be set because the setter is private
+ Property '{0}' on attribute cannot be set because the setter is private
+
+ This property or field was not found on this custom attribute typeEsta 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..6503bb5d445 100644
--- a/src/Compiler/xlf/FSComp.txt.ru.xlf
+++ b/src/Compiler/xlf/FSComp.txt.ru.xlf
@@ -5147,6 +5147,11 @@
Это свойство задать нельзя
+
+ Property '{0}' on attribute cannot be set because the setter is private
+ Property '{0}' 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..6c793f05567 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 '{0}' on attribute cannot be set because the setter is private
+ Property '{0}' on attribute cannot be set because the setter is private
+
+ This property or field was not found on this custom attribute typeBu ö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..12199c5cdd1 100644
--- a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf
+++ b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf
@@ -5147,6 +5147,11 @@
无法设置此属性
+
+ Property '{0}' on attribute cannot be set because the setter is private
+ Property '{0}' 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..692c4cd9928 100644
--- a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf
+++ b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf
@@ -5147,6 +5147,11 @@
無法設定這個屬性
+
+ Property '{0}' on attribute cannot be set because the setter is private
+ Property '{0}' 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/tests/FSharp.Compiler.ComponentTests/Attributes/AttributePrivateSetterTests.fs b/tests/FSharp.Compiler.ComponentTests/Attributes/AttributePrivateSetterTests.fs
new file mode 100644
index 00000000000..0c49c01a40e
--- /dev/null
+++ b/tests/FSharp.Compiler.ComponentTests/Attributes/AttributePrivateSetterTests.fs
@@ -0,0 +1,24 @@
+module FSharp.Compiler.ComponentTests.AttributePrivateSetter
+
+open Xunit
+open FSharp.Test.Compiler
+
+[]
+let ``Compiler disallows setting a value of a private property on attribute``() =
+ // Arrange
+ let mainCode = """
+module AttributeTest
+
+open System.Diagnostics
+
+[]
+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")
+ ]
+ |> 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 @@
+