diff --git a/docs/release-notes/.FSharp.Compiler.Service/8.0.300.md b/docs/release-notes/.FSharp.Compiler.Service/8.0.300.md
index 83b2c864908..6a2c4414491 100644
--- a/docs/release-notes/.FSharp.Compiler.Service/8.0.300.md
+++ b/docs/release-notes/.FSharp.Compiler.Service/8.0.300.md
@@ -16,6 +16,7 @@
* Enforce AttributeTargets on let values and functions. ([PR #16692](https://github.com/dotnet/fsharp/pull/16692))
* Enforce AttributeTargets on union case declarations. ([PR #16764](https://github.com/dotnet/fsharp/pull/16764))
* Disallow using base to invoke an abstract base method. ([Issue #13926](https://github.com/dotnet/fsharp/issues/13926), [PR #16773](https://github.com/dotnet/fsharp/pull/16773))
+* Enforce AttributeTargets on implicit constructors. ([PR #16845](https://github.com/dotnet/fsharp/pull/16845/))
* Enforce AttributeTargets on structs and classes ([PR #16790](https://github.com/dotnet/fsharp/pull/16790))
* Parser: fix pattern range for idents with trivia ([PR #16824](https://github.com/dotnet/fsharp/pull/16824))
* Fix broken code completion after a record type declaration ([PR #16813](https://github.com/dotnet/fsharp/pull/16813))
diff --git a/docs/release-notes/.Language/preview.md b/docs/release-notes/.Language/preview.md
index 4a6122e29dd..1e51f83984c 100644
--- a/docs/release-notes/.Language/preview.md
+++ b/docs/release-notes/.Language/preview.md
@@ -11,6 +11,7 @@
* Allow extension methods without type attribute work for types from imported assemblies. ([PR #16368](https://github.com/dotnet/fsharp/pull/16368))
* Enforce AttributeTargets on let values and functions. ([PR #16692](https://github.com/dotnet/fsharp/pull/16692))
* Enforce AttributeTargets on union case declarations. ([PR #16764](https://github.com/dotnet/fsharp/pull/16764))
+* Enforce AttributeTargets on implicit constructors. ([PR #16845](https://github.com/dotnet/fsharp/pull/16845/))
* Enforce AttributeTargets on structs and classes ([PR #16790](https://github.com/dotnet/fsharp/pull/16790))
### Changed
diff --git a/src/Compiler/Checking/CheckDeclarations.fs b/src/Compiler/Checking/CheckDeclarations.fs
index 88c8c7b5a72..442a21e3601 100644
--- a/src/Compiler/Checking/CheckDeclarations.fs
+++ b/src/Compiler/Checking/CheckDeclarations.fs
@@ -574,7 +574,7 @@ module TcRecdUnionAndEnumDeclarations =
type SomeUnion =
| Case1 // Compiles down to a static property
*)
- if g.langVersion.SupportsFeature(LanguageFeature.EnforceAttributeTargetsUnionCaseDeclarations) then
+ if g.langVersion.SupportsFeature(LanguageFeature.EnforceAttributeTargets) then
let target = if rfields.IsEmpty then AttributeTargets.Property else AttributeTargets.Method
TcAttributes cenv env target synAttrs
else
@@ -2927,13 +2927,13 @@ module EstablishTypeDefinitionCores =
let kind =
match kind with
| SynTypeDefnKind.Class ->
- if g.langVersion.SupportsFeature(LanguageFeature.EnforceAttributeTargetsOnStructAndClasses) then
+ if g.langVersion.SupportsFeature(LanguageFeature.EnforceAttributeTargets) then
TcAttributesWithPossibleTargets false cenv envinner AttributeTargets.Class synAttrs |> ignore
TFSharpClass
| SynTypeDefnKind.Interface -> TFSharpInterface
| SynTypeDefnKind.Delegate _ -> TFSharpDelegate (MakeSlotSig("Invoke", g.unit_ty, [], [], [], None))
| SynTypeDefnKind.Struct ->
- if g.langVersion.SupportsFeature(LanguageFeature.EnforceAttributeTargetsOnStructAndClasses) then
+ if g.langVersion.SupportsFeature(LanguageFeature.EnforceAttributeTargets) then
TcAttributesWithPossibleTargets false cenv envinner AttributeTargets.Struct synAttrs |> ignore
TFSharpStruct
| _ -> error(InternalError("should have inferred tycon kind", m))
diff --git a/src/Compiler/Checking/CheckExpressions.fs b/src/Compiler/Checking/CheckExpressions.fs
index f7e048223bf..220e4da4c82 100644
--- a/src/Compiler/Checking/CheckExpressions.fs
+++ b/src/Compiler/Checking/CheckExpressions.fs
@@ -10874,7 +10874,7 @@ and TcNormalizedBinding declKind (cenv: cenv) env tpenv overallTy safeThisValOpt
if not (isNil declaredTypars) then
errorR(Error(FSComp.SR.tcLiteralCannotHaveGenericParameters(), mBinding))
- if g.langVersion.SupportsFeature(LanguageFeature.EnforceAttributeTargetsOnFunctions) && memberFlagsOpt.IsNone && not attrs.IsEmpty then
+ if g.langVersion.SupportsFeature(LanguageFeature.EnforceAttributeTargets) && memberFlagsOpt.IsNone && not attrs.IsEmpty then
TcAttributeTargetsOnLetBindings cenv env attrs overallPatTy overallExprTy (not declaredTypars.IsEmpty)
CheckedBindingInfo(inlineFlag, valAttribs, xmlDoc, tcPatPhase2, explicitTyparInfo, nameToPrelimValSchemeMap, rhsExprChecked, argAndRetAttribs, overallPatTy, mBinding, debugPoint, isCompGen, literalValue, isFixed), tpenv
diff --git a/src/Compiler/Checking/CheckIncrementalClasses.fs b/src/Compiler/Checking/CheckIncrementalClasses.fs
index 1424a8ef7f3..014e3144717 100644
--- a/src/Compiler/Checking/CheckIncrementalClasses.fs
+++ b/src/Compiler/Checking/CheckIncrementalClasses.fs
@@ -5,6 +5,7 @@ module internal FSharp.Compiler.CheckIncrementalClasses
open System
open FSharp.Compiler.Diagnostics
+open FSharp.Compiler.Features
open Internal.Utilities.Collections
open Internal.Utilities.Library
open Internal.Utilities.Library.Extras
@@ -173,7 +174,13 @@ let TcImplicitCtorInfo_Phase2A(cenv: cenv, env, tpenv, tcref: TyconRef, vis, att
let ctorTy = mkFunTy g argTy objTy
// NOTE: no attributes can currently be specified for the implicit constructor
- let attribs = TcAttributes cenv env (AttributeTargets.Constructor ||| AttributeTargets.Method) attrs
+ let attribs =
+ // Implicit constructors can only target AttributeTargets.Constructor
+ if g.langVersion.SupportsFeature(LanguageFeature.EnforceAttributeTargets) then
+ TcAttributes cenv env AttributeTargets.Constructor attrs
+ else
+ TcAttributes cenv env (AttributeTargets.Constructor ||| AttributeTargets.Method) attrs
+
let memberFlags = CtorMemberFlags
let synArgInfos = List.map (SynInfo.InferSynArgInfoFromSimplePat []) spats
diff --git a/src/Compiler/FSComp.txt b/src/Compiler/FSComp.txt
index eda76095bb2..a716fe7204c 100644
--- a/src/Compiler/FSComp.txt
+++ b/src/Compiler/FSComp.txt
@@ -1593,10 +1593,8 @@ featureWarningIndexedPropertiesGetSetSameType,"Indexed properties getter and set
featureChkTailCallAttrOnNonRec,"Raises warnings if the 'TailCall' attribute is used on non-recursive functions."
featureUnionIsPropertiesVisible,"Union case test properties"
featureBooleanReturningAndReturnTypeDirectedPartialActivePattern,"Boolean-returning and return-type-directed partial active patterns"
-featureEnforceAttributeTargetsOnFunctions,"Enforce AttributeTargets on functions"
-featureEnforceAttributeTargetsUnionCaseDeclarations,"Enforce AttributeTargets on union case declarations"
+featureEnforceAttributeTargets,"Enforce AttributeTargets"
featureLowerInterpolatedStringToConcat,"Optimizes interpolated strings in certain cases, by lowering to concatenation"
-featureEnforceAttributeTargetsOnStructAndClasses,"Enforce AttributeTargets on structs and classes"
featureLowerIntegralRangesToFastLoops,"Optimizes certain uses of the integral range (..) and range-step (.. ..) operators to fast while-loops."
3354,tcNotAFunctionButIndexerNamedIndexingNotYetEnabled,"This value supports indexing, e.g. '%s.[index]'. The syntax '%s[index]' requires /langversion:preview. See https://aka.ms/fsharp-index-notation."
3354,tcNotAFunctionButIndexerIndexingNotYetEnabled,"This expression supports indexing, e.g. 'expr.[index]'. The syntax 'expr[index]' requires /langversion:preview. See https://aka.ms/fsharp-index-notation."
diff --git a/src/Compiler/Facilities/LanguageFeatures.fs b/src/Compiler/Facilities/LanguageFeatures.fs
index ac48fc40b91..2ce326d9c75 100644
--- a/src/Compiler/Facilities/LanguageFeatures.fs
+++ b/src/Compiler/Facilities/LanguageFeatures.fs
@@ -85,10 +85,8 @@ type LanguageFeature =
| WarningIndexedPropertiesGetSetSameType
| WarningWhenTailCallAttrOnNonRec
| BooleanReturningAndReturnTypeDirectedPartialActivePattern
- | EnforceAttributeTargetsOnFunctions
- | EnforceAttributeTargetsUnionCaseDeclarations
+ | EnforceAttributeTargets
| LowerInterpolatedStringToConcat
- | EnforceAttributeTargetsOnStructAndClasses
| LowerIntegralRangesToFastLoops
/// LanguageVersion management
@@ -202,10 +200,8 @@ type LanguageVersion(versionText) =
LanguageFeature.WarningWhenTailCallAttrOnNonRec, previewVersion
LanguageFeature.UnionIsPropertiesVisible, previewVersion
LanguageFeature.BooleanReturningAndReturnTypeDirectedPartialActivePattern, previewVersion
- LanguageFeature.EnforceAttributeTargetsOnFunctions, previewVersion
- LanguageFeature.EnforceAttributeTargetsUnionCaseDeclarations, previewVersion
+ LanguageFeature.EnforceAttributeTargets, previewVersion
LanguageFeature.LowerInterpolatedStringToConcat, previewVersion
- LanguageFeature.EnforceAttributeTargetsOnStructAndClasses, previewVersion
LanguageFeature.LowerIntegralRangesToFastLoops, previewVersion
]
@@ -350,10 +346,8 @@ type LanguageVersion(versionText) =
| LanguageFeature.WarningWhenTailCallAttrOnNonRec -> FSComp.SR.featureChkTailCallAttrOnNonRec ()
| LanguageFeature.BooleanReturningAndReturnTypeDirectedPartialActivePattern ->
FSComp.SR.featureBooleanReturningAndReturnTypeDirectedPartialActivePattern ()
- | LanguageFeature.EnforceAttributeTargetsOnFunctions -> FSComp.SR.featureEnforceAttributeTargetsOnFunctions ()
- | LanguageFeature.EnforceAttributeTargetsUnionCaseDeclarations -> FSComp.SR.featureEnforceAttributeTargetsUnionCaseDeclarations ()
+ | LanguageFeature.EnforceAttributeTargets -> FSComp.SR.featureEnforceAttributeTargets ()
| LanguageFeature.LowerInterpolatedStringToConcat -> FSComp.SR.featureLowerInterpolatedStringToConcat ()
- | LanguageFeature.EnforceAttributeTargetsOnStructAndClasses -> FSComp.SR.featureEnforceAttributeTargetsOnStructAndClasses ()
| LanguageFeature.LowerIntegralRangesToFastLoops -> FSComp.SR.featureLowerIntegralRangesToFastLoops ()
/// Get a version string associated with the given feature.
diff --git a/src/Compiler/Facilities/LanguageFeatures.fsi b/src/Compiler/Facilities/LanguageFeatures.fsi
index 80a41c8ce54..f166975ec42 100644
--- a/src/Compiler/Facilities/LanguageFeatures.fsi
+++ b/src/Compiler/Facilities/LanguageFeatures.fsi
@@ -76,10 +76,8 @@ type LanguageFeature =
| WarningIndexedPropertiesGetSetSameType
| WarningWhenTailCallAttrOnNonRec
| BooleanReturningAndReturnTypeDirectedPartialActivePattern
- | EnforceAttributeTargetsOnFunctions
- | EnforceAttributeTargetsUnionCaseDeclarations
+ | EnforceAttributeTargets
| LowerInterpolatedStringToConcat
- | EnforceAttributeTargetsOnStructAndClasses
| LowerIntegralRangesToFastLoops
/// LanguageVersion management
diff --git a/src/Compiler/xlf/FSComp.txt.cs.xlf b/src/Compiler/xlf/FSComp.txt.cs.xlf
index 29a83a20d98..bb150927db9 100644
--- a/src/Compiler/xlf/FSComp.txt.cs.xlf
+++ b/src/Compiler/xlf/FSComp.txt.cs.xlf
@@ -292,19 +292,9 @@
literál float32 bez tečky
-
- Enforce AttributeTargets on functions
- Enforce AttributeTargets on functions
-
-
-
- Enforce AttributeTargets on structs and classes
- Enforce AttributeTargets on structs and classes
-
-
-
- Enforce AttributeTargets on union case declarations
- Enforce AttributeTargets on union case declarations
+
+ Enforce AttributeTargets
+ Enforce AttributeTargets
diff --git a/src/Compiler/xlf/FSComp.txt.de.xlf b/src/Compiler/xlf/FSComp.txt.de.xlf
index e28b1177ea9..8bde903616f 100644
--- a/src/Compiler/xlf/FSComp.txt.de.xlf
+++ b/src/Compiler/xlf/FSComp.txt.de.xlf
@@ -292,19 +292,9 @@
punktloses float32-Literal
-
- Enforce AttributeTargets on functions
- Enforce AttributeTargets on functions
-
-
-
- Enforce AttributeTargets on structs and classes
- Enforce AttributeTargets on structs and classes
-
-
-
- Enforce AttributeTargets on union case declarations
- Enforce AttributeTargets on union case declarations
+
+ Enforce AttributeTargets
+ Enforce AttributeTargets
diff --git a/src/Compiler/xlf/FSComp.txt.es.xlf b/src/Compiler/xlf/FSComp.txt.es.xlf
index d86bb178a0d..ff17bae30d1 100644
--- a/src/Compiler/xlf/FSComp.txt.es.xlf
+++ b/src/Compiler/xlf/FSComp.txt.es.xlf
@@ -292,19 +292,9 @@
literal float32 sin punto
-
- Enforce AttributeTargets on functions
- Enforce AttributeTargets on functions
-
-
-
- Enforce AttributeTargets on structs and classes
- Enforce AttributeTargets on structs and classes
-
-
-
- Enforce AttributeTargets on union case declarations
- Enforce AttributeTargets on union case declarations
+
+ Enforce AttributeTargets
+ Enforce AttributeTargets
diff --git a/src/Compiler/xlf/FSComp.txt.fr.xlf b/src/Compiler/xlf/FSComp.txt.fr.xlf
index e9cefd5803b..2006cd4a0e1 100644
--- a/src/Compiler/xlf/FSComp.txt.fr.xlf
+++ b/src/Compiler/xlf/FSComp.txt.fr.xlf
@@ -292,19 +292,9 @@
littéral float32 sans point
-
- Enforce AttributeTargets on functions
- Enforce AttributeTargets on functions
-
-
-
- Enforce AttributeTargets on structs and classes
- Enforce AttributeTargets on structs and classes
-
-
-
- Enforce AttributeTargets on union case declarations
- Enforce AttributeTargets on union case declarations
+
+ Enforce AttributeTargets
+ Enforce AttributeTargets
diff --git a/src/Compiler/xlf/FSComp.txt.it.xlf b/src/Compiler/xlf/FSComp.txt.it.xlf
index 539502d9670..70c046f57d7 100644
--- a/src/Compiler/xlf/FSComp.txt.it.xlf
+++ b/src/Compiler/xlf/FSComp.txt.it.xlf
@@ -292,19 +292,9 @@
valore letterale float32 senza punti
-
- Enforce AttributeTargets on functions
- Enforce AttributeTargets on functions
-
-
-
- Enforce AttributeTargets on structs and classes
- Enforce AttributeTargets on structs and classes
-
-
-
- Enforce AttributeTargets on union case declarations
- Enforce AttributeTargets on union case declarations
+
+ Enforce AttributeTargets
+ Enforce AttributeTargets
diff --git a/src/Compiler/xlf/FSComp.txt.ja.xlf b/src/Compiler/xlf/FSComp.txt.ja.xlf
index a364c7953d6..97d052f9bc4 100644
--- a/src/Compiler/xlf/FSComp.txt.ja.xlf
+++ b/src/Compiler/xlf/FSComp.txt.ja.xlf
@@ -292,19 +292,9 @@
ドットなしの float32 リテラル
-
- Enforce AttributeTargets on functions
- Enforce AttributeTargets on functions
-
-
-
- Enforce AttributeTargets on structs and classes
- Enforce AttributeTargets on structs and classes
-
-
-
- Enforce AttributeTargets on union case declarations
- Enforce AttributeTargets on union case declarations
+
+ Enforce AttributeTargets
+ Enforce AttributeTargets
diff --git a/src/Compiler/xlf/FSComp.txt.ko.xlf b/src/Compiler/xlf/FSComp.txt.ko.xlf
index 96768306e24..edbbbc1f0ab 100644
--- a/src/Compiler/xlf/FSComp.txt.ko.xlf
+++ b/src/Compiler/xlf/FSComp.txt.ko.xlf
@@ -292,19 +292,9 @@
점이 없는 float32 리터럴
-
- Enforce AttributeTargets on functions
- Enforce AttributeTargets on functions
-
-
-
- Enforce AttributeTargets on structs and classes
- Enforce AttributeTargets on structs and classes
-
-
-
- Enforce AttributeTargets on union case declarations
- Enforce AttributeTargets on union case declarations
+
+ Enforce AttributeTargets
+ Enforce AttributeTargets
diff --git a/src/Compiler/xlf/FSComp.txt.pl.xlf b/src/Compiler/xlf/FSComp.txt.pl.xlf
index 22210fdee9c..4960765fa1a 100644
--- a/src/Compiler/xlf/FSComp.txt.pl.xlf
+++ b/src/Compiler/xlf/FSComp.txt.pl.xlf
@@ -292,19 +292,9 @@
bezkropkowy literał float32
-
- Enforce AttributeTargets on functions
- Enforce AttributeTargets on functions
-
-
-
- Enforce AttributeTargets on structs and classes
- Enforce AttributeTargets on structs and classes
-
-
-
- Enforce AttributeTargets on union case declarations
- Enforce AttributeTargets on union case declarations
+
+ Enforce AttributeTargets
+ Enforce AttributeTargets
diff --git a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf
index 8449413e457..8ea97b7b5b1 100644
--- a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf
+++ b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf
@@ -292,19 +292,9 @@
literal float32 sem ponto
-
- Enforce AttributeTargets on functions
- Enforce AttributeTargets on functions
-
-
-
- Enforce AttributeTargets on structs and classes
- Enforce AttributeTargets on structs and classes
-
-
-
- Enforce AttributeTargets on union case declarations
- Enforce AttributeTargets on union case declarations
+
+ Enforce AttributeTargets
+ Enforce AttributeTargets
diff --git a/src/Compiler/xlf/FSComp.txt.ru.xlf b/src/Compiler/xlf/FSComp.txt.ru.xlf
index 41129014c1b..8793d14fbfd 100644
--- a/src/Compiler/xlf/FSComp.txt.ru.xlf
+++ b/src/Compiler/xlf/FSComp.txt.ru.xlf
@@ -292,19 +292,9 @@
литерал float32 без точки
-
- Enforce AttributeTargets on functions
- Enforce AttributeTargets on functions
-
-
-
- Enforce AttributeTargets on structs and classes
- Enforce AttributeTargets on structs and classes
-
-
-
- Enforce AttributeTargets on union case declarations
- Enforce AttributeTargets on union case declarations
+
+ Enforce AttributeTargets
+ Enforce AttributeTargets
diff --git a/src/Compiler/xlf/FSComp.txt.tr.xlf b/src/Compiler/xlf/FSComp.txt.tr.xlf
index 659004ddc36..4261665d83e 100644
--- a/src/Compiler/xlf/FSComp.txt.tr.xlf
+++ b/src/Compiler/xlf/FSComp.txt.tr.xlf
@@ -292,19 +292,9 @@
noktasız float32 sabit değeri
-
- Enforce AttributeTargets on functions
- Enforce AttributeTargets on functions
-
-
-
- Enforce AttributeTargets on structs and classes
- Enforce AttributeTargets on structs and classes
-
-
-
- Enforce AttributeTargets on union case declarations
- Enforce AttributeTargets on union case declarations
+
+ Enforce AttributeTargets
+ Enforce AttributeTargets
diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf
index 1b8716f794d..eac9a233793 100644
--- a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf
+++ b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf
@@ -292,19 +292,9 @@
无点 float32 文本
-
- Enforce AttributeTargets on functions
- Enforce AttributeTargets on functions
-
-
-
- Enforce AttributeTargets on structs and classes
- Enforce AttributeTargets on structs and classes
-
-
-
- Enforce AttributeTargets on union case declarations
- Enforce AttributeTargets on union case declarations
+
+ Enforce AttributeTargets
+ Enforce AttributeTargets
diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf
index 43da50f6960..e0f3f70149c 100644
--- a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf
+++ b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf
@@ -292,19 +292,9 @@
無點號的 float32 常值
-
- Enforce AttributeTargets on functions
- Enforce AttributeTargets on functions
-
-
-
- Enforce AttributeTargets on structs and classes
- Enforce AttributeTargets on structs and classes
-
-
-
- Enforce AttributeTargets on union case declarations
- Enforce AttributeTargets on union case declarations
+
+ Enforce AttributeTargets
+ Enforce AttributeTargets
diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/AttributeUsage.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/AttributeUsage.fs
index 652755fd5cd..d34f6d797c1 100644
--- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/AttributeUsage.fs
+++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/AttributeUsage.fs
@@ -481,7 +481,6 @@ module CustomAttributes_AttributeUsage =
(Error 842, Line 15, Col 5, Line 15, Col 25, "This attribute is not valid for use on this language element")
]
-
// SOURCE=E_AttributeTargetIsProperty01.fs # E_AttributeTargetIsField03.fs
[]
let ``E_AttributeTargetIsProperty01_fs`` compilation =
@@ -499,4 +498,25 @@ module CustomAttributes_AttributeUsage =
|> withDiagnostics [
(Error 842, Line 14, Col 5, Line 14, Col 18, "This attribute is not valid for use on this language element")
(Error 842, Line 15, Col 5, Line 15, Col 25, "This attribute is not valid for use on this language element")
+ ]
+
+ // SOURCE=E_AttributeTargetIsCtor01.fs # E_AttributeTargetIsCtor01.fs
+ []
+ let ``E_AttributeTargetIsCtor01_fs`` compilation =
+ compilation
+ |> verifyCompile
+ |> shouldSucceed
+
+ // SOURCE=E_AttributeTargetIsCtor01.fs # E_AttributeTargetIsCtor01.fs
+ []
+ let ``E_AttributeTargetIsCtor01_fs preview`` compilation =
+ compilation
+ |> withLangVersionPreview
+ |> verifyCompile
+ |> shouldFail
+ |> withDiagnostics [
+ (Error 842, Line 9, Col 15, Line 9, Col 27, "This attribute is not valid for use on this language element")
+ (Error 842, Line 11, Col 16, Line 11, Col 28, "This attribute is not valid for use on this language element")
+ (Error 842, Line 14, Col 15, Line 14, Col 27, "This attribute is not valid for use on this language element")
+ (Error 842, Line 17, Col 16, Line 17, Col 28, "This attribute is not valid for use on this language element")
]
\ No newline at end of file
diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/E_AttributeTargetIsCtor01.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/E_AttributeTargetIsCtor01.fs
new file mode 100644
index 00000000000..6112b952fbf
--- /dev/null
+++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/E_AttributeTargetIsCtor01.fs
@@ -0,0 +1,17 @@
+open System
+
+open System
+
+[]
+type CustomMethodAttribute() =
+ inherit Attribute()
+
+type Class1 [] () = class end
+
+type Struct1 [](c: int) = struct end
+
+[]
+type Class2 []() = class end
+
+[]
+type Struct2 [](c: int) = struct end