internal (CSharpAttributeData, BoundAttribute) GetAttribute(AttributeSyntax node, NamedTypeSymbol boundAttributeType, out bool generatedDiagnostics)
        {
            var dummyDiagnosticBag = new BindingDiagnosticBag(DiagnosticBag.GetInstance());
            var result             = base.GetAttribute(node, boundAttributeType, dummyDiagnosticBag);

            generatedDiagnostics = !dummyDiagnosticBag.DiagnosticBag.IsEmptyWithoutResolution;
            dummyDiagnosticBag.Free();
            return(result);
        }
Exemplo n.º 2
0
        internal BoundExpression SetInferredTypeWithAnnotations(
            TypeWithAnnotations type,
            Binder?binderOpt,
            BindingDiagnosticBag?diagnosticsOpt
            )
        {
            Debug.Assert(binderOpt != null || type.HasType);
            Debug.Assert(
                this.Syntax.Kind() == SyntaxKind.SingleVariableDesignation ||
                (
                    this.Syntax.Kind() == SyntaxKind.DeclarationExpression &&
                    ((DeclarationExpressionSyntax)this.Syntax).Designation.Kind()
                    == SyntaxKind.SingleVariableDesignation
                )
                );

            bool inferenceFailed = !type.HasType;

            if (inferenceFailed)
            {
                type = TypeWithAnnotations.Create(binderOpt !.CreateErrorType("var"));
            }

            switch (this.VariableSymbol.Kind)
            {
            case SymbolKind.Local:
                var localSymbol = (SourceLocalSymbol)this.VariableSymbol;

                if (diagnosticsOpt?.DiagnosticBag != null)
                {
                    if (inferenceFailed)
                    {
                        ReportInferenceFailure(diagnosticsOpt);
                    }
                    else
                    {
                        SyntaxNode typeOrDesignationSyntax =
                            this.Syntax.Kind() == SyntaxKind.DeclarationExpression
                                    ? ((DeclarationExpressionSyntax)this.Syntax).Type
                                    : this.Syntax;

                        Binder.CheckRestrictedTypeInAsyncMethod(
                            localSymbol.ContainingSymbol,
                            type.Type,
                            diagnosticsOpt,
                            typeOrDesignationSyntax
                            );
                    }
                }

                localSymbol.SetTypeWithAnnotations(type);
                return(new BoundLocal(
                           this.Syntax,
                           localSymbol,
                           BoundLocalDeclarationKind.WithInferredType,
                           constantValueOpt: null,
                           isNullableUnknown: false,
                           type: type.Type,
                           hasErrors: this.HasErrors || inferenceFailed
                           ).WithWasConverted());

            case SymbolKind.Field:
                var fieldSymbol          = (GlobalExpressionVariable)this.VariableSymbol;
                var inferenceDiagnostics = new BindingDiagnosticBag(
                    DiagnosticBag.GetInstance()
#if DEBUG
                    ,
                    PooledHashSet <AssemblySymbol> .GetInstance()
#endif
                    );

                if (inferenceFailed)
                {
                    ReportInferenceFailure(inferenceDiagnostics);
                }

                type = fieldSymbol.SetTypeWithAnnotations(type, inferenceDiagnostics);
#if DEBUG
                Debug.Assert(inferenceDiagnostics.DependenciesBag is object);
                Debug.Assert(inferenceDiagnostics.DependenciesBag.Count == 0);
#endif
                inferenceDiagnostics.Free();

                return(new BoundFieldAccess(
                           this.Syntax,
                           this.ReceiverOpt,
                           fieldSymbol,
                           null,
                           LookupResultKind.Viable,
                           isDeclaration: true,
                           type: type.Type,
                           hasErrors: this.HasErrors || inferenceFailed
                           ));

            default:
                throw ExceptionUtilities.UnexpectedValue(this.VariableSymbol.Kind);
            }
        }