Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 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
5 changes: 4 additions & 1 deletion src/Compilers/CSharp/Portable/CSharpResources.resx
Comment thread
stbau04 marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -8202,4 +8202,7 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<data name="ERR_ExplicitInterfaceMemberReturnTypeMismatch" xml:space="preserve">
<value>'{0}': return type must be '{1}' to match implemented member '{2}'</value>
</data>
</root>
<data name="ERR_BadVisBaseType" xml:space="preserve">
<value>Inconsistent accessibility: type '{1}' is less accessible than class '{0}' </value>
</data>
</root>
1 change: 1 addition & 0 deletions src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2429,6 +2429,7 @@ internal enum ErrorCode
ERR_BadSpreadInCatchFilter = 9332,
ERR_ExplicitInterfaceMemberTypeMismatch = 9333,
ERR_ExplicitInterfaceMemberReturnTypeMismatch = 9334,
ERR_BadVisBaseType = 9335,

// Note: you will need to do the following after adding errors:
// 1) Update ErrorFacts.IsBuildOnlyDiagnostic (src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs)
Expand Down
1 change: 1 addition & 0 deletions src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2538,6 +2538,7 @@ or ErrorCode.ERR_AttributeCannotBeAppliedManually
or ErrorCode.ERR_BadSpreadInCatchFilter
or ErrorCode.ERR_ExplicitInterfaceMemberTypeMismatch
or ErrorCode.ERR_ExplicitInterfaceMemberReturnTypeMismatch
or ErrorCode.ERR_BadVisBaseType
=> false,
};
#pragma warning restore CS8524 // The switch expression does not handle some values of its input type (it is not exhaustive) involving an unnamed enum value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,20 @@ static bool containsOnlyOblivious(TypeSymbol type)
diagnostics.Add(ErrorCode.ERR_StaticBaseClass, baseTypeLocation, baseType, this);
}

if (!this.IsNoMoreVisibleThan(baseType, ref useSiteInfo))
var lessVisibleTypes = this.FindAllLessVisible(baseType, ref useSiteInfo);
foreach (var lessVisibleType in lessVisibleTypes)
{
// Inconsistent accessibility: base class '{1}' is less accessible than class '{0}'
diagnostics.Add(ErrorCode.ERR_BadVisBaseClass, baseTypeLocation, this, baseType);
if (Equals(baseType, lessVisibleType, TypeCompareKind.ConsiderEverything))
Comment thread
stbau04 marked this conversation as resolved.
Outdated
Comment thread
stbau04 marked this conversation as resolved.
Outdated
{
// Inconsistent accessibility: base class '{1}' is less accessible than class '{0}'
diagnostics.Add(ErrorCode.ERR_BadVisBaseClass, baseTypeLocation, this, lessVisibleType);
}
else
{
// Inconsistent accessibility: type '{1}' is less accessible than class '{0}'
var lessVisibleTypeLocation = lessVisibleType.GetFirstLocation();
diagnostics.Add(ErrorCode.ERR_BadVisBaseType, baseTypeLocation, this, lessVisibleType);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you intend to use lessVisibleTypeLocation instead of baseTypeLocation in the diagnostics entry?

@stbau04 stbau04 Oct 20, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iirc lessVisibleTypeLocation is the location of the type definition. So it would not be intended to be used instead of the baseTypeLocation, but the variable is not used anywhere so i guess the declaration can be removed #80823

}
}

if (baseType.HasFileLocalTypes() && !this.HasFileLocalTypes())
Expand Down
35 changes: 35 additions & 0 deletions src/Compilers/CSharp/Portable/Symbols/TypeSymbolExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,41 @@ public static bool IsAtLeastAsVisibleAs(this TypeSymbol type, Symbol sym, ref Co
}
}

public static List<TypeSymbol> FindAllLessVisible(this TypeSymbol type, TypeSymbol sym, ref CompoundUseSiteInfo<AssemblySymbol> useSiteInfo)
Comment thread
stbau04 marked this conversation as resolved.
Outdated
{
List<TypeSymbol> result = [];
var visitTypeData = s_visitTypeDataPool.Allocate();

try
{
visitTypeData.UseSiteInfo = useSiteInfo;
visitTypeData.Symbol = type;

sym.VisitType(addToResultIfLessVisibleAndContinueSearchPredicate,
arg: visitTypeData,
canDigThroughNullable: true); // System.Nullable is public

useSiteInfo = visitTypeData.UseSiteInfo;
return result;
}
finally
{
visitTypeData.UseSiteInfo = default;
visitTypeData.Symbol = null;
s_visitTypeDataPool.Free(visitTypeData);
}

bool addToResultIfLessVisibleAndContinueSearchPredicate(TypeSymbol type1, VisitTypeData arg, bool unused)
{
if (IsTypeLessVisibleThan(type1, arg.Symbol!, ref arg.UseSiteInfo))
{
result.Add(type1);
}

return false;
}
}

private static bool IsTypeLessVisibleThan(TypeSymbol type, Symbol sym, ref CompoundUseSiteInfo<AssemblySymbol> useSiteInfo)
{
switch (type.TypeKind)
Expand Down
7 changes: 6 additions & 1 deletion src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading