Exemplo n.º 1
0
 public override void VisitParameterDeclarationSyntax(ParameterDeclarationSyntax syntax)
 {
     // {deployment,resourceroup}().location are acceptable inside of the "location" parameter's
     //   default value, so don't traverse into the parameter's default value any further because we'll flag
     //   any other uses of those expressions.
     return;
 }
Exemplo n.º 2
0
        private IEnumerable <Diagnostic> ValidateIdentifierAccess(ParameterDeclarationSyntax syntax)
        {
            return(SyntaxAggregator.Aggregate(syntax, new List <Diagnostic>(), (accumulated, current) =>
            {
                if (current is VariableAccessSyntax)
                {
                    var symbol = bindings[current];

                    // Error: already has error info attached, no need to add more
                    // Parameter: references are permitted in other parameters' default values as long as there is not a cycle (BCP080)
                    // Function: we already validate that a function cannot be used as a variable (BCP063)
                    // Output: we already validate that outputs cannot be referenced in expressions (BCP058)
                    if (symbol.Kind != SymbolKind.Error &&
                        symbol.Kind != SymbolKind.Parameter &&
                        symbol.Kind != SymbolKind.Function &&
                        symbol.Kind != SymbolKind.Output)
                    {
                        accumulated.Add(DiagnosticBuilder.ForPosition(current).CannotReferenceSymbolInParamDefaultValue());
                    }
                }

                return accumulated;
            },
                                              accumulated => accumulated));
        }
Exemplo n.º 3
0
 public override void VisitParameterDeclarationSyntax(ParameterDeclarationSyntax syntax)
 {
     currentDeclaration = declarations[syntax.Name.IdentifierName];
     declarationAccessDict[currentDeclaration] = new List <SyntaxBase>();
     base.VisitParameterDeclarationSyntax(syntax);
     currentDeclaration = null;
 }
Exemplo n.º 4
0
        public override void VisitParameterDeclarationSyntax(ParameterDeclarationSyntax syntax)
        {
            base.VisitParameterDeclarationSyntax(syntax);

            var symbol = new ParameterSymbol(this.context, syntax.Name.IdentifierName, syntax, syntax.Modifier);

            this.declaredSymbols.Add(symbol);
        }
Exemplo n.º 5
0
 public override void VisitParameterDeclarationSyntax(ParameterDeclarationSyntax syntax) =>
 this.BuildStatement(syntax, () =>
 {
     this.VisitNodes(syntax.LeadingNodes);
     this.Visit(syntax.Keyword);
     this.documentStack.Push(Nil);
     this.Visit(syntax.Name);
     this.Visit(syntax.Type);
     this.Visit(syntax.Modifier);
 });
Exemplo n.º 6
0
 public override void VisitParameterDeclarationSyntax(ParameterDeclarationSyntax syntax)
 {
     allowedFlags = FunctionFlags.ParameterDecorator;
     this.VisitNodes(syntax.LeadingNodes);
     this.Visit(syntax.Keyword);
     this.Visit(syntax.Name);
     this.Visit(syntax.Type);
     allowedFlags = FunctionFlags.ParamDefaultsOnly;
     this.Visit(syntax.Modifier);
     allowedFlags = FunctionFlags.Default;
 }
