private void ValidateCallerFilePathAttribute(AttributeSyntax node, DiagnosticBag diagnostics)
        {
            CSharpCompilation        compilation        = this.DeclaringCompilation;
            HashSet <DiagnosticInfo> useSiteDiagnostics = null;

            if (!IsValidCallerInfoContext(node))
            {
                // CS4025: The CallerFilePathAttribute applied to parameter '{0}' will have no effect because it applies to a
                //         member that is used in contexts that do not allow optional arguments
                diagnostics.Add(ErrorCode.WRN_CallerFilePathParamForUnconsumedLocation, node.Name.Location, CSharpSyntaxNode.Identifier.ValueText);
            }
            else if (!compilation.Conversions.HasCallerInfoStringConversion(Type, ref useSiteDiagnostics))
            {
                // CS4018: CallerFilePathAttribute cannot be applied because there are no standard conversions from type '{0}' to type '{1}'
                TypeSymbol stringType = compilation.GetSpecialType(SpecialType.System_String);
                diagnostics.Add(ErrorCode.ERR_NoConversionForCallerFilePathParam, node.Name.Location, stringType, Type);
            }
            else if (!HasExplicitDefaultValue && !ContainingSymbol.IsPartialImplementation()) // attribute applied to parameter without default
            {
                // Unconsumed location checks happen first, so we require a default value.

                // CS4021: The CallerFilePathAttribute may only be applied to parameters with default values
                diagnostics.Add(ErrorCode.ERR_BadCallerFilePathParamWithoutDefaultValue, node.Name.Location);
            }
            else if (HasCallerLineNumberAttribute)
            {
                // CS7082: The CallerFilePathAttribute applied to parameter '{0}' will have no effect. It is overridden by the CallerLineNumberAttribute.
                diagnostics.Add(ErrorCode.WRN_CallerLineNumberPreferredOverCallerFilePath, node.Name.Location, CSharpSyntaxNode.Identifier.ValueText);
            }

            diagnostics.Add(node.Name.Location, useSiteDiagnostics);
        }
        public override bool Equals(Symbol other, TypeCompareKind compareKind)
        {
            if (other == (object)this)
            {
                return(true);
            }

            if (!(other is LocalSymbol otherLocal))
            {
                return(false);
            }

            SourceLocalSymbol?otherSource = otherLocal switch
            {
                UpdatedContainingSymbolAndNullableAnnotationLocal updated => updated._underlyingLocal,
                SourceLocalSymbol source => source,
                             _ => null
            };

            if (otherSource is null || !_underlyingLocal.Equals(otherSource, compareKind))
            {
                return(false);
            }

            var ignoreNullable = (compareKind & TypeCompareKind.AllNullableIgnoreOptions) != 0;

            return(ignoreNullable ||
                   (TypeWithAnnotations.Equals(otherLocal.TypeWithAnnotations, compareKind) &&
                    ContainingSymbol.Equals(otherLocal.ContainingSymbol, compareKind)));
        }
        internal override void ForceComplete(SourceLocation locationOpt, CancellationToken cancellationToken)
        {
            while (true)
            {
                cancellationToken.ThrowIfCancellationRequested();
                var incompletePart = _state.NextIncompletePart;
                switch (incompletePart)
                {
                //@t-mawind We don't have any attributes on these, so don't
                // try to complete them.

                case CompletionPart.TypeParameterConstraints:
                    var constraintTypes = ConstraintTypesNoUseSiteDiagnostics;

                    // Nested type parameter references might not be valid in error scenarios.
                    //Debug.Assert(this.ContainingSymbol.IsContainingSymbolOfAllTypeParameters(this.ConstraintTypes));
                    //Debug.Assert(this.ContainingSymbol.IsContainingSymbolOfAllTypeParameters(ImmutableArray<TypeSymbol>.CreateFrom(this.Interfaces)));
                    Debug.Assert(ContainingSymbol.IsContainingSymbolOfAllTypeParameters(EffectiveBaseClassNoUseSiteDiagnostics));
                    Debug.Assert(ContainingSymbol.IsContainingSymbolOfAllTypeParameters(DeducedBaseTypeNoUseSiteDiagnostics));
                    break;

                case CompletionPart.None:
                    return;

                default:
                    // any other values are completion parts intended for other kinds of symbols
                    // @t-mawind Again, we don't have attributes, so note them complete.
                    _state.NotePartComplete(CompletionPart.All & ~CompletionPart.TypeParameterConstraints);
                    break;
                }

                _state.SpinWaitComplete(incompletePart, cancellationToken);
            }
        }
