Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static TestClassModel Build(INamedTypeSymbol typeSymbol, List<DiagnosticI
// its members (e.g. base-declared [ClassInitialize]/[TestContext]) via [DynamicDependency]
// under trimming / Native AOT. Members are folded into the leaf model, but the trimmer
// only keeps members of the concrete type unless the base is rooted explicitly too.
if (!isLeaf && !current.IsGenericType && IsTypeReachableFromGeneratedCode(current))
if (!isLeaf && !current.IsGenericType && SymbolAccessibilityHelper.IsAccessibleFromGeneratedCode(current))
{
baseTypes.Add(current.ToDisplayString(FullyQualifiedFormat));
}
Expand Down Expand Up @@ -133,29 +133,6 @@ when IsAccessibleFromConsumer(method):
BaseTypeFullyQualifiedNames: new EquatableArray<string>(baseTypes.ToImmutable()));
}

// The generated registration lives in the same assembly as the test class, so a type is
// reachable when it (and every enclosing type) is at least internal and not file-local.
private static bool IsTypeReachableFromGeneratedCode(INamedTypeSymbol type)
{
for (INamedTypeSymbol? current = type; current is not null; current = current.ContainingType)
{
if (current.IsFileLocal)
{
return false;
}

switch (current.DeclaredAccessibility)
{
case Accessibility.Private:
case Accessibility.Protected:
case Accessibility.ProtectedAndInternal:
return false;
}
}

return true;
}

private static bool IsTestMethodAttributePresent(IMethodSymbol method)
{
foreach (AttributeData attribute in method.GetAttributes())
Expand Down
Loading