Browse Source

#3134: A bug in DetermineEffectiveAccessibility prevented references from the enclosing type to public members of private nested types to be found.

pull/3138/head
Siegfried Pammer 2 years ago
parent
commit
1ab03508f5
  1. 38
      ILSpy/Analyzers/AnalyzerScope.cs

38
ILSpy/Analyzers/AnalyzerScope.cs

@ -54,16 +54,7 @@ namespace ICSharpCode.ILSpy.Analyzers
AssemblyList = assemblyList; AssemblyList = assemblyList;
assemblyListSnapshot = assemblyList.GetSnapshot(); assemblyListSnapshot = assemblyList.GetSnapshot();
AnalyzedSymbol = entity; AnalyzedSymbol = entity;
if (entity is ITypeDefinition type) DetermineEffectiveAccessibility(entity, out typeScope, out effectiveAccessibility);
{
typeScope = type;
effectiveAccessibility = DetermineEffectiveAccessibility(ref typeScope, Accessibility.Public);
}
else
{
typeScope = entity.DeclaringTypeDefinition;
effectiveAccessibility = DetermineEffectiveAccessibility(ref typeScope, entity.Accessibility);
}
IsLocal = effectiveAccessibility.LessThanOrEqual(Accessibility.Private); IsLocal = effectiveAccessibility.LessThanOrEqual(Accessibility.Private);
} }
@ -112,20 +103,31 @@ namespace ICSharpCode.ILSpy.Analyzers
} }
} }
static Accessibility DetermineEffectiveAccessibility(ref ITypeDefinition typeScope, Accessibility memberAccessibility) static void DetermineEffectiveAccessibility(IEntity input, out ITypeDefinition typeScope, out Accessibility accessibility)
{
if (input is ITypeDefinition td)
{ {
Accessibility accessibility = memberAccessibility; accessibility = Accessibility.Public;
var ts = typeScope; typeScope = td;
while (ts != null && !accessibility.LessThanOrEqual(Accessibility.Private)) }
else
{ {
accessibility = accessibility.Intersect(ts.Accessibility); accessibility = input.Accessibility;
typeScope = ts; typeScope = input.DeclaringTypeDefinition;
ts = ts.DeclaringTypeDefinition;
} }
// Once we reach a private entity, we leave the loop with typeScope set to the class that // Once we reach a private entity, we leave the loop with typeScope set to the class that
// contains the private entity = the scope that needs to be searched. // contains the private entity = the scope that needs to be searched.
// Otherwise (if we don't find a private entity) we return the top-level class. // Otherwise (if we don't find a private entity) we return the top-level class.
return accessibility; var prevTypeScope = typeScope;
while (typeScope != null && !accessibility.LessThanOrEqual(Accessibility.Private))
{
accessibility = accessibility.Intersect(typeScope.Accessibility);
typeScope = prevTypeScope.DeclaringTypeDefinition;
}
if (typeScope == null)
{
typeScope = prevTypeScope;
}
} }
#region Find modules #region Find modules

Loading…
Cancel
Save