-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Bug 217681: compiler should not crash on public+private metadata #11547
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1346,5 +1346,38 @@ instance void .ctor() cil managed | |
var method = type.GetMember<MethodSymbol>("M"); | ||
Assert.NotNull(method.ReturnType); | ||
} | ||
|
||
[Fact, WorkItem(217681, "https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_workitems?id=217681")] | ||
public void LoadingMethodWithPublicAndPrivateAccessibility() | ||
{ | ||
string source = | ||
@" | ||
public class D | ||
{ | ||
public static void Main() | ||
{ | ||
new C().M(); | ||
System.Console.WriteLine(new C().F); | ||
new C.C2().M2(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
} | ||
"; | ||
var references = new[] { MetadataReference.CreateFromImage(TestResources.SymbolsTests.Metadata.PublicAndPrivateFlags) }; | ||
|
||
var comp = CreateCompilationWithMscorlib(source, references: references); | ||
|
||
// The method, field and nested type with public and private accessibility flags get loaded as private. | ||
comp.VerifyDiagnostics( | ||
// (6,15): error CS0122: 'C.M()' is inaccessible due to its protection level | ||
// new C().M(); | ||
Diagnostic(ErrorCode.ERR_BadAccess, "M").WithArguments("C.M()").WithLocation(6, 15), | ||
// (7,40): error CS0122: 'C.F' is inaccessible due to its protection level | ||
// System.Console.WriteLine(new C().F); | ||
Diagnostic(ErrorCode.ERR_BadAccess, "F").WithArguments("C.F").WithLocation(7, 40), | ||
// (8,13): error CS0122: 'C.C2' is inaccessible due to its protection level | ||
// new C.C2().M2(); | ||
Diagnostic(ErrorCode.ERR_BadAccess, "C2").WithArguments("C.C2").WithLocation(8, 13) | ||
); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,235 @@ | ||
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
// This relates to VSO bug 217681 https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_workitems?id=217681 | ||
// The code below is compiled with a modified compiler such that MetadataWriter will set both public and private flags on M, F, C2 and M2. | ||
// But the constructors should be left public. | ||
// You can also see the resulting meta info at the bottom | ||
|
||
public class C | ||
{ | ||
public void M() { System.Console.WriteLine("I am C!"); } | ||
public int F = 42; | ||
|
||
public class C2 | ||
{ | ||
public void M2() { System.Console.WriteLine("I am C2!"); } | ||
} | ||
} | ||
|
||
string metainfo = @" | ||
=========================================================== | ||
ScopeName : public-and-private.dll | ||
MVID : {3C7CF08B-32C8-4C36-BD58-85DEB7FA5843} | ||
=========================================================== | ||
Global functions | ||
------------------------------------------------------- | ||
|
||
Global fields | ||
------------------------------------------------------- | ||
|
||
Global MemberRefs | ||
------------------------------------------------------- | ||
|
||
TypeDef #1 (02000002) | ||
------------------------------------------------------- | ||
TypDefName: C (02000002) | ||
Flags : [Public] [AutoLayout] [Class] [AnsiClass] [BeforeFieldInit] (00100001) | ||
Extends : 01000005 [TypeRef] System.Object | ||
Field #1 (04000001) | ||
------------------------------------------------------- | ||
Field Name: F (04000001) | ||
Flags : [none] (00000007) | ||
CallCnvntn: [FIELD] | ||
Field type: I4 | ||
|
||
Method #1 (06000001) | ||
------------------------------------------------------- | ||
MethodName: M (06000001) | ||
Flags : [HideBySig] [ReuseSlot] (00000087) | ||
RVA : 0x00002050 | ||
ImplFlags : [IL] [Managed] (00000000) | ||
CallCnvntn: [DEFAULT] | ||
hasThis | ||
ReturnType: Void | ||
No arguments. | ||
|
||
Method #2 (06000002) | ||
------------------------------------------------------- | ||
MethodName: .ctor (06000002) | ||
Flags : [Public] [HideBySig] [ReuseSlot] [SpecialName] [RTSpecialName] [.ctor] (00001886) | ||
RVA : 0x0000205e | ||
ImplFlags : [IL] [Managed] (00000000) | ||
CallCnvntn: [DEFAULT] | ||
hasThis | ||
ReturnType: Void | ||
No arguments. | ||
|
||
|
||
TypeDef #2 (02000003) | ||
------------------------------------------------------- | ||
TypDefName: C2 (02000003) | ||
Flags : [NestedFamORAssem] [AutoLayout] [Class] [AnsiClass] [BeforeFieldInit] (00100007) | ||
Extends : 01000005 [TypeRef] System.Object | ||
EnclosingClass : C (02000002) | ||
Method #1 (06000003) | ||
------------------------------------------------------- | ||
MethodName: M2 (06000003) | ||
Flags : [HideBySig] [ReuseSlot] (00000087) | ||
RVA : 0x0000206f | ||
ImplFlags : [IL] [Managed] (00000000) | ||
CallCnvntn: [DEFAULT] | ||
hasThis | ||
ReturnType: Void | ||
No arguments. | ||
|
||
Method #2 (06000004) | ||
------------------------------------------------------- | ||
MethodName: .ctor (06000004) | ||
Flags : [Public] [HideBySig] [ReuseSlot] [SpecialName] [RTSpecialName] [.ctor] (00001886) | ||
RVA : 0x0000207d | ||
ImplFlags : [IL] [Managed] (00000000) | ||
CallCnvntn: [DEFAULT] | ||
hasThis | ||
ReturnType: Void | ||
No arguments. | ||
|
||
|
||
TypeRef #1 (01000001) | ||
------------------------------------------------------- | ||
Token: 0x01000001 | ||
ResolutionScope: 0x23000001 | ||
TypeRefName: System.Runtime.CompilerServices.CompilationRelaxationsAttribute | ||
MemberRef #1 (0a000001) | ||
------------------------------------------------------- | ||
Member: (0a000001) .ctor: | ||
CallCnvntn: [DEFAULT] | ||
hasThis | ||
ReturnType: Void | ||
1 Arguments | ||
Argument #1: I4 | ||
|
||
TypeRef #2 (01000002) | ||
------------------------------------------------------- | ||
Token: 0x01000002 | ||
ResolutionScope: 0x23000001 | ||
TypeRefName: System.Runtime.CompilerServices.RuntimeCompatibilityAttribute | ||
MemberRef #1 (0a000002) | ||
------------------------------------------------------- | ||
Member: (0a000002) .ctor: | ||
CallCnvntn: [DEFAULT] | ||
hasThis | ||
ReturnType: Void | ||
No arguments. | ||
|
||
TypeRef #3 (01000003) | ||
------------------------------------------------------- | ||
Token: 0x01000003 | ||
ResolutionScope: 0x23000001 | ||
TypeRefName: System.Diagnostics.DebuggableAttribute | ||
MemberRef #1 (0a000003) | ||
------------------------------------------------------- | ||
Member: (0a000003) .ctor: | ||
CallCnvntn: [DEFAULT] | ||
hasThis | ||
ReturnType: Void | ||
1 Arguments | ||
Argument #1: ValueClass DebuggingModes | ||
|
||
TypeRef #4 (01000004) | ||
------------------------------------------------------- | ||
Token: 0x01000004 | ||
ResolutionScope: 0x01000003 | ||
TypeRefName: DebuggingModes | ||
|
||
TypeRef #5 (01000005) | ||
------------------------------------------------------- | ||
Token: 0x01000005 | ||
ResolutionScope: 0x23000001 | ||
TypeRefName: System.Object | ||
MemberRef #1 (0a000005) | ||
------------------------------------------------------- | ||
Member: (0a000005) .ctor: | ||
CallCnvntn: [DEFAULT] | ||
hasThis | ||
ReturnType: Void | ||
No arguments. | ||
|
||
TypeRef #6 (01000006) | ||
------------------------------------------------------- | ||
Token: 0x01000006 | ||
ResolutionScope: 0x23000001 | ||
TypeRefName: System.Console | ||
MemberRef #1 (0a000004) | ||
------------------------------------------------------- | ||
Member: (0a000004) WriteLine: | ||
CallCnvntn: [DEFAULT] | ||
ReturnType: Void | ||
1 Arguments | ||
Argument #1: String | ||
|
||
Assembly | ||
------------------------------------------------------- | ||
Token: 0x20000001 | ||
Name : public-and-private | ||
Public Key : | ||
Hash Algorithm : 0x00008004 | ||
Version: 0.0.0.0 | ||
Major Version: 0x00000000 | ||
Minor Version: 0x00000000 | ||
Build Number: 0x00000000 | ||
Revision Number: 0x00000000 | ||
Locale: <null> | ||
Flags : [none] (00000000) | ||
CustomAttribute #1 (0c000001) | ||
------------------------------------------------------- | ||
CustomAttribute Type: 0a000001 | ||
CustomAttributeName: System.Runtime.CompilerServices.CompilationRelaxationsAttribute :: instance void .ctor(int32) | ||
Length: 8 | ||
Value : 01 00 08 00 00 00 00 00 > < | ||
ctor args: (8) | ||
|
||
CustomAttribute #2 (0c000002) | ||
------------------------------------------------------- | ||
CustomAttribute Type: 0a000002 | ||
CustomAttributeName: System.Runtime.CompilerServices.RuntimeCompatibilityAttribute :: instance void .ctor() | ||
Length: 30 | ||
Value : 01 00 01 00 54 02 16 57 72 61 70 4e 6f 6e 45 78 > T WrapNonEx< | ||
: 63 65 70 74 69 6f 6e 54 68 72 6f 77 73 01 >ceptionThrows < | ||
ctor args: () | ||
|
||
CustomAttribute #3 (0c000003) | ||
------------------------------------------------------- | ||
CustomAttribute Type: 0a000003 | ||
CustomAttributeName: System.Diagnostics.DebuggableAttribute :: instance void .ctor(value class DebuggingModes) | ||
Length: 8 | ||
Value : 01 00 07 01 00 00 00 00 > < | ||
ctor args: ( <can not decode> ) | ||
|
||
|
||
AssemblyRef #1 (23000001) | ||
------------------------------------------------------- | ||
Token: 0x23000001 | ||
Public Key or Token: b7 7a 5c 56 19 34 e0 89 | ||
Name: mscorlib | ||
Version: 4.0.0.0 | ||
Major Version: 0x00000004 | ||
Minor Version: 0x00000000 | ||
Build Number: 0x00000000 | ||
Revision Number: 0x00000000 | ||
Locale: <null> | ||
HashValue Blob: | ||
Flags: [none] (00000000) | ||
|
||
|
||
User Strings | ||
------------------------------------------------------- | ||
70000001 : ( 7) L""I am C!"" | ||
70000011 : ( 8) L""I am C2!"" | ||
|
||
|
||
Coff symbol name overhead: 0 | ||
=========================================================== | ||
=========================================================== | ||
=========================================================== | ||
|
||
"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,8 @@ Imports Microsoft.CodeAnalysis.Collections | |
Imports Microsoft.CodeAnalysis.Test.Utilities | ||
Imports Microsoft.CodeAnalysis.Text | ||
Imports Microsoft.CodeAnalysis.VisualBasic | ||
Imports Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE | ||
Imports Microsoft.CodeAnalysis.VisualBasic.Symbols | ||
Imports Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE | ||
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax | ||
Imports Roslyn.Test.Utilities | ||
|
||
|
@@ -925,5 +925,35 @@ BC30657: 'VT' has a return type that is not supported or parameter types that ar | |
~~ | ||
]]>) | ||
End Sub | ||
|
||
<Fact, WorkItem(217681, "https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_workitems?id=217681")> | ||
Public Sub LoadingMethodWithPublicAndPrivateAccessibility() | ||
Dim source = | ||
<compilation> | ||
<file> | ||
Class D | ||
Shared Sub Main() | ||
Dim test = new C() | ||
test.M() | ||
System.Console.WriteLine(test.F) | ||
|
||
Dim test2 = new C.C2() | ||
test2.M2() | ||
End Sub | ||
End Class | ||
</file> | ||
</compilation> | ||
|
||
Dim references = {MetadataReference.CreateFromImage(TestResources.SymbolsTests.Metadata.PublicAndPrivateFlags)} | ||
|
||
Dim comp = CreateCompilationWithMscorlib(source, references:=references) | ||
comp.VerifyDiagnostics( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use AssertTheseDiagnostics helper instead. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the advantage of this method over the current approach? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jaredpar It captures more details about the diagnostics and seems more readable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jaredpar This is the preferred way to baseline diagnostics for VB (human readable with squiggle). See the previous unit-test, for example. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gotcha. |
||
Diagnostic(ERRID.ERR_InaccessibleMember3, "test.M").WithArguments("C", "Private Overloads Sub M()", "Private").WithLocation(4, 7), | ||
Diagnostic(ERRID.ERR_InaccessibleSymbol2, "test.F").WithArguments("C.F", "Private").WithLocation(5, 32), | ||
Diagnostic(ERRID.ERR_InaccessibleSymbol2, "C.C2").WithArguments("C.C2", "Protected Friend").WithLocation(7, 23), | ||
Diagnostic(ERRID.ERR_InaccessibleMember3, "test2.M2").WithArguments("C2", "Private Overloads Sub M2()", "Private").WithLocation(8, 7) | ||
) | ||
End Sub | ||
|
||
End Class | ||
End Namespace |
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.
This bug was meant to cover
public + private
accessibility flags. This change expands it to all forms of accessibility not caught above. Is that intentional?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.
There are only eight values possible
In reply to: 64623823 [](ancestors = 64623823)
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.
See the mask at the top of the switch case. The default case only covered this one remaining value.
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.
Gotcha.