Repository: dotnet/roslyn
File: src/Compilers/CSharp/Portable/Symbols/Source/SourceNamedTypeSymbol_Bases.cs (C#)

Code before:
                        diagnostics.Add(ErrorCode.ERR_DeriveFromDynamic, location, this);
                        continue;

                    case TypeKind.Submission:
                        throw ExceptionUtilities.UnexpectedValue(baseType.TypeKind);

                    default:
                        diagnostics.Add(ErrorCode.ERR_NonInterfaceInInterfaceList, location, baseType);
                        continue;
                }
            }

            if (this.SpecialType == SpecialType.System_Object && ((object)localBase != null || localInterfaces.Count != 0))
            {
                var name = GetName(bases.Parent);
                diagnostics.Add(ErrorCode.ERR_ObjectCantHaveBases, new SourceLocation(name));
            }

            return new Tuple<NamedTypeSymbol, ImmutableArray<NamedTypeSymbol>>(localBase, localInterfaces.ToImmutableAndFree());

            void checkPrimaryConstructorBaseType(BaseTypeSyntax baseTypeSyntax, TypeSymbol baseType)
            {
                if (baseTypeSyntax is PrimaryConstructorBaseTypeSyntax primaryConstructorBaseType)
                {
                    // Check if this is a class inheriting from a class but missing a parameter list
                    if (TypeKind == TypeKind.Class &&
                        baseType.TypeKind != TypeKind.Interface &&
                        decl.SyntaxReference.GetSyntax() is TypeDeclarationSyntax { ParameterList: null })
                    {
                        diagnostics.Add(ErrorCode.ERR_UnexpectedArgumentListInBaseTypeWithoutParameterList,
                            primaryConstructorBaseType.ArgumentList.Location,
                            this.Name);
                    }
                    // Other cases where argument lists are not allowed
                    else if (TypeKind != TypeKind.Class || baseType.TypeKind == TypeKind.Interface)
                    {
                        diagnostics.Add(ErrorCode.ERR_UnexpectedArgumentList, primaryConstructorBaseType.ArgumentList.Location);
                    }
                }
            }
        }

        /// <summary>
        /// Returns true if the type cannot be used as an explicit base class.
        /// </summary>
        private static bool IsRestrictedBaseType(SpecialType specialType)
        {
            switch (specialType)
            {
                case SpecialType.System_Array:
                case SpecialType.System_Enum:

Review comment (suggestion):
>if (TypeKind == TypeKind.Class && [](http://example.com/codeflow?start=20&length=33)

I think the code will be much simpler and much easier to follow if it was structured like:
```
if (TypeKind != TypeKind.Class || baseType.TypeKind == TypeKind.Interface)
{
    ...
}
else if (((TypeDeclarationSyntax)decl.SyntaxReference.GetSyntax()).ParameterList is null)
{
    ...
}
```
 #Closed

Code after:
                        diagnostics.Add(ErrorCode.ERR_DeriveFromDynamic, location, this);
                        continue;

                    case TypeKind.Submission:
                        throw ExceptionUtilities.UnexpectedValue(baseType.TypeKind);

                    default:
                        diagnostics.Add(ErrorCode.ERR_NonInterfaceInInterfaceList, location, baseType);
                        continue;
                }
            }

            if (this.SpecialType == SpecialType.System_Object && ((object)localBase != null || localInterfaces.Count != 0))
            {
                var name = GetName(bases.Parent);
                diagnostics.Add(ErrorCode.ERR_ObjectCantHaveBases, new SourceLocation(name));
            }

            return new Tuple<NamedTypeSymbol, ImmutableArray<NamedTypeSymbol>>(localBase, localInterfaces.ToImmutableAndFree());

            void checkPrimaryConstructorBaseType(BaseTypeSyntax baseTypeSyntax, TypeSymbol baseType)
            {
                if (baseTypeSyntax is PrimaryConstructorBaseTypeSyntax primaryConstructorBaseType)
                {
                    if (TypeKind != TypeKind.Class || baseType.TypeKind == TypeKind.Interface)
                    {
                        diagnostics.Add(ErrorCode.ERR_UnexpectedArgumentList, primaryConstructorBaseType.ArgumentList.Location);
                    }
                    else if (((TypeDeclarationSyntax)decl.SyntaxReference.GetSyntax()).ParameterList is null)
                    {
                        diagnostics.Add(ErrorCode.ERR_UnexpectedArgumentListInBaseTypeWithoutParameterList, primaryConstructorBaseType.ArgumentList.Location);
                    }
                }
            }
        }

        /// <summary>
        /// Returns true if the type cannot be used as an explicit base class.
        /// </summary>
        private static bool IsRestrictedBaseType(SpecialType specialType)
        {
            switch (specialType)
            {
                case SpecialType.System_Array:
                case SpecialType.System_Enum:
                case SpecialType.System_Delegate:
                case SpecialType.System_MulticastDelegate:
                case SpecialType.System_ValueType:
                    return true;
            }