-
Notifications
You must be signed in to change notification settings - Fork 805
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix for issue 8351 #8354
Merged
KevinRansom
merged 17 commits into
dotnet:master
from
smoothdeveloper:fix-for-issue-8351
Jun 23, 2020
Merged
Fix for issue 8351 #8354
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
7b958fd
add a failing test exhibiting issue #8351
smoothdeveloper 827e5b8
updating VB and F# code to have private getter as well, VB has same i…
smoothdeveloper b5e59d5
Furthering the test, all languages exhibit the same issue.
smoothdeveloper cccb3da
F# setter on Prop1 works, despite the getter is internal
smoothdeveloper 5986427
fix for 8351 (/!\ may break other things)
smoothdeveloper b799113
reshuffle ILMemberAccess so plain comparison works
smoothdeveloper 8f94aff
testConfig has a new version
smoothdeveloper b5f5f6a
adding basic test around ILMemberAccess items being comparable to eac…
smoothdeveloper 1ccb4b1
ceci n'est pas une fonction factorielle
smoothdeveloper b024d51
codereview: redefine order of ILMemberAccess to match roslyn codebase
smoothdeveloper b88ba3c
Update for fix8351
KevinRansom 49d99be
feedback
KevinRansom fb3c52b
Update src/fsharp/AccessibilityLogic.fs
KevinRansom 16deb23
resolve conflicts
KevinRansom 37be39e
merge
KevinRansom 24b4d28
Update
smoothdeveloper 8bfcdd6
Merge branch 'master' into fix-for-issue-8351
KevinRansom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
224 changes: 224 additions & 0 deletions
224
tests/fsharp/Compiler/Conformance/Properties/ILMemberAccessTests.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,224 @@ | ||
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. | ||
|
||
namespace FSharp.Compiler.UnitTests | ||
|
||
open FSharp.Compiler.SourceCodeServices | ||
open FSharp.Reflection | ||
open FSharp.Test | ||
open FSharp.Test.Utilities | ||
open FSharp.Test.Utilities.Utilities | ||
open NUnit.Framework | ||
|
||
[<TestFixture>] | ||
module ILMemberAccessTests = | ||
|
||
let csharpBaseClass = """ | ||
namespace ExhaustiveCombinations | ||
{ | ||
public class CSharpBaseClass | ||
{ | ||
public string GetPublicSetInternal { get; internal set; } | ||
public string GetPublicSetProtected { get; protected set; } | ||
public string GetPublicSetPrivateProtected { get; private protected set; } | ||
public string GetPublicSetProtectedInternal { get; protected internal set; } | ||
public string GetPublicSetPrivate { get; private set; } | ||
|
||
public string SetPublicGetInternal { internal get; set; } | ||
public string SetPublicGetProtected { protected get; set; } | ||
public string SetPublicGetPrivateProtected { private protected get; set; } | ||
public string SetPublicGetProtectedInternal { protected internal get; set; } | ||
public string SetPublicGetPrivate { private get; set; } | ||
} | ||
} | ||
""" | ||
|
||
let fsharpBaseClass = """ | ||
namespace ExhaustiveCombinations | ||
|
||
open System | ||
|
||
type FSharpBaseClass () = | ||
|
||
member this.GetPublicSetInternal with public get() = "" and internal set (parameter:string) = ignore parameter | ||
member this.GetPublicSetPrivate with public get() = "" and private set (parameter:string) = ignore parameter | ||
member this.SetPublicGetInternal with internal get() = "" and public set (parameter:string) = ignore parameter | ||
member this.SetPublicGetPrivate with private get() = "" and public set (parameter:string) = ignore parameter | ||
|
||
""" | ||
|
||
|
||
[<Test>] | ||
let ``VerifyVisibility of Properties C# class F# derived class -- AccessPublicStuff`` () = | ||
|
||
let fsharpSource = | ||
fsharpBaseClass + """ | ||
open System | ||
open ExhaustiveCombinations | ||
|
||
type MyFSharpClass () = | ||
inherit CSharpBaseClass() | ||
|
||
member this.AccessPublicStuff() = | ||
|
||
this.GetPublicSetInternal <- "1" // Inaccessible | ||
let _ = this.GetPublicSetInternal // Accessible | ||
|
||
this.GetPublicSetPrivateProtected <- "1" // Accessible | ||
let _ = this.GetPublicSetPrivateProtected // Accessible | ||
|
||
this.GetPublicSetProtectedInternal <- "1" // Accessible | ||
let _ = this.GetPublicSetProtectedInternal // Accessible | ||
|
||
this.GetPublicSetProtected <- "1" // Accessible | ||
let _ = this.GetPublicSetProtected // Accessible | ||
|
||
this.GetPublicSetPrivate <- "1" // Inaccessible | ||
let _ = this.GetPublicSetPrivate // Accessible | ||
() | ||
""" | ||
|
||
let csCmpl = | ||
CompilationUtil.CreateCSharpCompilation(csharpBaseClass, CSharpLanguageVersion.CSharp8, TargetFramework.NetCoreApp30) | ||
|> CompilationReference.Create | ||
|
||
let fsCmpl = | ||
Compilation.Create(fsharpSource, Fsx, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) | ||
|
||
CompilerAssert.CompileWithErrors(fsCmpl, [| | ||
(FSharpErrorSeverity.Error, 491, (22, 9, 22, 41), | ||
"The member or object constructor 'GetPublicSetInternal' 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."); | ||
(FSharpErrorSeverity.Error, 491, (25, 9, 25, 49), | ||
"The member or object constructor 'GetPublicSetPrivateProtected' 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."); | ||
(FSharpErrorSeverity.Error, 491, (34, 9, 34, 40), | ||
"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.")|]) | ||
|
||
|
||
[<Test>] | ||
let ``VerifyVisibility of Properties C# class F# non-derived class -- AccessPublicStuff`` () = | ||
|
||
let fsharpSource = | ||
fsharpBaseClass + """ | ||
open System | ||
open ExhaustiveCombinations | ||
|
||
type MyFSharpClass () = | ||
|
||
member _.AccessPublicStuff() = | ||
let bc = new CSharpBaseClass() | ||
|
||
bc.GetPublicSetInternal <- "1" // Inaccessible | ||
let _ = bc.GetPublicSetInternal // Accessible | ||
|
||
bc.GetPublicSetPrivateProtected <- "1" // Inaccessible | ||
let _ = bc.GetPublicSetPrivateProtected // Accessible | ||
|
||
bc.GetPublicSetProtectedInternal <- "1" // Accessible | ||
let _ = bc.GetPublicSetProtectedInternal // Inaccessible | ||
|
||
bc.GetPublicSetProtected <- "1" // Inaccessible | ||
let _ = bc.SetPublicGetProtected // Accessible | ||
|
||
bc.GetPublicSetPrivate <- "1" // Inaccessible | ||
let _ = bc.GetPublicSetPrivate // Accessible | ||
() | ||
""" | ||
|
||
let csCmpl = | ||
CompilationUtil.CreateCSharpCompilation(csharpBaseClass, CSharpLanguageVersion.CSharp8, TargetFramework.NetCoreApp30) | ||
|> CompilationReference.Create | ||
|
||
let fsCmpl = | ||
Compilation.Create(fsharpSource, Fsx, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) | ||
|
||
CompilerAssert.CompileWithErrors(fsCmpl, [| | ||
(FSharpErrorSeverity.Error, 491, (22, 9, 22, 39), | ||
"The member or object constructor 'GetPublicSetInternal' 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."); | ||
(FSharpErrorSeverity.Error, 491, (25, 9, 25, 47), | ||
"The member or object constructor 'GetPublicSetPrivateProtected' 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."); | ||
(FSharpErrorSeverity.Error, 491, (28, 9, 28, 48), | ||
"The member or object constructor 'GetPublicSetProtectedInternal' 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."); | ||
(FSharpErrorSeverity.Error, 491, (31, 9, 31, 40), | ||
"The member or object constructor 'GetPublicSetProtected' 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."); | ||
(FSharpErrorSeverity.Error, 491, (32, 17, 32, 41), | ||
"The member or object constructor 'SetPublicGetProtected' 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."); | ||
(FSharpErrorSeverity.Error, 491, (34, 9, 34, 38), | ||
"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.")|]) | ||
|
||
|
||
[<Test>] | ||
let ``VerifyVisibility of Properties F# base F# derived class -- AccessPublicStuff`` () = | ||
|
||
let fsharpSource = | ||
fsharpBaseClass + """ | ||
open System | ||
open ExhaustiveCombinations | ||
|
||
type MyFSharpClass () = | ||
inherit FSharpBaseClass() | ||
|
||
member this.AccessPublicStuff() = | ||
|
||
this.GetPublicSetInternal <- "1" // Inaccessible | ||
let _ = this.GetPublicSetInternal // Accessible | ||
|
||
this.GetPublicSetPrivate <- "1" // Inaccessible | ||
let _ = this.GetPublicSetPrivate // Accessible | ||
|
||
this.SetPublicGetInternal <- "1" // Accessible | ||
let _ = this.SetPublicGetInternal // Inaccessible | ||
|
||
this.SetPublicGetPrivate <- "1" // Accessible | ||
let _ = this.SetPublicGetPrivate // accessible | ||
|
||
() | ||
""" | ||
|
||
let csCmpl = | ||
CompilationUtil.CreateCSharpCompilation(csharpBaseClass, CSharpLanguageVersion.CSharp8, TargetFramework.NetCoreApp30) | ||
|> CompilationReference.Create | ||
|
||
let fsCmpl = | ||
Compilation.Create(fsharpSource, Fsx, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) | ||
|
||
CompilerAssert.CompileWithErrors(fsCmpl, [| | ||
(FSharpErrorSeverity.Error, 810, (25, 9, 25, 33), | ||
"Property 'GetPublicSetPrivate' cannot be set"); | ||
(FSharpErrorSeverity.Error, 807, (32, 17, 32, 41), | ||
"Property 'SetPublicGetPrivate' is not readable") | ||
|]) | ||
|
||
|
||
[<Test>] | ||
let ``VerifyVisibility of Properties F# class F# non-derived class -- AccessPublicStuff`` () = | ||
|
||
let fsharpSource = | ||
fsharpBaseClass + """ | ||
open System | ||
open ExhaustiveCombinations | ||
|
||
type MyFSharpClass () = | ||
|
||
member _.AccessPublicStuff() = | ||
let bc = new FSharpBaseClass() | ||
|
||
bc.GetPublicSetInternal <- "1" // Inaccessible | ||
let _ = bc.GetPublicSetInternal // Accessible | ||
|
||
bc.GetPublicSetPrivate <- "1" // Inaccessible | ||
let _ = bc.GetPublicSetPrivate // Accessible | ||
() | ||
""" | ||
|
||
let csCmpl = | ||
CompilationUtil.CreateCSharpCompilation(csharpBaseClass, CSharpLanguageVersion.CSharp8, TargetFramework.NetCoreApp30) | ||
|> CompilationReference.Create | ||
|
||
let fsCmpl = | ||
Compilation.Create(fsharpSource, Fsx, Exe, options = [|"--langversion:preview"|], cmplRefs = [csCmpl]) | ||
|
||
CompilerAssert.CompileWithErrors(fsCmpl, [| | ||
(FSharpErrorSeverity.Error, 810, (25, 9, 25, 31), | ||
"Property 'GetPublicSetPrivate' cannot be set")|]) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this makes a lot of sense. I feel like we need to do something similar on the
ILProp
side, maybe insideIsILPropInfoAccessible
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TIHan I think this is handled:
fsharp/src/fsharp/AccessibilityLogic.fs
Lines 255 to 265 in 1ccb4b1
it returns the max accessible in
GetILAccessOfILPropInfo
which is then checked againstIsILTypeAndMemberAccessible
.Does that make sense?