Esempio n. 1
0
        public override void VisitInstanceFunctionCallSyntax(InstanceFunctionCallSyntax syntax)
        {
            FunctionFlags currentFlags = allowedFlags;

            this.Visit(syntax.BaseExpression);
            this.Visit(syntax.Dot);
            this.Visit(syntax.Name);
            this.Visit(syntax.OpenParen);
            allowedFlags = allowedFlags.HasDecoratorFlag() ? FunctionFlags.Default : allowedFlags;
            this.VisitNodes(syntax.Arguments);
            this.Visit(syntax.CloseParen);
            allowedFlags = currentFlags;

            if (!syntax.Name.IsValid)
            {
                // the parser produced an instance function calls with an invalid name
                // all instance function calls must be bound to a symbol, so let's
                // bind to a symbol without any errors (there's already a parse error)
                this.bindings.Add(syntax, new ErrorSymbol());
                return;
            }

            if (bindings.TryGetValue(syntax.BaseExpression, out var baseSymbol) && baseSymbol is NamespaceSymbol namespaceSymbol)
            {
                var functionSymbol = allowedFlags.HasDecoratorFlag()
                                     // Decorator functions are only valid when HasDecoratorFlag() is true which means
                                     // the instance function call is the top level expression of a DecoratorSyntax node.
                    ? namespaceSymbol.Type.MethodResolver.TryGetSymbol(syntax.Name) ?? namespaceSymbol.Type.DecoratorResolver.TryGetSymbol(syntax.Name)
                    : namespaceSymbol.Type.MethodResolver.TryGetSymbol(syntax.Name);

                var foundSymbol = SymbolValidator.ResolveNamespaceQualifiedFunction(allowedFlags, functionSymbol, syntax.Name, namespaceSymbol);

                this.bindings.Add(syntax, foundSymbol);
            }
        }
Esempio n. 2
0
            public override void VisitInstanceFunctionCallSyntax(InstanceFunctionCallSyntax syntax)
            {
                if (syntax.Name.IdentifierName.StartsWithOrdinalInsensitively(ListFunctionPrefix))
                {
                    bool isFailure = false;

                    Symbol?baseSymbol = model.GetSymbolInfo(syntax.BaseExpression);
                    if (baseSymbol is ResourceSymbol)
                    {
                        // It's a usage of a list*() member function for a resource value, e.g.:
                        //
                        //   output badResult object = stg.listKeys().keys[0].value
                        //
                        isFailure = true;
                    }
                    else if (baseSymbol is BuiltInNamespaceSymbol)
                    {
                        // It's a usage of a built-in list*() function as a member of the built-in "az" module, e.g.:
                        //
                        //   output badResult object = az.listKeys(resourceId('Microsoft.Storage/storageAccounts', 'storageName'), '2021-02-01')
                        //
                        isFailure = true;
                    }

                    if (isFailure)
                    {
                        string foundMessage = string.Format(CoreResources.OutputsShouldNotContainSecretsFunction, syntax.Name.IdentifierName);
                        this.diagnostics.Add(parent.CreateDiagnosticForSpan(syntax.Span, foundMessage));
                    }
                }

                base.VisitInstanceFunctionCallSyntax(syntax);
            }
Esempio n. 3
0
        public override void VisitInstanceFunctionCallSyntax(InstanceFunctionCallSyntax syntax)
        {
            base.VisitInstanceFunctionCallSyntax(syntax);

            if (bindings.TryGetValue(syntax.BaseExpression, out var baseSymbol) && baseSymbol is NamespaceSymbol namespaceSymbol)
            {
                var functionSymbol = namespaceSymbol.Type.MethodResolver.TryGetSymbol(syntax.Name);

                var foundSymbol = SymbolValidator.ResolveNamespaceQualifiedFunction(allowedFlags, functionSymbol, syntax.Name, namespaceSymbol);

                this.bindings.Add(syntax, foundSymbol);
            }
        }
Esempio n. 4
0
        public override void VisitInstanceFunctionCallSyntax(InstanceFunctionCallSyntax syntax)
        {
            base.VisitInstanceFunctionCallSyntax(syntax);

            Symbol foundSymbol;

            // baseExpression must be bound to a namespaceSymbol otherwise there was an error
            if (bindings.ContainsKey(syntax.BaseExpression) &&
                bindings[syntax.BaseExpression] is NamespaceSymbol namespaceSymbol)
            {
                foundSymbol = this.LookupSymbolByName(syntax.Name.IdentifierName, syntax.Name.Span, namespaceSymbol);
            }
            else
            {
                foundSymbol = new UnassignableSymbol(DiagnosticBuilder.ForPosition(syntax.Name.Span).SymbolicNameDoesNotExist(syntax.Name.IdentifierName));
            }

            // bind what we got - the type checker will validate if it fits
            this.bindings.Add(syntax, foundSymbol);
        }
        public override void VisitInstanceFunctionCallSyntax(InstanceFunctionCallSyntax syntax)
        {
            if (this.model.Binder.GetParent(syntax) is DecoratorSyntax)
            {
                return;
            }

            var baseType = this.model.TypeManager.GetTypeInfo(syntax.BaseExpression);

            if (TypeAssignmentVisitor.UnwrapType(baseType) is not ObjectType objectType)
            {
                return;
            }

            var symbol = SymbolValidator.ResolveObjectQualifiedFunctionWithoutValidatingFlags(
                objectType.MethodResolver.TryGetSymbol(syntax.Name),
                syntax.Name,
                objectType);

            if (symbol is not FunctionSymbol functionSymbol)
            {
                return;
            }

            var currentDeployTimeConstantScopeSyntax = this.deployTimeConstantScopeSyntax;

            if (functionSymbol.FunctionFlags.HasFlag(FunctionFlags.RequiresInlining))
            {
                this.deployTimeConstantScopeSyntax = syntax;
            }

            base.VisitInstanceFunctionCallSyntax(syntax);

            if (this.errorSyntax is not null)
            {
                this.AppendError();
            }


            this.deployTimeConstantScopeSyntax = currentDeployTimeConstantScopeSyntax;
        }
Esempio n. 6
0
        public override void VisitInstanceFunctionCallSyntax(InstanceFunctionCallSyntax syntax)
        {
            base.VisitInstanceFunctionCallSyntax(syntax);

            if (!syntax.Name.IsValid)
            {
                // the parser produced an instance function calls with an invalid name
                // all instance function calls must be bound to a symbol, so let's
                // bind to a symbol without any errors (there's already a parse error)
                this.bindings.Add(syntax, new ErrorSymbol());
                return;
            }

            if (bindings.TryGetValue(syntax.BaseExpression, out var baseSymbol) && baseSymbol is NamespaceSymbol namespaceSymbol)
            {
                var functionSymbol = namespaceSymbol.Type.MethodResolver.TryGetSymbol(syntax.Name);

                var foundSymbol = SymbolValidator.ResolveNamespaceQualifiedFunction(allowedFlags, functionSymbol, syntax.Name, namespaceSymbol);

                this.bindings.Add(syntax, foundSymbol);
            }
        }
Esempio n. 7
0
 public override void VisitInstanceFunctionCallSyntax(InstanceFunctionCallSyntax syntax)
 {
     VisitFunctionCallSyntaxBaseInternal(syntax);
     base.VisitInstanceFunctionCallSyntax(syntax);
 }
Esempio n. 8
0
 public override void VisitInstanceFunctionCallSyntax(InstanceFunctionCallSyntax syntax)
 {
     this.AppendError(syntax);
 }