提交 ad685d49 编写于 作者: L Lukas Rieger 提交者: Kevin Ransom (msft)

Fix 1373: add checks for famANDassembly visibility (#2495)

* add checks for famANDassembly visibility

fixes https://github.com/Microsoft/visualfsharp/issues/1373

* add unit tests for FamAndAssembly / FamOrAssembly

* disable failing test

* adapt ut error message for error message rework

* add issue link to disabled unit test

* align and replace all tabs with whitespace (maybe build failure is related to tabs? I'm probably paranoid ....)

* -a => --target:library

* fix assembly

* fix FamAndAssembly

* manually modify accessibilities in AccessibilityTests.dll

* Revert "-a => --target:library"

This reverts commit 33af6458fc2839511e7b110b4b0c3922ff95fa4e.
上级 38f489a7
......@@ -90,7 +90,15 @@ let private IsILMemberAccessible g amap m (tcrefOfViewedItem : TyconRef) ad acce
(access = ILMemberAccess.Assembly || access = ILMemberAccess.FamilyOrAssembly) &&
canAccessFromOneOf cpaths tcrefOfViewedItem.CompilationPath
(access = ILMemberAccess.Public) || accessibleByFamily || accessibleByInternalsVisibleTo
let accessibleByFamilyAndAssembly =
access = ILMemberAccess.FamilyAndAssembly &&
canAccessFromOneOf cpaths tcrefOfViewedItem.CompilationPath &&
match tcrefViewedFromOption with
| None -> false
| Some tcrefViewedFrom ->
ExistsHeadTypeInEntireHierarchy g amap m (generalizedTyconRef tcrefViewedFrom) tcrefOfViewedItem
(access = ILMemberAccess.Public) || accessibleByFamily || accessibleByInternalsVisibleTo || accessibleByFamilyAndAssembly
| AccessibleFromSomewhere ->
true
......
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("FamAndAssembly")]
[assembly: InternalsVisibleTo("FamOrAssembly")]
public class Accessibility
{
public int Public { get; set; }
private int Private { get; set; }
protected int Protected { get; set; }
internal int Internal { get; set; }
// Note: accessibility was modified using dnspy
public int FamOrAssembly { get; set; }
// Note: accessibility was modified using dnspy
public int FamAndAssembly { get; set; }
}
// #Regression #NoMT #Import
namespace NS
type T() =
// note: the assembly 'Accessibility' has an IVT to this assembly
inherit Accessibility()
member x.Test() = base.FamAndAssembly
// #Regression #NoMT #Import
//<Expects status="error" span="(8,28)" id="FS0039">The field, constructor or member 'FamAndAssembly' is not defined.</Expects>
namespace NS
type T() =
// note: the assembly 'Accessibility' does NOT have an IVT to this assembly, so it is expected to fail.
inherit Accessibility()
member x.Test() = base.FamAndAssembly
// #Regression #NoMT #Import
namespace NS
// note: the assembly 'Accessibility' has an IVT to this assembly
type T() =
inherit Accessibility()
member x.Test() = base.FamOrAssembly
module M =
let Test() = Accessibility().FamOrAssembly
// #Regression #NoMT #Import
//<Expects status="error" span="(12,18)" id="FS0491">The member or object constructor 'FamOrAssembly' 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.</Expects>
namespace NS
// with FamOrAssembly, this should succeed, even though there is no IVT
type T() =
inherit Accessibility()
member x.Test() = base.FamOrAssembly
module M =
// note: the assembly 'Accessibility' does NOT have an IVT to this assembly, so it is expected to fail.
let Test() = Accessibility().FamOrAssembly
......@@ -80,6 +80,15 @@ NOMONO SOURCE=reference2.fsx SCFLAGS="--nologo -r:reference1.dll" PRECMD="\$FSC_
SOURCE=InternalsConsumer.fs SCFLAGS="-r:InternalsConsumer.CSAssembly.dll" PRECMD="\$CSC_PIPE /t:library InternalsConsumer.CSAssembly.cs" # InternalsConsumer.fs
SOURCE=E_InternalsConsumer.fs SCFLAGS="-r:InternalsConsumer.CSAssembly.dll" PRECMD="\$CSC_PIPE /t:library InternalsConsumer.CSAssembly.cs" # E_InternalsConsumer.fs
###
### F# can consume FamOrAssembly and FamAndAssembly in combination with IVT
###
SOURCE=FamAndAssembly.fs SCFLAGS="-a -r:AccessibilityTests.dll" # FamAndAssembly.fs
### See issue https://github.com/Microsoft/visualfsharp/issues/2496
### SOURCE=FamOrAssembly.fs SCFLAGS="-a -r:AccessibilityTests.dll" # FamOrAssembly.fs
SOURCE=FamAndAssembly_NoIVT.fs SCFLAGS="-a -r:AccessibilityTests.dll" # FamAndAssembly_NoIVT.fs
### SOURCE=FamOrAssembly_NoIVT.fs SCFLAGS="-a -r:AccessibilityTests.dll" # FamOrAssembly_NoIVT.fs
###
### Iterate over BCL collections
###
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册