Skip to content

Commit 49d99be

Browse files
committed
feedback
1 parent b88ba3c commit 49d99be

2 files changed

Lines changed: 28 additions & 3 deletions

File tree

src/fsharp/AccessibilityLogic.fs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,19 @@ let GetILAccessOfILPropInfo (ILPropInfo(tinfo, pdef)) =
254254
| None, Some mref -> (resolveILMethodRef tdef mref).Access
255255

256256
| Some mrefGet, Some mrefSet ->
257+
//
258+
// Dotnet properties have a getter and a setter method, each of which can have a separate visibility public, protected, private etc ...
259+
// This code computes the visibility for the property by choosing the most visible method. This approximation is usefull for cases
260+
// where the compiler needs to know the visibility of the property.
261+
// The specific ordering for choosing the most visible is:
262+
// ILMemberAccess.Public,
263+
// ILMemberAccess.FamilyOrAssembly
264+
// ILMemberAccess.Assembly
265+
// ILMemberAccess.Family
266+
// ILMemberAccess.FamilyAndAssembly
267+
// ILMemberAccess.Private
268+
// ILMemberAccess.CompilerControlled
269+
//
257270
let getA = (resolveILMethodRef tdef mrefGet).Access
258271
let setA = (resolveILMethodRef tdef mrefSet).Access
259272

@@ -274,7 +287,10 @@ let GetILAccessOfILPropInfo (ILPropInfo(tinfo, pdef)) =
274287
| ILMemberAccess.FamilyAndAssembly, _
275288
| _, ILMemberAccess.FamilyAndAssembly -> ILMemberAccess.FamilyAndAssembly
276289

277-
| _ -> ILMemberAccess.Private
290+
| ILMemberAccess.Private, _
291+
| _, ILMemberAccess.Private -> ILMemberAccess.Private
292+
293+
| _ -> ILMemberAccess.CompilerControlled
278294

279295
| None, None -> ILMemberAccess.Public
280296

tests/fsharp/Compiler/Conformance/Properties/ILMemberAccessTests.fs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ type MyFSharpClass () =
9191
(FSharpErrorSeverity.Error, 491, (34, 9, 34, 40),
9292
"The member or object constructor 'GetPublicSetPrivate' is not accessible. Private members may only be accessed from within the declaring type. Protected members may only be accessed from an extending type and cannot be accessed from inner lambda expressions.")|])
9393

94+
9495
[<Test>]
9596
let ``VerifyVisibility of Properties C# class F# non-derived class -- AccessPublicStuff`` () =
9697

@@ -161,6 +162,13 @@ type MyFSharpClass () =
161162
162163
this.GetPublicSetPrivate <- "1" // Inaccessible
163164
let _ = this.GetPublicSetPrivate // Accessible
165+
166+
this.SetPublicGetInternal <- "1" // Accessible
167+
let _ = this.SetPublicGetInternal // Inaccessible
168+
169+
this.SetPublicGetPrivate <- "1" // Accessible
170+
let _ = this.SetPublicGetPrivate // accessible
171+
164172
()
165173
"""
166174

@@ -173,7 +181,9 @@ type MyFSharpClass () =
173181

174182
CompilerAssert.CompileWithErrors(fsCmpl, [|
175183
(FSharpErrorSeverity.Error, 810, (25, 9, 25, 33),
176-
"Property 'GetPublicSetPrivate' cannot be set")
184+
"Property 'GetPublicSetPrivate' cannot be set");
185+
(FSharpErrorSeverity.Error, 807, (32, 17, 32, 41),
186+
"Property 'SetPublicGetPrivate' is not readable")
177187
|])
178188

179189

@@ -211,4 +221,3 @@ type MyFSharpClass () =
211221

212222

213223

214-
// Todo: Repeat these tests with a seperate F# assembly

0 commit comments

Comments
 (0)