-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Open
Description
The docs for ITypeSymbol.BaseType explicitly state:
The base type of a type parameter is its effective base class.
However, in practice, this does not appear to be true. For example, when given the following code:
abstract class Base
{
public abstract void Method();
}
class Derived<T> : Base where T : Base
{
T inner;
}The ITypeParameterSymbol for T returns null for BaseType.
Debugging through, this appears to be very explicit:
ITypeSymbol.BaseType is:
INamedTypeSymbol ITypeSymbol.BaseType
{
get
{
return UnderlyingTypeSymbol.BaseTypeNoUseSiteDiagnostics.GetPublicSymbol();
}
}And BaseTypeNoUseSiteDiagnostics is defined for all TypeParameters with this sealed override:
internal sealed override NamedTypeSymbol BaseTypeNoUseSiteDiagnostics => null;Now, TypeParameterSymbol also has:
/// <summary>
/// The effective base class of the type parameter (spec 10.1.5). If the deduced
/// base type is a reference type, the effective base type will be the same as
/// the deduced base type. Otherwise if the deduced base type is a value type,
/// the effective base type will be the most derived reference type from which
/// deduced base type is derived.
/// </summary>
internal NamedTypeSymbol EffectiveBaseClassNoUseSiteDiagnosticsOne of two things seems to be going on here:
- we actually want ITypeParameterSymbol.BaseType to return null (in which case we need to update the docs).
- The docs are correct, but the impl is incorrect. In which case we could consider fixing (though it's unclear what the implications of that might be).
jnm2Copilot