From f11d08fd504536b998ae141a5a33eeffc0e81bb9 Mon Sep 17 00:00:00 2001 From: ijklam <43789618+Tangent-90@users.noreply.github.com> Date: Fri, 27 Sep 2024 02:00:24 +0800 Subject: [PATCH 1/9] Disallow abstract member with access modifiers in sig file --- src/Compiler/Service/FSharpSource.fsi | 2 +- src/Compiler/SyntaxTree/ParseHelpers.fs | 8 ++++++ src/Compiler/SyntaxTree/ParseHelpers.fsi | 2 ++ src/Compiler/pars.fsy | 5 +++- .../PermittedLocations/PermittedLocations.fs | 27 +++++++++++++++++++ 5 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/Compiler/Service/FSharpSource.fsi b/src/Compiler/Service/FSharpSource.fsi index ca272a51fef..6bdabbdedf1 100644 --- a/src/Compiler/Service/FSharpSource.fsi +++ b/src/Compiler/Service/FSharpSource.fsi @@ -26,7 +26,7 @@ type internal FSharpSource = abstract TimeStamp: DateTime /// Gets the internal text container. Text may be on-disk, in a stream, or a source text. - abstract internal GetTextContainer: unit -> Async + abstract GetTextContainer: unit -> Async /// Creates a FSharpSource from disk. Only used internally. static member internal CreateFromFile: filePath: string -> FSharpSource diff --git a/src/Compiler/SyntaxTree/ParseHelpers.fs b/src/Compiler/SyntaxTree/ParseHelpers.fs index 22c27eeb9b0..5f231ecd753 100644 --- a/src/Compiler/SyntaxTree/ParseHelpers.fs +++ b/src/Compiler/SyntaxTree/ParseHelpers.fs @@ -1213,3 +1213,11 @@ let mkValField mkSynField parseState idOpt typ isMutable access attribs mStaticOpt rangeStart (Some leadingKeyword) SynMemberDefn.ValField(field, field.Range) + +let leadingKeywordIsAbstract = + function + | SynLeadingKeyword.Abstract _ + | SynLeadingKeyword.AbstractMember _ + | SynLeadingKeyword.StaticAbstract _ + | SynLeadingKeyword.StaticAbstractMember _ -> true + | _ -> false \ No newline at end of file diff --git a/src/Compiler/SyntaxTree/ParseHelpers.fsi b/src/Compiler/SyntaxTree/ParseHelpers.fsi index 52f4257d4c2..93998d5a225 100644 --- a/src/Compiler/SyntaxTree/ParseHelpers.fsi +++ b/src/Compiler/SyntaxTree/ParseHelpers.fsi @@ -302,3 +302,5 @@ val mkSynField: rangeStart: range -> leadingKeyword: SynLeadingKeyword option -> SynField + +val leadingKeywordIsAbstract: SynLeadingKeyword -> bool \ No newline at end of file diff --git a/src/Compiler/pars.fsy b/src/Compiler/pars.fsy index 656b75c39ff..770b131940e 100644 --- a/src/Compiler/pars.fsy +++ b/src/Compiler/pars.fsy @@ -985,8 +985,11 @@ classMemberSpfn: match optLiteralValue with | None -> m | Some e -> unionRanges m e.Range - + let flags, leadingKeyword = $3 + if leadingKeywordIsAbstract leadingKeyword && Option.isSome $5 || Option.isSome getterAccess || Option.isSome setterAccess + then errorR(Error(FSComp.SR.parsAccessibilityModsIllegalForAbstract(), mWhole)) + let flags = flags (getSetAdjuster arity) let trivia = { LeadingKeyword = leadingKeyword; InlineKeyword = $4; WithKeyword = mWith; EqualsRange = mEquals } let valSpfn = SynValSig($1, id, explicitValTyparDecls, ty, arity, isInline, false, doc, vis2, optLiteralValue, mWhole, trivia) diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/AccessibilityAnnotations/PermittedLocations/PermittedLocations.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/AccessibilityAnnotations/PermittedLocations/PermittedLocations.fs index 68eb881ff7f..a24caf2796c 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/AccessibilityAnnotations/PermittedLocations/PermittedLocations.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/AccessibilityAnnotations/PermittedLocations/PermittedLocations.fs @@ -160,3 +160,30 @@ module AccessibilityAnnotations_PermittedLocations = |> withDiagnostics [ (Error 531, Line 8, Col 13, Line 8, Col 20, "Accessibility modifiers should come immediately prior to the identifier naming a construct") ] + + [] + let ``Signature File Test: abstract member cannot have access modifiers`` () = + Fsi """module Program + +type A = + abstract internal B: int ->int + abstract member internal E: int ->int + abstract member C: int with internal get, private set + abstract internal D: int with get, set + static abstract internal B2: int ->int + static abstract member internal E2: int ->int + static abstract member C2: int with internal get, private set + static abstract internal D2: int with get, set""" + |> withOptions ["--nowarn:3535"] + |> verifyCompile + |> shouldFail + |> withDiagnostics [ + (Error 0561, Line 4, Col 5, Line 4, Col 35, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") + (Error 0561, Line 5, Col 5, Line 5, Col 42, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") + (Error 0561, Line 6, Col 5, Line 6, Col 58, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") + (Error 0561, Line 7, Col 5, Line 7, Col 43, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") + (Error 0561, Line 8, Col 5, Line 8, Col 43, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") + (Error 0561, Line 9, Col 5, Line 9, Col 50, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") + (Error 0561, Line 10, Col 5, Line 10, Col 66, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") + (Error 0561, Line 11, Col 5, Line 11, Col 51, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") + ] From 115444cde803853b37a86e7581f7e4989b404bce Mon Sep 17 00:00:00 2001 From: ijklam <43789618+Tangent-90@users.noreply.github.com> Date: Fri, 27 Sep 2024 02:12:03 +0800 Subject: [PATCH 2/9] release note --- docs/release-notes/.FSharp.Compiler.Service/9.0.200.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md b/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md index 5ef93105656..5cb5178e51e 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md +++ b/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md @@ -1,4 +1,5 @@ ### Fixed +* Disallow abstract member with access modifiers in sig file. ([PR #17802](https://github.com/dotnet/fsharp/pull/17802)) ### Added From 348011e8fb632b407950343838f81868b12148d9 Mon Sep 17 00:00:00 2001 From: ijklam <43789618+Tangent-90@users.noreply.github.com> Date: Fri, 27 Sep 2024 21:28:37 +0800 Subject: [PATCH 3/9] format --- src/Compiler/SyntaxTree/ParseHelpers.fs | 4 ++-- src/Compiler/SyntaxTree/ParseHelpers.fsi | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Compiler/SyntaxTree/ParseHelpers.fs b/src/Compiler/SyntaxTree/ParseHelpers.fs index 5f231ecd753..3733119fd6a 100644 --- a/src/Compiler/SyntaxTree/ParseHelpers.fs +++ b/src/Compiler/SyntaxTree/ParseHelpers.fs @@ -1214,10 +1214,10 @@ let mkValField SynMemberDefn.ValField(field, field.Range) -let leadingKeywordIsAbstract = +let leadingKeywordIsAbstract = function | SynLeadingKeyword.Abstract _ | SynLeadingKeyword.AbstractMember _ | SynLeadingKeyword.StaticAbstract _ | SynLeadingKeyword.StaticAbstractMember _ -> true - | _ -> false \ No newline at end of file + | _ -> false diff --git a/src/Compiler/SyntaxTree/ParseHelpers.fsi b/src/Compiler/SyntaxTree/ParseHelpers.fsi index 93998d5a225..ebb06834943 100644 --- a/src/Compiler/SyntaxTree/ParseHelpers.fsi +++ b/src/Compiler/SyntaxTree/ParseHelpers.fsi @@ -303,4 +303,4 @@ val mkSynField: leadingKeyword: SynLeadingKeyword option -> SynField -val leadingKeywordIsAbstract: SynLeadingKeyword -> bool \ No newline at end of file +val leadingKeywordIsAbstract: SynLeadingKeyword -> bool From da7d50a1fd295fe048ea77818ffdaf55bb59716c Mon Sep 17 00:00:00 2001 From: ijklam <43789618+Tangent-90@users.noreply.github.com> Date: Fri, 27 Sep 2024 23:27:48 +0800 Subject: [PATCH 4/9] fix --- src/Compiler/pars.fsy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compiler/pars.fsy b/src/Compiler/pars.fsy index 770b131940e..caf620c2245 100644 --- a/src/Compiler/pars.fsy +++ b/src/Compiler/pars.fsy @@ -987,7 +987,7 @@ classMemberSpfn: | Some e -> unionRanges m e.Range let flags, leadingKeyword = $3 - if leadingKeywordIsAbstract leadingKeyword && Option.isSome $5 || Option.isSome getterAccess || Option.isSome setterAccess + if leadingKeywordIsAbstract leadingKeyword && (Option.isSome $5 || Option.isSome getterAccess || Option.isSome setterAccess) then errorR(Error(FSComp.SR.parsAccessibilityModsIllegalForAbstract(), mWhole)) let flags = flags (getSetAdjuster arity) From f64c4fe6a7176f6d6266aae0b115b6184680c594 Mon Sep 17 00:00:00 2001 From: ijklam <43789618+Tangent-90@users.noreply.github.com> Date: Sat, 28 Sep 2024 12:49:42 +0800 Subject: [PATCH 5/9] fix test --- .../MethodsAndProperties/AutoPropsWithModifierBeforeGetSet.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/MemberDefinitions/MethodsAndProperties/AutoPropsWithModifierBeforeGetSet.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/MemberDefinitions/MethodsAndProperties/AutoPropsWithModifierBeforeGetSet.fs index 676746d96f5..92b1ca23e5d 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/MemberDefinitions/MethodsAndProperties/AutoPropsWithModifierBeforeGetSet.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/MemberDefinitions/MethodsAndProperties/AutoPropsWithModifierBeforeGetSet.fs @@ -132,7 +132,7 @@ type A = |> verifyCompile |> shouldFail |> withDiagnostics [ - (Error 240, Line 1, Col 1, Line 9, Col 42, "The signature file 'Program' does not have a corresponding implementation file. If an implementation file exists then check the 'module' and 'namespace' declarations in the signature and implementation files match.") + (Error 0561, Line 9, Col 5, Line 9, Col 42, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") ] [] From 382bed247a6bf9e2b81fd34351641f56312d63a5 Mon Sep 17 00:00:00 2001 From: ijklam <43789618+Tangent-90@users.noreply.github.com> Date: Wed, 9 Oct 2024 23:25:17 +0800 Subject: [PATCH 6/9] use access modifier range to show error --- src/Compiler/pars.fsy | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/Compiler/pars.fsy b/src/Compiler/pars.fsy index 6f6f4210b70..ba3ebc40e65 100644 --- a/src/Compiler/pars.fsy +++ b/src/Compiler/pars.fsy @@ -987,8 +987,9 @@ classMemberSpfn: | Some e -> unionRanges m e.Range let flags, leadingKeyword = $3 - if leadingKeywordIsAbstract leadingKeyword && (Option.isSome $5 || Option.isSome getterAccess || Option.isSome setterAccess) - then errorR(Error(FSComp.SR.parsAccessibilityModsIllegalForAbstract(), mWhole)) + if leadingKeywordIsAbstract leadingKeyword then + [ $5; getterAccess; setterAccess ] + |> List.iter (function None -> () | Some access -> errorR(Error(FSComp.SR.parsAccessibilityModsIllegalForAbstract(), access.Range))) let flags = flags (getSetAdjuster arity) let trivia = { LeadingKeyword = leadingKeyword; InlineKeyword = $4; WithKeyword = mWith; EqualsRange = mEquals } @@ -2049,10 +2050,11 @@ classDefnMember: let ty = SynType.FromParseError(mInterface.EndRange) [ SynMemberDefn.Interface(ty, None, None, rhs2 parseState 1 3) ] } - | opt_attributes opt_access abstractMemberFlags opt_inline nameop opt_explicitValTyparDecls COLON topTypeWithTypeConstraints classMemberSpfnGetSet opt_ODECLEND - { let ty, arity = $8 - let isInline, doc, id, explicitValTyparDecls = (Option.isSome $4), grabXmlDoc(parseState, $1, 1), $5, $6 - let mWith, (getSet, getSetRangeOpt, getterAccess, setterAccess) = $9 + | opt_attributes opt_access abstractMemberFlags opt_access opt_inline nameop opt_explicitValTyparDecls COLON topTypeWithTypeConstraints classMemberSpfnGetSet opt_ODECLEND + { if Option.isSome $2 then errorR(Error(FSComp.SR.parsVisibilityDeclarationsShouldComePriorToIdentifier(), rhs parseState 2)) + let ty, arity = $9 + let isInline, doc, id, explicitValTyparDecls = (Option.isSome $5), grabXmlDoc(parseState, $1, 1), $6, $7 + let mWith, (getSet, getSetRangeOpt, getterAccess, setterAccess) = $10 let getSetAdjuster arity = match arity, getSet with SynValInfo([], _), SynMemberKind.Member -> SynMemberKind.PropertyGet | _ -> getSet let mWhole = let m = rhs parseState 1 @@ -2060,10 +2062,12 @@ classDefnMember: | None -> unionRanges m ty.Range | Some gs -> unionRanges m gs.Range |> unionRangeWithXmlDoc doc - if Option.isSome $2 || Option.isSome getterAccess || Option.isSome setterAccess - then errorR(Error(FSComp.SR.parsAccessibilityModsIllegalForAbstract(), mWhole)) + + [ $4; getterAccess; setterAccess ] + |> List.iter (function None -> () | Some access -> errorR(Error(FSComp.SR.parsAccessibilityModsIllegalForAbstract(), access.Range))) + let mkFlags, leadingKeyword = $3 - let trivia = { LeadingKeyword = leadingKeyword; InlineKeyword = $4; WithKeyword = mWith; EqualsRange = None } + let trivia = { LeadingKeyword = leadingKeyword; InlineKeyword = $5; WithKeyword = mWith; EqualsRange = None } let vis2 = SynValSigAccess.Single(None) let valSpfn = SynValSig($1, id, explicitValTyparDecls, ty, arity, isInline, false, doc, vis2, None, mWhole, trivia) let trivia: SynMemberDefnAbstractSlotTrivia = { GetSetKeywords = getSetRangeOpt } From 45d54a261c8dd124a4f0058f902224168469cf77 Mon Sep 17 00:00:00 2001 From: ijklam <43789618+Tangent-90@users.noreply.github.com> Date: Thu, 10 Oct 2024 12:52:16 +0800 Subject: [PATCH 7/9] update tests --- .../PermittedLocations/PermittedLocations.fs | 40 ++++++++++--------- .../AutoPropsWithModifierBeforeGetSet.fs | 5 ++- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/AccessibilityAnnotations/PermittedLocations/PermittedLocations.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/AccessibilityAnnotations/PermittedLocations/PermittedLocations.fs index a24caf2796c..23281b293cf 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/AccessibilityAnnotations/PermittedLocations/PermittedLocations.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/AccessibilityAnnotations/PermittedLocations/PermittedLocations.fs @@ -27,12 +27,12 @@ module AccessibilityAnnotations_PermittedLocations = |> verifyCompile |> shouldFail |> withDiagnostics [ - (Error 561, Line 18, Col 5, Line 18, Col 62, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") - (Error 561, Line 19, Col 5, Line 19, Col 62, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") - (Error 561, Line 20, Col 5, Line 20, Col 62, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") - (Error 10, Line 21, Col 14, Line 21, Col 20, "Unexpected keyword 'public' in member definition. Expected identifier, '(', '(*)' or other token.") + (Error 531, Line 18, Col 5, Line 18, Col 11, "Accessibility modifiers should come immediately prior to the identifier naming a construct") + (Error 531, Line 19, Col 5, Line 19, Col 12, "Accessibility modifiers should come immediately prior to the identifier naming a construct") + (Error 531, Line 20, Col 5, Line 20, Col 13, "Accessibility modifiers should come immediately prior to the identifier naming a construct") + (Error 561, Line 21, Col 14, Line 21, Col 20, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") (Error 561, Line 21, Col 14, Line 22, Col 62, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") - (Error 10, Line 23, Col 14, Line 23, Col 22, "Unexpected keyword 'internal' in member definition. Expected identifier, '(', '(*)' or other token.") + (Error 561, Line 23, Col 14, Line 23, Col 22, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") ] // SOURCE=E_accessibilityOnInterface01.fs SCFLAGS="--test:ErrorRanges" # E_accessibilityOnInterface01.fs @@ -42,7 +42,7 @@ module AccessibilityAnnotations_PermittedLocations = |> verifyCompile |> shouldFail |> withDiagnostics [ - (Error 561, Line 13, Col 5, Line 13, Col 67, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") + (Error 531, Line 13, Col 5, Line 13, Col 11, "Accessibility modifiers should come immediately prior to the identifier naming a construct") ] // SOURCE=E_accessibilityOnInterface02.fs SCFLAGS="--test:ErrorRanges" # E_accessibilityOnInterface02.fs @@ -52,7 +52,7 @@ module AccessibilityAnnotations_PermittedLocations = |> verifyCompile |> shouldFail |> withDiagnostics [ - (Error 561, Line 15, Col 5, Line 15, Col 68, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") + (Error 531, Line 15, Col 5, Line 15, Col 12, "Accessibility modifiers should come immediately prior to the identifier naming a construct") ] // SOURCE=E_accessibilityOnInterface03.fs SCFLAGS="--test:ErrorRanges" # E_accessibilityOnInterface03.fs @@ -62,7 +62,7 @@ module AccessibilityAnnotations_PermittedLocations = |> verifyCompile |> shouldFail |> withDiagnostics [ - (Error 561, Line 15, Col 5, Line 15, Col 69, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") + (Error 531, Line 15, Col 5, Line 15, Col 13, "Accessibility modifiers should come immediately prior to the identifier naming a construct") ] // SOURCE=E_accessibilityOnInterface04.fs SCFLAGS="--test:ErrorRanges" # E_accessibilityOnInterface04.fs @@ -72,7 +72,7 @@ module AccessibilityAnnotations_PermittedLocations = |> verifyCompile |> shouldFail |> withDiagnostics [ - (Error 10, Line 15, Col 14, Line 15, Col 20, "Unexpected keyword 'public' in member definition. Expected identifier, '(', '(*)' or other token.") + (Error 561, Line 15, Col 14, Line 15, Col 20, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") ] // SOURCE=E_accessibilityOnInterface05.fs SCFLAGS="--test:ErrorRanges" # E_accessibilityOnInterface05.fs @@ -82,7 +82,7 @@ module AccessibilityAnnotations_PermittedLocations = |> verifyCompile |> shouldFail |> withDiagnostics [ - (Error 10, Line 15, Col 14, Line 15, Col 21, "Unexpected keyword 'private' in member definition. Expected identifier, '(', '(*)' or other token.") + (Error 561, Line 15, Col 14, Line 15, Col 21, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") ] // SOURCE=E_accessibilityOnInterface06.fs SCFLAGS="--test:ErrorRanges" # E_accessibilityOnInterface06.fs @@ -92,7 +92,7 @@ module AccessibilityAnnotations_PermittedLocations = |> verifyCompile |> shouldFail |> withDiagnostics [ - (Error 10, Line 15, Col 14, Line 15, Col 22, "Unexpected keyword 'internal' in member definition. Expected identifier, '(', '(*)' or other token.") + (Error 561, Line 15, Col 14, Line 15, Col 22, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") ] // SOURCE=E_accessibilityOnRecords.fs SCFLAGS="--test:ErrorRanges" # E_accessibilityOnRecords.fs @@ -178,12 +178,14 @@ type A = |> verifyCompile |> shouldFail |> withDiagnostics [ - (Error 0561, Line 4, Col 5, Line 4, Col 35, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") - (Error 0561, Line 5, Col 5, Line 5, Col 42, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") - (Error 0561, Line 6, Col 5, Line 6, Col 58, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") - (Error 0561, Line 7, Col 5, Line 7, Col 43, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") - (Error 0561, Line 8, Col 5, Line 8, Col 43, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") - (Error 0561, Line 9, Col 5, Line 9, Col 50, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") - (Error 0561, Line 10, Col 5, Line 10, Col 66, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") - (Error 0561, Line 11, Col 5, Line 11, Col 51, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") + (Error 0561, Line 4, Col 14, Line 4, Col 22, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") + (Error 0561, Line 5, Col 21, Line 5, Col 29, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") + (Error 0561, Line 6, Col 33, Line 6, Col 41, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") + (Error 0561, Line 6, Col 47, Line 6, Col 54, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") + (Error 0561, Line 7, Col 14, Line 7, Col 22, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") + (Error 0561, Line 8, Col 21, Line 8, Col 29, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") + (Error 0561, Line 9, Col 28, Line 9, Col 36, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") + (Error 0561, Line 10, Col 41, Line 10, Col 49, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") + (Error 0561, Line 10, Col 55, Line 10, Col 62, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") + (Error 0561, Line 11, Col 21, Line 11, Col 29, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") ] diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/MemberDefinitions/MethodsAndProperties/AutoPropsWithModifierBeforeGetSet.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/MemberDefinitions/MethodsAndProperties/AutoPropsWithModifierBeforeGetSet.fs index 92b1ca23e5d..942fae3950a 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/MemberDefinitions/MethodsAndProperties/AutoPropsWithModifierBeforeGetSet.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/MemberDefinitions/MethodsAndProperties/AutoPropsWithModifierBeforeGetSet.fs @@ -112,7 +112,8 @@ let ``Abstract Properties Test: access modifiers are not allowed`` () = |> withDiagnostics [ (Error 0561, Line 6, Col 5, Line 6, Col 51, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") (Error 0561, Line 8, Col 5, Line 8, Col 51, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") - (Error 0561, Line 10, Col 5, Line 10, Col 60, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") + (Error 0561, Line 10, Col 34, Line 10, Col 42, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") + (Error 0561, Line 10, Col 48, Line 10, Col 56, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") (Error 0561, Line 12, Col 5, Line 12, Col 46, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") (Error 0561, Line 14, Col 5, Line 14, Col 46, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") ] @@ -132,7 +133,7 @@ type A = |> verifyCompile |> shouldFail |> withDiagnostics [ - (Error 0561, Line 9, Col 5, Line 9, Col 42, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") + (Error 0561, Line 9, Col 31, Line 9, Col 38, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") ] [] From 8a77bb32e1c643c567061b5ea9978d70778cbc2e Mon Sep 17 00:00:00 2001 From: ijklam <43789618+Tangent-90@users.noreply.github.com> Date: Thu, 10 Oct 2024 14:27:50 +0800 Subject: [PATCH 8/9] update tests --- .../PermittedLocations/PermittedLocations.fs | 2 +- .../AutoPropsWithModifierBeforeGetSet.fs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/AccessibilityAnnotations/PermittedLocations/PermittedLocations.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/AccessibilityAnnotations/PermittedLocations/PermittedLocations.fs index 23281b293cf..7142fca4c74 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/AccessibilityAnnotations/PermittedLocations/PermittedLocations.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/AccessibilityAnnotations/PermittedLocations/PermittedLocations.fs @@ -31,7 +31,7 @@ module AccessibilityAnnotations_PermittedLocations = (Error 531, Line 19, Col 5, Line 19, Col 12, "Accessibility modifiers should come immediately prior to the identifier naming a construct") (Error 531, Line 20, Col 5, Line 20, Col 13, "Accessibility modifiers should come immediately prior to the identifier naming a construct") (Error 561, Line 21, Col 14, Line 21, Col 20, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") - (Error 561, Line 21, Col 14, Line 22, Col 62, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") + (Error 561, Line 22, Col 14, Line 22, Col 21, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") (Error 561, Line 23, Col 14, Line 23, Col 22, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") ] diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/MemberDefinitions/MethodsAndProperties/AutoPropsWithModifierBeforeGetSet.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/MemberDefinitions/MethodsAndProperties/AutoPropsWithModifierBeforeGetSet.fs index 942fae3950a..7e7cdff06cc 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/MemberDefinitions/MethodsAndProperties/AutoPropsWithModifierBeforeGetSet.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/MemberDefinitions/MethodsAndProperties/AutoPropsWithModifierBeforeGetSet.fs @@ -110,12 +110,12 @@ let ``Abstract Properties Test: access modifiers are not allowed`` () = |> typecheck |> shouldFail |> withDiagnostics [ - (Error 0561, Line 6, Col 5, Line 6, Col 51, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") - (Error 0561, Line 8, Col 5, Line 8, Col 51, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") + (Error 0561, Line 6, Col 34, Line 6, Col 42, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") + (Error 0561, Line 8, Col 39, Line 8, Col 47, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") (Error 0561, Line 10, Col 34, Line 10, Col 42, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") (Error 0561, Line 10, Col 48, Line 10, Col 56, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") - (Error 0561, Line 12, Col 5, Line 12, Col 46, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") - (Error 0561, Line 14, Col 5, Line 14, Col 46, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") + (Error 0561, Line 12, Col 34, Line 12, Col 42, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") + (Error 0561, Line 14, Col 34, Line 14, Col 42, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") ] [] From 88e49a9eed4af19d304b4ad27305b789c84062d5 Mon Sep 17 00:00:00 2001 From: ijklam <43789618+Tangent-90@users.noreply.github.com> Date: Thu, 24 Oct 2024 09:47:15 +0800 Subject: [PATCH 9/9] show both FS0531 and FS0561 --- src/Compiler/pars.fsy | 4 ++-- .../PermittedLocations/PermittedLocations.fs | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Compiler/pars.fsy b/src/Compiler/pars.fsy index 627fbd1f075..21671779904 100644 --- a/src/Compiler/pars.fsy +++ b/src/Compiler/pars.fsy @@ -988,7 +988,7 @@ classMemberSpfn: let flags, leadingKeyword = $3 if leadingKeywordIsAbstract leadingKeyword then - [ $5; getterAccess; setterAccess ] + [ $2; $5; getterAccess; setterAccess ] |> List.iter (function None -> () | Some access -> errorR(Error(FSComp.SR.parsAccessibilityModsIllegalForAbstract(), access.Range))) let flags = flags (getSetAdjuster arity) @@ -2063,7 +2063,7 @@ classDefnMember: | Some gs -> unionRanges m gs.Range |> unionRangeWithXmlDoc doc - [ $4; getterAccess; setterAccess ] + [ $2; $4; getterAccess; setterAccess ] |> List.iter (function None -> () | Some access -> errorR(Error(FSComp.SR.parsAccessibilityModsIllegalForAbstract(), access.Range))) let mkFlags, leadingKeyword = $3 diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/AccessibilityAnnotations/PermittedLocations/PermittedLocations.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/AccessibilityAnnotations/PermittedLocations/PermittedLocations.fs index 7142fca4c74..7f4c02ab56f 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/AccessibilityAnnotations/PermittedLocations/PermittedLocations.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/AccessibilityAnnotations/PermittedLocations/PermittedLocations.fs @@ -28,8 +28,11 @@ module AccessibilityAnnotations_PermittedLocations = |> shouldFail |> withDiagnostics [ (Error 531, Line 18, Col 5, Line 18, Col 11, "Accessibility modifiers should come immediately prior to the identifier naming a construct") + (Error 561, Line 18, Col 5, Line 18, Col 11, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") (Error 531, Line 19, Col 5, Line 19, Col 12, "Accessibility modifiers should come immediately prior to the identifier naming a construct") + (Error 561, Line 19, Col 5, Line 19, Col 12, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") (Error 531, Line 20, Col 5, Line 20, Col 13, "Accessibility modifiers should come immediately prior to the identifier naming a construct") + (Error 561, Line 20, Col 5, Line 20, Col 13, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") (Error 561, Line 21, Col 14, Line 21, Col 20, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") (Error 561, Line 22, Col 14, Line 22, Col 21, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") (Error 561, Line 23, Col 14, Line 23, Col 22, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") @@ -43,6 +46,7 @@ module AccessibilityAnnotations_PermittedLocations = |> shouldFail |> withDiagnostics [ (Error 531, Line 13, Col 5, Line 13, Col 11, "Accessibility modifiers should come immediately prior to the identifier naming a construct") + (Error 561, Line 13, Col 5, Line 13, Col 11, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") ] // SOURCE=E_accessibilityOnInterface02.fs SCFLAGS="--test:ErrorRanges" # E_accessibilityOnInterface02.fs @@ -53,6 +57,7 @@ module AccessibilityAnnotations_PermittedLocations = |> shouldFail |> withDiagnostics [ (Error 531, Line 15, Col 5, Line 15, Col 12, "Accessibility modifiers should come immediately prior to the identifier naming a construct") + (Error 561, Line 15, Col 5, Line 15, Col 12, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") ] // SOURCE=E_accessibilityOnInterface03.fs SCFLAGS="--test:ErrorRanges" # E_accessibilityOnInterface03.fs @@ -63,6 +68,7 @@ module AccessibilityAnnotations_PermittedLocations = |> shouldFail |> withDiagnostics [ (Error 531, Line 15, Col 5, Line 15, Col 13, "Accessibility modifiers should come immediately prior to the identifier naming a construct") + (Error 561, Line 15, Col 5, Line 15, Col 13, "Accessibility modifiers are not allowed on this member. Abstract slots always have the same visibility as the enclosing type.") ] // SOURCE=E_accessibilityOnInterface04.fs SCFLAGS="--test:ErrorRanges" # E_accessibilityOnInterface04.fs