コード例 #1
0
 private void CheckNullableAnnotationsInConstraints(DiagnosticBag diagnostics)
 {
     if (ConstraintsNeedNullableAttribute())
     {
         DeclaringCompilation.EnsureNullableAttributeExists(diagnostics, this.GetNonNullSyntaxNode().Location, ModifyCompilationForAttributeEmbedding());
     }
 }
コード例 #2
0
        internal void ComputeReturnType()
        {
            if (!_lazyReturnType.IsDefault)
            {
                return;
            }

            var        diagnostics               = DiagnosticBag.GetInstance();
            TypeSyntax returnTypeSyntax          = _syntax.ReturnType;
            TypeSymbolWithAnnotations returnType = _binder.BindType(returnTypeSyntax.SkipRef(), diagnostics);

            if (this.IsAsync)
            {
                if (this.RefKind != RefKind.None)
                {
                    ReportBadRefToken(returnTypeSyntax, diagnostics);
                }
                else if (returnType.TypeSymbol.IsBadAsyncReturn(this.DeclaringCompilation))
                {
                    diagnostics.Add(ErrorCode.ERR_BadAsyncReturn, this.Locations[0]);
                }
            }

            var location = _syntax.ReturnType.Location;

            if (_refKind == RefKind.RefReadOnly)
            {
                DeclaringCompilation.EnsureIsReadOnlyAttributeExists(diagnostics, location, modifyCompilation: false);
            }

            if (returnType.NeedsNullableAttribute())
            {
                DeclaringCompilation.EnsureNullableAttributeExists(diagnostics, location, modifyCompilation: false);
                // Note: we don't need to warn on annotations used without NonNullTypes context for local functions, as this is handled in binding already
            }

            // span-like types are returnable in general
            if (returnType.IsRestrictedType(ignoreSpanLikeTypes: true))
            {
                // Method or delegate cannot return type '{0}'
                diagnostics.Add(ErrorCode.ERR_MethodReturnCantBeRefAny, returnTypeSyntax.Location, returnType.TypeSymbol);
            }

            Debug.Assert(_refKind == RefKind.None ||
                         returnType.SpecialType != SpecialType.System_Void ||
                         returnTypeSyntax.HasErrors);

            lock (_declarationDiagnostics)
            {
                if (!_lazyReturnType.IsDefault)
                {
                    diagnostics.Free();
                    return;
                }

                _declarationDiagnostics.AddRangeAndFree(diagnostics);
                _lazyReturnType = returnType;
            }
        }
コード例 #3
0
 private void CheckNullableAnnotationsInConstraints(DiagnosticBag diagnostics)
 {
     if ((this.HasReferenceTypeConstraint && this.ReferenceTypeConstraintIsNullable != null) ||
         this.ConstraintTypesNoUseSiteDiagnostics.Any(c => c.NeedsNullableAttribute()))
     {
         DeclaringCompilation.EnsureNullableAttributeExists(diagnostics, this.GetNonNullSyntaxNode().Location, ModifyCompilationForAttributeEmbedding());
     }
 }
コード例 #4
0
 internal override void AfterAddingTypeMembersChecks(ConversionsBase conversions, DiagnosticBag diagnostics)
 {
     var location = ErrorLocation;
     if (this.Type.NeedsNullableAttribute())
     {
         DeclaringCompilation.EnsureNullableAttributeExists(diagnostics, location, modifyCompilation: true);
     }
 }
コード例 #5
0
 private void EnsureAttributesFromConstraints(DiagnosticBag diagnostics)
 {
     if (ConstraintTypesNoUseSiteDiagnostics.Any(t => t.ContainsNativeInteger()))
     {
         DeclaringCompilation.EnsureNativeIntegerAttributeExists(diagnostics, getLocation(), ModifyCompilationForAttributeEmbedding());
     }
     if (ConstraintsNeedNullableAttribute())
     {
         DeclaringCompilation.EnsureNullableAttributeExists(diagnostics, getLocation(), ModifyCompilationForAttributeEmbedding());
     }
     Location getLocation() => this.GetNonNullSyntaxNode().Location;
 }
コード例 #6
0
        internal void ComputeReturnType()
        {
            if (!_lazyReturnType.IsNull)
            {
                return;
            }

            var        diagnostics               = DiagnosticBag.GetInstance();
            TypeSyntax returnTypeSyntax          = _syntax.ReturnType;
            TypeSymbolWithAnnotations returnType = _binder.BindType(returnTypeSyntax.SkipRef(), diagnostics);

            if (this.IsAsync)
            {
                if (this.RefKind != RefKind.None)
                {
                    ReportBadRefToken(returnTypeSyntax, diagnostics);
                }
                else if (returnType.TypeSymbol.IsBadAsyncReturn(this.DeclaringCompilation))
                {
                    diagnostics.Add(ErrorCode.ERR_BadAsyncReturn, this.Locations[0]);
                }
            }

            var location = _syntax.ReturnType.Location;

            if (_refKind == RefKind.RefReadOnly)
            {
                DeclaringCompilation.EnsureIsReadOnlyAttributeExists(diagnostics, location, modifyCompilation: false);
            }

            if (returnType.ContainsNullableReferenceTypes())
            {
                DeclaringCompilation.EnsureNullableAttributeExists(diagnostics, location, modifyCompilation: false);
                // Note: we don't need to warn on annotations used without NonNullTypes context for local functions, as this is handled in binding already
            }

            Debug.Assert(_refKind == RefKind.None ||
                         returnType.SpecialType != SpecialType.System_Void ||
                         returnTypeSyntax.HasErrors);

            lock (_declarationDiagnostics)
            {
                if (!_lazyReturnType.IsNull)
                {
                    diagnostics.Free();
                    return;
                }

                _declarationDiagnostics.AddRangeAndFree(diagnostics);
                _lazyReturnType = returnType;
            }
        }