From 4720fac4f4d2cecd148630ced87d705662d5a884 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Tue, 21 May 2024 14:22:56 +0100 Subject: [PATCH 01/15] Initial test --- .../E_AttributeTargetIsClass02.fs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/E_AttributeTargetIsClass02.fs diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/E_AttributeTargetIsClass02.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/E_AttributeTargetIsClass02.fs new file mode 100644 index 00000000000..4b0089ffd5d --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/E_AttributeTargetIsClass02.fs @@ -0,0 +1,20 @@ +open System + +[] +type InterfaceTargetAttribute() = + inherit Attribute() + +[] +type StructTargetAttribute() = + inherit Attribute() + +[] // Should this be allowed? +[] // Should this be allowed? +type Record = { Prop: string } + + +[] // Should this be allowed? +[]// Should this be allowed? +[] +[] +type StructRecord = { Prop: string } \ No newline at end of file From e14eb379400f545d8d0a07d1633353396028a08f Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Tue, 21 May 2024 17:03:58 +0100 Subject: [PATCH 02/15] Update record check for targets --- src/Compiler/Checking/CheckDeclarations.fs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Compiler/Checking/CheckDeclarations.fs b/src/Compiler/Checking/CheckDeclarations.fs index be083e74871..3c7a53f4443 100644 --- a/src/Compiler/Checking/CheckDeclarations.fs +++ b/src/Compiler/Checking/CheckDeclarations.fs @@ -2840,6 +2840,7 @@ module EstablishTypeDefinitionCores = // Allow failure of constructor resolution because Vals for members in the same recursive group are not yet available let attrs, getFinalAttrs = TcAttributesCanFail cenv envinner AttributeTargets.TyconDecl synAttrs let hasMeasureAttr = HasFSharpAttribute g g.attrib_MeasureAttribute attrs + let hasStructAttr = HasFSharpAttribute g g.attrib_StructAttribute attrs let isStructRecordOrUnionType = match synTyconRepr with @@ -2896,6 +2897,12 @@ module EstablishTypeDefinitionCores = // Run InferTyconKind to raise errors on inconsistent attribute sets InferTyconKind g (SynTypeDefnKind.Record, attrs, [], [], inSig, true, m) |> ignore + + if g.langVersion.SupportsFeature(LanguageFeature.EnforceAttributeTargets) then + if hasStructAttr then + TcAttributesWithPossibleTargets false cenv envinner AttributeTargets.Struct synAttrs |> ignore + else + TcAttributesWithPossibleTargets false cenv envinner AttributeTargets.Class synAttrs |> ignore // Note: the table of record fields is initially empty TFSharpTyconRepr (Construct.NewEmptyFSharpTyconData TFSharpRecord) From f0cd5d542801cd3f5408d32a3890cd25ac160e55 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Tue, 21 May 2024 21:45:58 +0100 Subject: [PATCH 03/15] More tests --- src/Compiler/Checking/CheckDeclarations.fs | 6 +++++- .../AttributeUsage/AttributeTargetsIsClass.fs | 8 +++++++ .../AttributeUsage/AttributeUsage.fs | 21 +++++++++++++++++++ .../E_AttributeTargetIsClass02.fs | 15 +++++++------ 4 files changed, 43 insertions(+), 7 deletions(-) diff --git a/src/Compiler/Checking/CheckDeclarations.fs b/src/Compiler/Checking/CheckDeclarations.fs index 3c7a53f4443..2c0718a8a5c 100644 --- a/src/Compiler/Checking/CheckDeclarations.fs +++ b/src/Compiler/Checking/CheckDeclarations.fs @@ -2841,6 +2841,7 @@ module EstablishTypeDefinitionCores = let attrs, getFinalAttrs = TcAttributesCanFail cenv envinner AttributeTargets.TyconDecl synAttrs let hasMeasureAttr = HasFSharpAttribute g g.attrib_MeasureAttribute attrs let hasStructAttr = HasFSharpAttribute g g.attrib_StructAttribute attrs + let hasRQAAttr = HasFSharpAttribute g g.attrib_RequireQualifiedAccessAttribute attrs let isStructRecordOrUnionType = match synTyconRepr with @@ -2900,7 +2901,10 @@ module EstablishTypeDefinitionCores = if g.langVersion.SupportsFeature(LanguageFeature.EnforceAttributeTargets) then if hasStructAttr then - TcAttributesWithPossibleTargets false cenv envinner AttributeTargets.Struct synAttrs |> ignore + if hasRQAAttr then + TcAttributesWithPossibleTargets false cenv envinner (AttributeTargets.Class ||| AttributeTargets.Struct) synAttrs |> ignore + else + TcAttributesWithPossibleTargets false cenv envinner AttributeTargets.Struct synAttrs |> ignore else TcAttributesWithPossibleTargets false cenv envinner AttributeTargets.Class synAttrs |> ignore diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/AttributeTargetsIsClass.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/AttributeTargetsIsClass.fs index 8f587dcf099..a2728dace4e 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/AttributeTargetsIsClass.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/AttributeTargetsIsClass.fs @@ -24,3 +24,11 @@ type SemanticClassificationItem = type ILTableName(idx: int) = member __.Index = idx static member FromIndex n = ILTableName n + +[] +[] +type Record = { Prop: string } + +[] +[] +type StructRecord = { Prop: string } 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 1e68d9d5ee8..1e5b49a1d83 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/AttributeUsage.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/AttributeUsage.fs @@ -638,4 +638,25 @@ type InterruptibleLazy<'T> private (valueFactory: unit -> 'T) = (Error 842, Line 14, Col 3, Line 14, Col 15, "This attribute is not valid for use on this language element") (Error 842, Line 18, Col 3, Line 18, Col 14, "This attribute is not valid for use on this language element") (Error 842, Line 19, Col 3, Line 19, Col 15, "This attribute is not valid for use on this language element") + ] + + // SOURCE= E_AttributeTargetIsClass02.fs # E_AttributeTargetIsClass02.fs + [] + let ``E_AttributeTargetIsClass02_fs`` compilation = + compilation + |> verifyCompile + |> shouldSucceed + + // SOURCE=E_AttributeTargetIsClass02.fs # E_AttributeTargetIsClass02.fs + [] + let ``E_AttributeTargetIsClass02_fs preview`` compilation = + compilation + |> withLangVersionPreview + |> verifyCompile + |> shouldFail + |> withDiagnostics [ + (Error 842, Line 15, Col 3, Line 15, Col 18, "This attribute is not valid for use on this language element") + (Error 842, Line 16, Col 3, Line 16, Col 15, "This attribute is not valid for use on this language element") + (Error 842, Line 20, Col 3, Line 20, Col 14, "This attribute is not valid for use on this language element") + (Error 842, Line 21, Col 3, Line 21, Col 18, "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_AttributeTargetIsClass02.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/E_AttributeTargetIsClass02.fs index 4b0089ffd5d..56712514253 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/E_AttributeTargetIsClass02.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/E_AttributeTargetIsClass02.fs @@ -1,5 +1,9 @@ open System +[] +type ClassTargetAttribute() = + inherit Attribute() + [] type InterfaceTargetAttribute() = inherit Attribute() @@ -8,13 +12,12 @@ type InterfaceTargetAttribute() = type StructTargetAttribute() = inherit Attribute() -[] // Should this be allowed? -[] // Should this be allowed? +[] +[] +[] type Record = { Prop: string } - -[] // Should this be allowed? -[]// Should this be allowed? -[] +[] +[] [] type StructRecord = { Prop: string } \ No newline at end of file From ffb497bbb4cbbf42fa6697f75b1dafd2fe9e997d Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Wed, 22 May 2024 22:07:11 +0100 Subject: [PATCH 04/15] Check Record fields --- src/Compiler/Checking/CheckDeclarations.fs | 7 ++++++- .../AttributeUsage/AttributeTargetsIsProperty.fs | 13 +++++++++++++ .../AttributeUsage/AttributeUsage.fs | 3 +++ .../E_AttributeTargetIsProperty01.fs | 15 ++++++++++++++- 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/Compiler/Checking/CheckDeclarations.fs b/src/Compiler/Checking/CheckDeclarations.fs index 2c0718a8a5c..bfe6592d012 100644 --- a/src/Compiler/Checking/CheckDeclarations.fs +++ b/src/Compiler/Checking/CheckDeclarations.fs @@ -427,7 +427,12 @@ module TcRecdUnionAndEnumDeclarations = let TcFieldDecl (cenv: cenv) env parent isIncrClass tpenv (isStatic, synAttrs, id: Ident, nameGenerated, ty, isMutable, xmldoc, vis) = let g = cenv.g let m = id.idRange - let attrs, _ = TcAttributesWithPossibleTargets false cenv env AttributeTargets.FieldDecl synAttrs + let attrs, _ = + if g.langVersion.SupportsFeature(LanguageFeature.EnforceAttributeTargets) then + TcAttributesWithPossibleTargets false cenv env AttributeTargets.Property synAttrs + else + TcAttributesWithPossibleTargets false cenv env AttributeTargets.FieldDecl synAttrs + let attrsForProperty, attrsForField = attrs |> List.partition (fun (attrTargets, _) -> (attrTargets &&& AttributeTargets.Property) <> enum 0) let attrsForProperty = (List.map snd attrsForProperty) let attrsForField = (List.map snd attrsForField) diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/AttributeTargetsIsProperty.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/AttributeTargetsIsProperty.fs index 42c94f1e474..212a78960d5 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/AttributeTargetsIsProperty.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/AttributeTargetsIsProperty.fs @@ -8,3 +8,16 @@ type PropertyLevelAttribute() = type U = | [] A | [] B + +[] +type Name(x: string) = + inherit Attribute() + member _.value = x + +type User = + { [] + Id: int + [] + Email: string + [] + OrganizationId: option } \ No newline at end of file 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 1e5b49a1d83..2a2dc2f63af 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/AttributeUsage.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/AttributeUsage.fs @@ -497,6 +497,9 @@ 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") + (Error 842, Line 23, Col 9, Line 23, Col 19, "This attribute is not valid for use on this language element") + (Error 842, Line 25, Col 9, Line 25, Col 22, "This attribute is not valid for use on this language element") + (Error 842, Line 27, Col 9, Line 27, Col 32, "This attribute is not valid for use on this language element") ] // SOURCE=E_AttributeTargetIsCtor01.fs # E_AttributeTargetIsCtor01.fs diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/E_AttributeTargetIsProperty01.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/E_AttributeTargetIsProperty01.fs index 4627c3680dd..a4ff3eae643 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/E_AttributeTargetIsProperty01.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/E_AttributeTargetIsProperty01.fs @@ -12,4 +12,17 @@ type PropertyOrFieldLevelAttribute() = type SomeUnion = | [] Case1 of int // Should fail -| [] Case2 of int // Should fail \ No newline at end of file +| [] Case2 of int // Should fail + +[] +type Name(x: string) = + inherit Attribute() + member _.value = x + +type User = + { [] + Id: int + [] + Email: string + [] + OrganizationId: option } \ No newline at end of file From 669ee19825f0bdf4e3c0c70014a75ff55a2c1db9 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Wed, 22 May 2024 22:07:23 +0100 Subject: [PATCH 05/15] release notes --- docs/release-notes/.FSharp.Compiler.Service/8.0.400.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/release-notes/.FSharp.Compiler.Service/8.0.400.md b/docs/release-notes/.FSharp.Compiler.Service/8.0.400.md index bccd5a0d762..a130020cb7d 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/8.0.400.md +++ b/docs/release-notes/.FSharp.Compiler.Service/8.0.400.md @@ -1,5 +1,6 @@ ### Fixed +* Enforce `AttributeTargets` on records. ([PR #17207](https://github.com/dotnet/fsharp/pull/17207)) * Error for partial implementation of interface with static and non-static abstract members. ([Issue #17138](https://github.com/dotnet/fsharp/issues/17138), [PR #17160](https://github.com/dotnet/fsharp/pull/17160)) * Optimize simple mappings with preludes in computed collections. ([PR #17067](https://github.com/dotnet/fsharp/pull/17067)) * Improve error reporting for abstract members when used in classes. ([PR #17063](https://github.com/dotnet/fsharp/pull/17063)) From d43956fe7112a5d696d5abffc5c057da4dd3567a Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Wed, 22 May 2024 22:57:16 +0100 Subject: [PATCH 06/15] Extend DefaultValueAttribute to use AttributeTargets.Property --- src/FSharp.Core/prim-types.fs | 2 +- src/FSharp.Core/prim-types.fsi | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/FSharp.Core/prim-types.fs b/src/FSharp.Core/prim-types.fs index 556fb1bcde5..1a695d92449 100644 --- a/src/FSharp.Core/prim-types.fs +++ b/src/FSharp.Core/prim-types.fs @@ -110,7 +110,7 @@ namespace Microsoft.FSharp.Core inherit Attribute() member _.Value = value - [] + [] [] type DefaultValueAttribute(check:bool) = inherit Attribute() diff --git a/src/FSharp.Core/prim-types.fsi b/src/FSharp.Core/prim-types.fsi index dee677aac31..f8585751f1f 100644 --- a/src/FSharp.Core/prim-types.fsi +++ b/src/FSharp.Core/prim-types.fsi @@ -524,7 +524,7 @@ namespace Microsoft.FSharp.Core /// /// /// Attributes - [] + [] [] type DefaultValueAttribute = inherit Attribute From cd582b6180afa3f6d495cf60cc4e1b6a710ebd26 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Thu, 23 May 2024 11:40:11 +0100 Subject: [PATCH 07/15] revert DefaultValueAttribute changes --- src/FSharp.Core/prim-types.fs | 2 +- src/FSharp.Core/prim-types.fsi | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/FSharp.Core/prim-types.fs b/src/FSharp.Core/prim-types.fs index 1a695d92449..556fb1bcde5 100644 --- a/src/FSharp.Core/prim-types.fs +++ b/src/FSharp.Core/prim-types.fs @@ -110,7 +110,7 @@ namespace Microsoft.FSharp.Core inherit Attribute() member _.Value = value - [] + [] [] type DefaultValueAttribute(check:bool) = inherit Attribute() diff --git a/src/FSharp.Core/prim-types.fsi b/src/FSharp.Core/prim-types.fsi index f8585751f1f..dee677aac31 100644 --- a/src/FSharp.Core/prim-types.fsi +++ b/src/FSharp.Core/prim-types.fsi @@ -524,7 +524,7 @@ namespace Microsoft.FSharp.Core /// /// /// Attributes - [] + [] [] type DefaultValueAttribute = inherit Attribute From 74e1342728375003e9d956872dad580e78de0164 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Thu, 23 May 2024 11:40:41 +0100 Subject: [PATCH 08/15] TcFieldDecl --- src/Compiler/Checking/CheckDeclarations.fs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Compiler/Checking/CheckDeclarations.fs b/src/Compiler/Checking/CheckDeclarations.fs index bfe6592d012..2105038c79f 100644 --- a/src/Compiler/Checking/CheckDeclarations.fs +++ b/src/Compiler/Checking/CheckDeclarations.fs @@ -427,11 +427,7 @@ module TcRecdUnionAndEnumDeclarations = let TcFieldDecl (cenv: cenv) env parent isIncrClass tpenv (isStatic, synAttrs, id: Ident, nameGenerated, ty, isMutable, xmldoc, vis) = let g = cenv.g let m = id.idRange - let attrs, _ = - if g.langVersion.SupportsFeature(LanguageFeature.EnforceAttributeTargets) then - TcAttributesWithPossibleTargets false cenv env AttributeTargets.Property synAttrs - else - TcAttributesWithPossibleTargets false cenv env AttributeTargets.FieldDecl synAttrs + let attrs, _ = TcAttributesWithPossibleTargets false cenv env AttributeTargets.FieldDecl synAttrs let attrsForProperty, attrsForField = attrs |> List.partition (fun (attrTargets, _) -> (attrTargets &&& AttributeTargets.Property) <> enum 0) let attrsForProperty = (List.map snd attrsForProperty) From 071611acf163573bde60ba007628139c2fe6ddcb Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Thu, 23 May 2024 13:30:42 +0100 Subject: [PATCH 09/15] update tests --- .../AttributeUsage/AttributeUsage.fs | 3 --- .../AttributeUsage/E_AttributeTargetIsProperty01.fs | 13 ------------- 2 files changed, 16 deletions(-) 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 2a2dc2f63af..1e5b49a1d83 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/AttributeUsage.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/AttributeUsage.fs @@ -497,9 +497,6 @@ 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") - (Error 842, Line 23, Col 9, Line 23, Col 19, "This attribute is not valid for use on this language element") - (Error 842, Line 25, Col 9, Line 25, Col 22, "This attribute is not valid for use on this language element") - (Error 842, Line 27, Col 9, Line 27, Col 32, "This attribute is not valid for use on this language element") ] // SOURCE=E_AttributeTargetIsCtor01.fs # E_AttributeTargetIsCtor01.fs diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/E_AttributeTargetIsProperty01.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/E_AttributeTargetIsProperty01.fs index a4ff3eae643..1f7f1d15631 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/E_AttributeTargetIsProperty01.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/E_AttributeTargetIsProperty01.fs @@ -13,16 +13,3 @@ type PropertyOrFieldLevelAttribute() = type SomeUnion = | [] Case1 of int // Should fail | [] Case2 of int // Should fail - -[] -type Name(x: string) = - inherit Attribute() - member _.value = x - -type User = - { [] - Id: int - [] - Email: string - [] - OrganizationId: option } \ No newline at end of file From 3ea80b3dae979bcfe5d8f208761eb7fb297f685f Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Mon, 10 Jun 2024 13:12:46 +0200 Subject: [PATCH 10/15] update tests --- .../AttributeUsage/AttributeTargetsIsProperty.fs | 15 +-------------- .../E_AttributeTargetIsProperty01.fs | 1 + 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/AttributeTargetsIsProperty.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/AttributeTargetsIsProperty.fs index 212a78960d5..ae150dc3034 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/AttributeTargetsIsProperty.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/AttributeTargetsIsProperty.fs @@ -7,17 +7,4 @@ type PropertyLevelAttribute() = type U = | [] A - | [] B - -[] -type Name(x: string) = - inherit Attribute() - member _.value = x - -type User = - { [] - Id: int - [] - Email: string - [] - OrganizationId: option } \ No newline at end of file + | [] B \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/E_AttributeTargetIsProperty01.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/E_AttributeTargetIsProperty01.fs index 1f7f1d15631..65a9ea17bd8 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/E_AttributeTargetIsProperty01.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/E_AttributeTargetIsProperty01.fs @@ -13,3 +13,4 @@ type PropertyOrFieldLevelAttribute() = type SomeUnion = | [] Case1 of int // Should fail | [] Case2 of int // Should fail + From 6e555a532a76e32a26041a733b8e63f41fd3b603 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Tue, 11 Jun 2024 22:53:33 +0100 Subject: [PATCH 11/15] update test --- .../AttributeUsage/E_AttributeTargetIsClass02.fs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/E_AttributeTargetIsClass02.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/E_AttributeTargetIsClass02.fs index 56712514253..f95f54b8354 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/E_AttributeTargetIsClass02.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/E_AttributeTargetIsClass02.fs @@ -19,5 +19,6 @@ type Record = { Prop: string } [] [] +[] [] type StructRecord = { Prop: string } \ No newline at end of file From 5a0b1c170c5f793075712619696b664eba4f2947 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Tue, 11 Jun 2024 23:23:11 +0100 Subject: [PATCH 12/15] Update StructAttribute to also AttributeTargets.Class --- docs/release-notes/.FSharp.Core/8.0.400.md | 1 + src/FSharp.Core/prim-types.fs | 2 +- src/FSharp.Core/prim-types.fsi | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/release-notes/.FSharp.Core/8.0.400.md b/docs/release-notes/.FSharp.Core/8.0.400.md index ee24d8d0a53..4c64de812a5 100644 --- a/docs/release-notes/.FSharp.Core/8.0.400.md +++ b/docs/release-notes/.FSharp.Core/8.0.400.md @@ -6,3 +6,4 @@ * Cache delegate in query extensions. ([PR #17130](https://github.com/dotnet/fsharp/pull/17130)) * Update `AllowNullLiteralAttribute` to also use `AttributeTargets.Interface` ([PR #17173](https://github.com/dotnet/fsharp/pull/17173)) +* Update `StructAttribute ` to also use `AttributeTargets.Classs` ([PR #17207](https://github.com/dotnet/fsharp/pull/17207)) diff --git a/src/FSharp.Core/prim-types.fs b/src/FSharp.Core/prim-types.fs index 556fb1bcde5..d95659a14f2 100644 --- a/src/FSharp.Core/prim-types.fs +++ b/src/FSharp.Core/prim-types.fs @@ -180,7 +180,7 @@ namespace Microsoft.FSharp.Core inherit Attribute() member _.CompiledName = compiledName - [] + [] [] type StructAttribute() = inherit Attribute() diff --git a/src/FSharp.Core/prim-types.fsi b/src/FSharp.Core/prim-types.fsi index 2b3bcf1ac7c..cb8c890171c 100644 --- a/src/FSharp.Core/prim-types.fsi +++ b/src/FSharp.Core/prim-types.fsi @@ -199,7 +199,7 @@ namespace Microsoft.FSharp.Core /// Adding this attribute to a type causes it to be represented using a CLI struct. /// /// Attributes - [] + [] [] type StructAttribute = inherit Attribute From 0062acb98f22c9fc8623f40226ebb4457cf7c323 Mon Sep 17 00:00:00 2001 From: Petr Date: Wed, 12 Jun 2024 13:02:49 +0200 Subject: [PATCH 13/15] Update 8.0.400.md --- docs/release-notes/.FSharp.Core/8.0.400.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/release-notes/.FSharp.Core/8.0.400.md b/docs/release-notes/.FSharp.Core/8.0.400.md index 4c64de812a5..9e01df90133 100644 --- a/docs/release-notes/.FSharp.Core/8.0.400.md +++ b/docs/release-notes/.FSharp.Core/8.0.400.md @@ -6,4 +6,4 @@ * Cache delegate in query extensions. ([PR #17130](https://github.com/dotnet/fsharp/pull/17130)) * Update `AllowNullLiteralAttribute` to also use `AttributeTargets.Interface` ([PR #17173](https://github.com/dotnet/fsharp/pull/17173)) -* Update `StructAttribute ` to also use `AttributeTargets.Classs` ([PR #17207](https://github.com/dotnet/fsharp/pull/17207)) +* Update `StructAttribute ` to also use `AttributeTargets.Class` ([PR #17207](https://github.com/dotnet/fsharp/pull/17207)) From a0f3acfb388a2fcf9d83df038f3f79cb0db079be Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Thu, 13 Jun 2024 14:45:25 +0100 Subject: [PATCH 14/15] Add clarifying comment --- src/Compiler/Checking/CheckDeclarations.fs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Compiler/Checking/CheckDeclarations.fs b/src/Compiler/Checking/CheckDeclarations.fs index 2105038c79f..601ae0cc9f0 100644 --- a/src/Compiler/Checking/CheckDeclarations.fs +++ b/src/Compiler/Checking/CheckDeclarations.fs @@ -2902,6 +2902,7 @@ module EstablishTypeDefinitionCores = if g.langVersion.SupportsFeature(LanguageFeature.EnforceAttributeTargets) then if hasStructAttr then + // To ensure that we can still use the RequiredQualifiedAccessAttribute on classes and structs we need to allow both AttributeTargets.Class ||| AttributeTargets.Struct. if hasRQAAttr then TcAttributesWithPossibleTargets false cenv envinner (AttributeTargets.Class ||| AttributeTargets.Struct) synAttrs |> ignore else From 5c6c7c8af32a3b73dda15766ac54a184d7074100 Mon Sep 17 00:00:00 2001 From: edgarfgp Date: Wed, 3 Jul 2024 20:13:05 +0100 Subject: [PATCH 15/15] We do not check for RQA attribute --- src/Compiler/Checking/CheckDeclarations.fs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Compiler/Checking/CheckDeclarations.fs b/src/Compiler/Checking/CheckDeclarations.fs index 601ae0cc9f0..b85bce8a198 100644 --- a/src/Compiler/Checking/CheckDeclarations.fs +++ b/src/Compiler/Checking/CheckDeclarations.fs @@ -2842,7 +2842,6 @@ module EstablishTypeDefinitionCores = let attrs, getFinalAttrs = TcAttributesCanFail cenv envinner AttributeTargets.TyconDecl synAttrs let hasMeasureAttr = HasFSharpAttribute g g.attrib_MeasureAttribute attrs let hasStructAttr = HasFSharpAttribute g g.attrib_StructAttribute attrs - let hasRQAAttr = HasFSharpAttribute g g.attrib_RequireQualifiedAccessAttribute attrs let isStructRecordOrUnionType = match synTyconRepr with @@ -2902,11 +2901,7 @@ module EstablishTypeDefinitionCores = if g.langVersion.SupportsFeature(LanguageFeature.EnforceAttributeTargets) then if hasStructAttr then - // To ensure that we can still use the RequiredQualifiedAccessAttribute on classes and structs we need to allow both AttributeTargets.Class ||| AttributeTargets.Struct. - if hasRQAAttr then - TcAttributesWithPossibleTargets false cenv envinner (AttributeTargets.Class ||| AttributeTargets.Struct) synAttrs |> ignore - else - TcAttributesWithPossibleTargets false cenv envinner AttributeTargets.Struct synAttrs |> ignore + TcAttributesWithPossibleTargets false cenv envinner AttributeTargets.Struct synAttrs |> ignore else TcAttributesWithPossibleTargets false cenv envinner AttributeTargets.Class synAttrs |> ignore