-
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
Merged
+321
−6
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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 |
---|---|---|
|
@@ -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) | ||
); | ||
} | ||
} | ||
} |
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
235 changes: 235 additions & 0 deletions
235
src/Compilers/Test/Resources/Core/SymbolsTests/Metadata/public-and-private.cs
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,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 | ||
=========================================================== | ||
=========================================================== | ||
=========================================================== | ||
|
||
"; |
Binary file added
BIN
+3.5 KB
src/Compilers/Test/Resources/Core/SymbolsTests/Metadata/public-and-private.dll
Binary file not shown.
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
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
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.
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.