protected override void CheckBase(DiagnosticBag diagnostics) { var localBase = this.BaseTypeNoUseSiteDiagnostics; if ((object)localBase == null) { // nothing to verify return; } Location baseLocation = null; bool baseContainsErrorTypes = localBase.ContainsErrorType(); if (!baseContainsErrorTypes) { baseLocation = FindBaseRefSyntax(localBase); Debug.Assert(!this.IsClassType() || localBase.IsObjectType() || baseLocation != null); } // you need to know all bases before you can ask this question... (asking this causes a cycle) if (this.IsGenericType && !baseContainsErrorTypes && this.DeclaringCompilation.IsAttributeType(localBase)) { // A generic type cannot derive from '{0}' because it is an attribute class diagnostics.Add(ErrorCode.ERR_GenericDerivingFromAttribute, baseLocation, localBase); } // Check constraints on the first declaration with explicit bases. var singleDeclaration = this.FirstDeclarationWithExplicitBases(); if (singleDeclaration != null) { var corLibrary = this.ContainingAssembly.CorLibrary; var conversions = new TypeConversions(corLibrary); var location = singleDeclaration.NameLocation; localBase.CheckAllConstraints(DeclaringCompilation, conversions, location, diagnostics); } // Records can only inherit from other records or object if (this.IsClassType() && !localBase.IsObjectType() && !baseContainsErrorTypes) { HashSet <DiagnosticInfo> useSiteDiagnostics = null; if (declaration.Kind == DeclarationKind.Record) { if (SynthesizedRecordClone.FindValidCloneMethod(localBase, ref useSiteDiagnostics) is null || SynthesizedRecordPrintMembers.FindValidPrintMembersMethod(localBase, DeclaringCompilation) is null) { diagnostics.Add(ErrorCode.ERR_BadRecordBase, baseLocation); } } else if (SynthesizedRecordClone.FindValidCloneMethod(localBase, ref useSiteDiagnostics) is object) { diagnostics.Add(ErrorCode.ERR_BadInheritanceFromRecord, baseLocation); } diagnostics.Add(baseLocation, useSiteDiagnostics); } }
protected override void CheckBase(BindingDiagnosticBag diagnostics) { var localBase = this.BaseTypeNoUseSiteDiagnostics; if ((object)localBase == null) { // nothing to verify return; } Location baseLocation = null; bool baseContainsErrorTypes = localBase.ContainsErrorType(); if (!baseContainsErrorTypes) { baseLocation = FindBaseRefSyntax(localBase); Debug.Assert(!this.IsClassType() || localBase.IsObjectType() || baseLocation != null); } // you need to know all bases before you can ask this question... (asking this causes a cycle) if (this.IsGenericType && !baseContainsErrorTypes && this.DeclaringCompilation.IsAttributeType(localBase)) { MessageID.IDS_FeatureGenericAttributes.CheckFeatureAvailability(diagnostics, this.DeclaringCompilation, baseLocation); } // Check constraints on the first declaration with explicit bases. var singleDeclaration = this.FirstDeclarationWithExplicitBases(); if (singleDeclaration != null) { var corLibrary = this.ContainingAssembly.CorLibrary; var conversions = new TypeConversions(corLibrary); var location = singleDeclaration.NameLocation; localBase.CheckAllConstraints(DeclaringCompilation, conversions, location, diagnostics); } // Records can only inherit from other records or object if (this.IsClassType() && !localBase.IsObjectType() && !baseContainsErrorTypes) { var useSiteInfo = new CompoundUseSiteInfo <AssemblySymbol>(diagnostics, ContainingAssembly); if (declaration.Kind == DeclarationKind.Record) { if (SynthesizedRecordClone.FindValidCloneMethod(localBase, ref useSiteInfo) is null) { diagnostics.Add(ErrorCode.ERR_BadRecordBase, baseLocation); } } else if (SynthesizedRecordClone.FindValidCloneMethod(localBase, ref useSiteInfo) is object) { diagnostics.Add(ErrorCode.ERR_BadInheritanceFromRecord, baseLocation); } diagnostics.Add(baseLocation, useSiteInfo); } }