-
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
Diagnostic Improvements for error #0281 #27052
Changes from 5 commits
37ed85e
6eb8ea7
de25429
ee189b0
ab9faaf
af6f5ac
0b3c9f1
080de89
3191a12
44e6815
e24f1a6
cf7eb19
200acb1
816472a
6f57496
56bb172
7eba065
72b880a
28f0a80
15176b2
6a36501
e9baab9
b095767
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 |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
using System.Collections.Immutable; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using Microsoft.CodeAnalysis.Collections; | ||
using Microsoft.CodeAnalysis.CSharp.Symbols; | ||
using Microsoft.CodeAnalysis.PooledObjects; | ||
using Roslyn.Utilities; | ||
|
@@ -1154,15 +1153,16 @@ internal SingleLookupResult CheckViability(Symbol symbol, int arity, LookupOptio | |
ref useSiteDiagnostics, | ||
basesBeingResolved)) | ||
{ | ||
if (inaccessibleViaQualifier) | ||
{ | ||
diagInfo = diagnose ? new CSDiagnosticInfo(ErrorCode.ERR_BadProtectedAccess, unwrappedSymbol, accessThroughType, this.ContainingType) : null; | ||
} | ||
else | ||
{ | ||
var unwrappedSymbols = ImmutableArray.Create<Symbol>(unwrappedSymbol); | ||
diagInfo = diagnose ? new CSDiagnosticInfo(ErrorCode.ERR_BadAccess, new[] { unwrappedSymbol }, unwrappedSymbols, additionalLocations: ImmutableArray<Location>.Empty) : null; | ||
} | ||
bool friendRefNotEqualToThis = getFriendRefNotEqualToThis(); | ||
|
||
diagInfo = diagnose ? | ||
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. I'm not sure this is what @cston had in mind. I think he just wanted the |
||
inaccessibleViaQualifier ? | ||
new CSDiagnosticInfo(ErrorCode.ERR_BadProtectedAccess, unwrappedSymbol, accessThroughType, this.ContainingType) : | ||
friendRefNotEqualToThis ? | ||
new CSDiagnosticInfo(ErrorCode.ERR_FriendRefNotEqualToThis, unwrappedSymbol.ContainingAssembly.Identity.ToString(), AssemblyIdentity.PublicKeyToString(this.ContainingType.ContainingAssembly.PublicKey)) : | ||
new CSDiagnosticInfo(ErrorCode.ERR_BadAccess, new[] { unwrappedSymbol }, ImmutableArray.Create<Symbol>(unwrappedSymbol), additionalLocations: ImmutableArray<Location>.Empty) : | ||
null; | ||
|
||
|
||
return LookupResult.Inaccessible(symbol, diagInfo); | ||
} | ||
|
@@ -1195,8 +1195,25 @@ internal SingleLookupResult CheckViability(Symbol symbol, int arity, LookupOptio | |
{ | ||
return LookupResult.Good(symbol); | ||
} | ||
} | ||
|
||
bool getFriendRefNotEqualToThis() | ||
{ | ||
if (inaccessibleViaQualifier) | ||
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. I think this check should be outside of the local funciton. |
||
{ | ||
return false; | ||
} | ||
bool temp = unwrappedSymbol != null | ||
&& this.ContainingType.ContainingAssembly.Name != null | ||
&& unwrappedSymbol.ContainingAssembly.GetInternalsVisibleToPublicKeys(this.ContainingType.ContainingAssembly.Name).Any() | ||
&& unwrappedSymbol.DeclaredAccessibility == Accessibility.Internal; | ||
foreach (ImmutableArray<byte> key in unwrappedSymbol.ContainingAssembly.GetInternalsVisibleToPublicKeys(this.ContainingType.ContainingAssembly.Name)) | ||
{ | ||
temp = key.SequenceEqual(this.ContainingType.ContainingAssembly.Identity.PublicKey) ? false : temp; | ||
} | ||
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. Is this |
||
return temp; | ||
} | ||
} | ||
|
||
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. Accidental whitespace change. |
||
private CSDiagnosticInfo MakeCallMethodsDirectlyDiagnostic(Symbol symbol) | ||
{ | ||
Debug.Assert(symbol.MustCallMethodsDirectly()); | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1909,7 +1909,7 @@ private void CheckOptimisticIVTAccessGrants(DiagnosticBag bag) | |
|
||
if (conclusion == IVTConclusion.PublicKeyDoesntMatch) | ||
bag.Add(ErrorCode.ERR_FriendRefNotEqualToThis, NoLocation.Singleton, | ||
otherAssembly.Identity); | ||
otherAssembly.Identity.ToString(), this.ContainingAssembly.Identity.ToString()); | ||
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. I don't believe we should be calling 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.
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. Why use 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. I usually prefer to be explicit on how things get serialized to strings -- Jared's comment reflects that this is usually a very deliberate decision and being explicit signals intent better, IMHO. |
||
else if (conclusion == IVTConclusion.OneSignedOneNot) | ||
bag.Add(ErrorCode.ERR_FriendRefSigningMismatch, NoLocation.Singleton, | ||
otherAssembly.Identity); | ||
|
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.
Calling it up front means we still pay for the execution. I would inline this call.