private static void TypeDependsClosure(NamedTypeSymbol type, CSharpCompilation currentCompilation, HashSet <Symbol> partialClosure) { if ((object)type == null) { return; } type = type.OriginalDefinition; if (partialClosure.Add(type)) { if (type.IsInterface) { foreach (var bt in type.GetDeclaredInterfaces(null)) { TypeDependsClosure(bt, currentCompilation, partialClosure); } } else { TypeDependsClosure(type.GetDeclaredBaseType(null), currentCompilation, partialClosure); } // containment is interesting only for the current compilation if (currentCompilation != null && type.IsFromCompilation(currentCompilation)) { TypeDependsClosure(type.ContainingType, currentCompilation, partialClosure); } } }
public static bool CheckConstraints( this NamedTypeSymbol type, CSharpCompilation currentCompilation, ConversionsBase conversions, Location location, DiagnosticBag diagnostics) { // We do not report element locations in method parameters and return types // so we will simply unwrap the type if it was a tuple. We are relying on // TypeSymbolExtensions.VisitType to dig into the "Rest" tuple so that they // will be recursively unwrapped as well. type = (NamedTypeSymbol)type.TupleUnderlyingTypeOrSelf(); if (!RequiresChecking(type)) { return(true); } var diagnosticsBuilder = ArrayBuilder <TypeParameterDiagnosticInfo> .GetInstance(); ArrayBuilder <TypeParameterDiagnosticInfo> useSiteDiagnosticsBuilder = null; var result = CheckTypeConstraints(type, conversions, currentCompilation, diagnosticsBuilder, ref useSiteDiagnosticsBuilder); if (useSiteDiagnosticsBuilder != null) { diagnosticsBuilder.AddRange(useSiteDiagnosticsBuilder); } foreach (var pair in diagnosticsBuilder) { diagnostics.Add(new CSDiagnostic(pair.DiagnosticInfo, location)); } diagnosticsBuilder.Free(); // we only check for distinct interfaces when the type is not from source, as we // trust that types that are from source have already been checked by the compiler // to prevent this from happening in the first place. if (!(currentCompilation != null && type.IsFromCompilation(currentCompilation)) && HasDuplicateInterfaces(type, null)) { result = false; diagnostics.Add(ErrorCode.ERR_BogusType, location, type); } return(result); }
private static void ClassDependsClosure(NamedTypeSymbol type, CSharpCompilation currentCompilation, HashSet<Symbol> partialClosure) { if ((object)type == null) { return; } type = type.OriginalDefinition; if (partialClosure.Add(type)) { ClassDependsClosure(type.GetDeclaredBaseType(null), currentCompilation, partialClosure); // containment is interesting only for the current compilation if (currentCompilation != null && type.IsFromCompilation(currentCompilation)) { ClassDependsClosure(type.ContainingType, currentCompilation, partialClosure); } } }
public static bool CheckConstraints( this NamedTypeSymbol type, CSharpCompilation currentCompilation, ConversionsBase conversions, Location location, DiagnosticBag diagnostics) { if (!RequiresChecking(type)) { return(true); } var diagnosticsBuilder = ArrayBuilder <TypeParameterDiagnosticInfo> .GetInstance(); ArrayBuilder <TypeParameterDiagnosticInfo> useSiteDiagnosticsBuilder = null; var result = CheckTypeConstraints(type, conversions, currentCompilation, diagnosticsBuilder, ref useSiteDiagnosticsBuilder); if (useSiteDiagnosticsBuilder != null) { diagnosticsBuilder.AddRange(useSiteDiagnosticsBuilder); } foreach (var pair in diagnosticsBuilder) { diagnostics.Add(new CSDiagnostic(pair.DiagnosticInfo, location)); } diagnosticsBuilder.Free(); // we only check for distinct interfaces when the type is not from source, as we // trust that types that are from source have already been checked by the compiler // to prevent this from happening in the first place. if (!(currentCompilation != null && type.IsFromCompilation(currentCompilation)) && HasDuplicateInterfaces(type, null)) { result = false; diagnostics.Add(ErrorCode.ERR_BogusType, location, type); } return(result); }