Exemplo n.º 7
0
 public ParameterType?GetParameterType(ParameterDeclarationSyntax parameterDeclarationSyntax)
 {
     if (parameterDeclarationSyntax.ParameterType is SimpleTypeSyntax simpleTypeSyntax &&
         simpleTypeSyntax is not null)
     {
         return(simpleTypeSyntax.TypeName switch
         {
             "array" => ParameterType.Array,
             "bool" => ParameterType.Bool,
             "int" => ParameterType.Int,
             "object" => ParameterType.Object,
             "string" => ParameterType.String,
             _ => null,
         });
Exemplo n.º 8
0
        public override void VisitParameterDeclarationSyntax(ParameterDeclarationSyntax syntax)
        => AssignTypeWithDiagnostics(syntax, diagnostics => {
            diagnostics.AddRange(this.ValidateIdentifierAccess(syntax));

            // assume "any" type when the parameter has parse errors (either missing or was skipped)
            var declaredType = syntax.ParameterType == null
                    ? LanguageConstants.Any
                    : LanguageConstants.TryGetDeclarationType(syntax.ParameterType.TypeName);

            if (declaredType == null)
            {
                return(new ErrorTypeSymbol(DiagnosticBuilder.ForPosition(syntax.Type).InvalidParameterType()));
            }

            var assignedType = declaredType;
            if (object.ReferenceEquals(assignedType, LanguageConstants.String))
            {
                var allowedItemTypes = SyntaxHelper.TryGetAllowedItems(syntax)?
                                       .Select(item => typeManager.GetTypeInfo(item));

                if (allowedItemTypes != null && allowedItemTypes.All(itemType => itemType is StringLiteralType))
                {
                    assignedType = UnionType.Create(allowedItemTypes);
                }
            }

            switch (syntax.Modifier)
            {
            case ParameterDefaultValueSyntax defaultValueSyntax:
                diagnostics.AddRange(ValidateDefaultValue(defaultValueSyntax, assignedType));
                break;

            case ObjectSyntax modifierSyntax:
                var modifierType = LanguageConstants.CreateParameterModifierType(declaredType, assignedType);
                // we don't need to actually use the narrowed type; just need to use this to collect assignment diagnostics
                TypeValidator.NarrowTypeAndCollectDiagnostics(typeManager, modifierSyntax, modifierType, diagnostics);
                break;
            }

            return(assignedType);
        });
Exemplo n.º 9
0
        public override void VisitParameterDeclarationSyntax(ParameterDeclarationSyntax syntax)
        {
            diagnostics.AddRange(this.ValidateIdentifierAccess(syntax));

            var assignedType = typeManager.GetTypeInfo(syntax);

            switch (syntax.Modifier)
            {
            case ParameterDefaultValueSyntax defaultValueSyntax:
                diagnostics.AddRange(ValidateDefaultValue(defaultValueSyntax, assignedType));
                break;

            case ObjectSyntax modifierSyntax:
                if (assignedType.TypeKind != TypeKind.Error && SyntaxHelper.TryGetPrimitiveType(syntax) is PrimitiveType primitiveType)
                {
                    var modifierType = LanguageConstants.CreateParameterModifierType(primitiveType, assignedType);
                    diagnostics.AddRange(TypeValidator.GetExpressionAssignmentDiagnostics(typeManager, modifierSyntax, modifierType));
                }
                break;
            }
        }
Exemplo n.º 10
0
        public override void VisitParameterDeclarationSyntax(ParameterDeclarationSyntax syntax)
        => AssignTypeWithCaching(syntax, () => {
            var primitiveType = LanguageConstants.TryGetDeclarationType(syntax.Type.TypeName);
            if (primitiveType == null)
            {
                return(new ErrorTypeSymbol(DiagnosticBuilder.ForPosition(syntax.Type).InvalidParameterType()));
            }

            if (!object.ReferenceEquals(primitiveType, LanguageConstants.String))
            {
                return(primitiveType);
            }

            var allowedItemTypes = SyntaxHelper.TryGetAllowedItems(syntax)?
                                   .Select(item => VisitAndReturnType(item));

            if (allowedItemTypes == null || !allowedItemTypes.All(itemType => itemType is StringLiteralType))
            {
                return(primitiveType);
            }

            return(UnionType.Create(allowedItemTypes));
        });
Exemplo n.º 11
0
 public override void VisitParameterDeclarationSyntax(ParameterDeclarationSyntax syntax)
 {
     allowedFlags = FunctionFlags.ParamDefaultsOnly;
     base.VisitParameterDeclarationSyntax(syntax);
     allowedFlags = FunctionFlags.Default;
 }
Exemplo n.º 12
0
 public override void VisitParameterDeclarationSyntax(ParameterDeclarationSyntax syntax) =>
 this.BuildStatement(syntax, () => base.VisitParameterDeclarationSyntax(syntax));
Exemplo n.º 13
0
 public ParameterSymbol(ISymbolContext context, string name, ParameterDeclarationSyntax declaringSyntax, SyntaxBase?modifier)
     : base(context, name, declaringSyntax, declaringSyntax.Name)
 {
     this.Modifier = modifier;
 }
Exemplo n.º 14
0
 public override void VisitParameterDeclarationSyntax(ParameterDeclarationSyntax syntax) =>
 this.BuildWithSpread(() => base.VisitParameterDeclarationSyntax(syntax));
Exemplo n.º 15
0
 public override void VisitParameterDeclarationSyntax(ParameterDeclarationSyntax syntax)
 => VisitDeclaration(syntax, base.VisitParameterDeclarationSyntax);
Exemplo n.º 16
0
 private DeclaredTypeAssignment GetParameterType(ParameterDeclarationSyntax syntax) => new DeclaredTypeAssignment(syntax.GetDeclaredType(), syntax);
Exemplo n.º 17
0
 public ParameterSymbol(ISymbolContext context, string name, ParameterDeclarationSyntax declaringSyntax)
     : base(context, name, declaringSyntax, declaringSyntax.Name)
 {
 }