示例#4
0
            public override bool Equals(Symbol obj, TypeCompareKind compareKind)
            {
                if (obj == (object)this)
                {
                    return(true);
                }

                var other = obj as SynthesizedOperatorParameterSymbol;

                if ((object)other == null)
                {
                    return(false);
                }

                return(Ordinal == other.Ordinal && ContainingSymbol.Equals(other.ContainingSymbol, compareKind));
            }
        /// <summary>
        /// Determines whether every constraint type on this type parameter
        /// names a concept.
        /// <remarks>
        /// This is a requirement for witness type parameters, mainly to
        /// ensure that their syntax isn't accidentally or intentionally
        /// misused.
        /// </remarks>
        /// </summary>
        /// <param name="diagnostics">
        /// The diagnostics bag to which errors raised by non-concept-naming
        /// constraint types will be added.
        /// </param>
        private void CheckAllConstraintTypesNameConcepts(DiagnosticBag diagnostics)
        {
            foreach (var constraintType in ConstraintTypesNoUseSiteDiagnostics)
            {
                if (!constraintType.IsConceptType())
                {
                    var loc = constraintType.Locations.IsEmpty ? Location.None : constraintType.Locations[0];

                    // Currently, call this a missing type variable in the constraint.
                    // This may change later.
                    diagnostics.Add(ErrorCode.ERR_TyVarNotFoundInConstraint,
                                    ClauseLocation,
                                    Name,
                                    ContainingSymbol.ConstructedFrom());
                }
            }
        }
        protected override void MakeMembers(ArrayBuilder <Symbol> mb, Binder binder, DiagnosticBag diagnostics)
        {
            // TODO(@MattWindsor91): handle duplicate methods

            foreach (var concept in ((SourceNamedTypeSymbol)ContainingSymbol).GetConceptsForInlineInstances(null))
            {
                foreach (var member in concept.GetMembersUnordered())
                {
                    // TODO(@MattWindsor91): properties
                    if (member.Kind != SymbolKind.Method)
                    {
                        // TODO(@MattWindsor91): better error?
                        diagnostics.Add(ErrorCode.ERR_InlineInstanceNonMethodMember, ContainingSymbol.GetNonNullSyntaxNode().Location, member);
                        continue;
                    }
                    var shim = TrySynthesizeInstanceShim(concept, (MethodSymbol)member, diagnostics);
                    if (shim != null)
                    {
                        mb.Add(shim);
                    }
                }
            }
        }
 private bool IsValidCallerInfoContext(AttributeSyntax node)
 {
     return(!ContainingSymbol.IsExplicitInterfaceImplementation() && !ContainingSymbol.IsOperator() && !IsOnPartialImplementation(node));
 }
示例#8
0
 /// <summary>
 /// The declaration diagnostics for a parameter depend on the containing symbol.
 /// For instance, if the containing symbol is a method the declaration diagnostics
 /// go on the compilation, but if it is a local function it is part of the local
 /// function's declaration diagnostics.
 /// </summary>
 internal override void AddDeclarationDiagnostics(DiagnosticBag diagnostics)
 => ContainingSymbol.AddDeclarationDiagnostics(diagnostics);
        internal void CheckConceptImplementations(DiagnosticBag diagnostics, CancellationToken cancellationToken)
        {
            // TODO(@MattWindsor91): Most of this is copied from
            //     SourceMemberContainerSymbol.ComputeInterfaceImplementations,
            //     and may not be relevant or optimal.

            ImmutableHashSet <NamedTypeSymbol> interfacesAndTheirBases = InterfacesAndTheirBaseInterfacesNoUseSiteDiagnostics;

            foreach (var concept in AllInterfacesNoUseSiteDiagnostics)
            {
                cancellationToken.ThrowIfCancellationRequested();

                if (!interfacesAndTheirBases.Contains(concept))
                {
                    continue;
                }

                foreach (var conceptMember in concept.GetMembersUnordered())
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    // Only require implementations for members that can be implemented in C#.
                    SymbolKind conceptMemberKind = conceptMember.Kind;
                    switch (conceptMemberKind)
                    {
                    case SymbolKind.Method:
                    case SymbolKind.Property:
                    case SymbolKind.Event:
                        if (conceptMember.IsStatic)
                        {
                            continue;
                        }
                        break;

                    default:
                        continue;
                    }

                    var implementingMemberAndDiagnostics = FindImplementationForInterfaceMemberWithDiagnostics(conceptMember);
                    // TODO(@MattWindsor91): Probably incorrect
                    if (implementingMemberAndDiagnostics.Diagnostics.Any())
                    {
                        diagnostics.AddRange(implementingMemberAndDiagnostics.Diagnostics);
                    }
                    else if (implementingMemberAndDiagnostics.Symbol == null)
                    {
                        // Suppress for bogus properties and events and for indexed properties.
                        if (!conceptMember.MustCallMethodsDirectly() && !conceptMember.IsIndexedProperty())
                        {
                            DiagnosticInfo useSiteDiagnostic = conceptMember.GetUseSiteDiagnostic();

                            if (useSiteDiagnostic != null && useSiteDiagnostic.DefaultSeverity == DiagnosticSeverity.Error)
                            {
                                // TODO(@MattWindsor91): location is wrong.
                                diagnostics.Add(useSiteDiagnostic, ContainingSymbol.GetNonNullSyntaxNode().Location);
                            }
                            else
                            {
                                diagnostics.Add(ErrorCode.ERR_InlineInstanceMissingMember, ContainingSymbol.GetNonNullSyntaxNode().Location, ContainingSymbol, concept, conceptMember);
                            }
                        }
                    }
                }
            }
        }
示例#10
0
 internal virtual byte?GetNullableContextValue()
 {
     return(GetLocalNullableContextValue() ?? ContainingSymbol?.GetNullableContextValue());
 }