Esempio n. 1
0
        private NamedTypeSymbol MakeAcyclicBaseType(DiagnosticBag diagnostics)
        {
            var             typeKind    = this.TypeKind;
            var             compilation = this.DeclaringCompilation;
            NamedTypeSymbol declaredBase;

            if (typeKind == TypeKind.Enum)
            {
                Debug.Assert((object)GetDeclaredBaseType(basesBeingResolved: null) == null, "Computation skipped for enums");
                declaredBase = compilation.GetSpecialType(SpecialType.System_Enum);
            }
            else
            {
                declaredBase = GetDeclaredBaseType(basesBeingResolved: null);
            }

            if ((object)declaredBase == null)
            {
                switch (typeKind)
                {
                case TypeKind.Class:

                    if (this.SpecialType == SpecialType.System_Object)
                    {
                        return(null);
                    }

                    declaredBase = compilation.GetSpecialType(SpecialType.System_Object);
                    break;

                case TypeKind.Struct:
                    declaredBase = compilation.GetSpecialType(SpecialType.System_ValueType);
                    break;

                case TypeKind.Interface:
                    return(null);

                case TypeKind.Delegate:
                    declaredBase = compilation.GetSpecialType(SpecialType.System_MulticastDelegate);
                    break;

                default:
                    throw ExceptionUtilities.UnexpectedValue(typeKind);
                }
            }

            if (BaseTypeAnalysis.ClassDependsOn(declaredBase, this))
            {
                return(new ExtendedErrorTypeSymbol(declaredBase, LookupResultKind.NotReferencable,
                                                   diagnostics.Add(ErrorCode.ERR_CircularBase, Locations[0], declaredBase, this)));
            }

            this.SetKnownToHaveNoDeclaredBaseCycles();

            HashSet <DiagnosticInfo> useSiteDiagnostics = null;
            NamedTypeSymbol          current            = declaredBase;

            do
            {
                if (current.DeclaringCompilation == this.DeclaringCompilation)
                {
                    break;
                }

                current.AddUseSiteDiagnostics(ref useSiteDiagnostics);
                current = current.BaseTypeNoUseSiteDiagnostics;
            }while ((object)current != null);

            if (!useSiteDiagnostics.IsNullOrEmpty())
            {
                diagnostics.Add(FindBaseRefSyntax(declaredBase) ?? Locations[0], useSiteDiagnostics);
            }

            return(declaredBase);
        }