Example #1
0
        private void Validate()
        {
            if (this == Empty)
            {
                return;
            }

            DiagnosticBag semanticDiagnostics = _compilation.DeclarationDiagnostics;

            // Check constraints within named aliases.

            // Force resolution of named aliases.
            foreach (var(_, alias) in UsingAliases)
            {
                alias.Alias.GetAliasTarget(basesBeingResolved: null);
                semanticDiagnostics.AddRange(alias.Alias.AliasTargetDiagnostics);
            }

            foreach (var(_, alias) in UsingAliases)
            {
                alias.Alias.CheckConstraints(semanticDiagnostics);
            }

            var corLibrary  = _compilation.SourceAssembly.CorLibrary;
            var conversions = new TypeConversions(corLibrary);

            foreach (var @using in Usings)
            {
                // Check if `using static` directives meet constraints.
                if (@using.NamespaceOrType.IsType)
                {
                    var typeSymbol = (TypeSymbol)@using.NamespaceOrType;
                    var location   = @using.ImportDirective?.Name.Location ?? NoLocation.Singleton;
                    typeSymbol.CheckAllConstraints(_compilation, conversions, location, semanticDiagnostics);
                }
            }

            // Force resolution of extern aliases.
            foreach (var alias in ExternAliases)
            {
                alias.Alias.GetAliasTarget(null);
                semanticDiagnostics.AddRange(alias.Alias.AliasTargetDiagnostics);
            }

            if (_diagnostics != null && !_diagnostics.IsEmptyWithoutResolution)
            {
                semanticDiagnostics.AddRange(_diagnostics.AsEnumerable());
            }
        }
Example #2
0
 private TypeConversions(AssemblySymbol corLibrary, int currentRecursionDepth, bool includeNullability, TypeConversions otherNullabilityOpt)
     : base(corLibrary, currentRecursionDepth, includeNullability, otherNullabilityOpt)
 {
 }