protected override TypeSymbol InferTypeOfVarVariable(DiagnosticBag diagnostics)
            {
                switch (_nodeToBind.Kind())
                {
                case SyntaxKind.ArgumentList:
                    var invocation = (ConstructorInitializerSyntax)_nodeToBind.Parent;
                    _nodeBinder.BindConstructorInitializer(invocation.ArgumentList, (MethodSymbol)ContainingSymbol, diagnostics);
                    break;

                case SyntaxKind.CasePatternSwitchLabel:
                    _nodeBinder.BindPatternSwitchLabelForInference((CasePatternSwitchLabelSyntax)_nodeToBind, diagnostics);
                    break;

                case SyntaxKind.VariableDeclarator:
                    // This occurs, for example, in
                    // int x, y[out var Z, 1 is int I];
                    // for (int x, y[out var Z, 1 is int I]; ;) {}
                    _nodeBinder.BindDeclaratorArguments((VariableDeclaratorSyntax)_nodeToBind, diagnostics);
                    break;

                default:
                    _nodeBinder.BindExpression((ExpressionSyntax)_nodeToBind, diagnostics);
                    break;
                }

                if ((object)this._type == null)
                {
                    Debug.Assert(this.DeclarationKind == LocalDeclarationKind.DeclarationExpressionVariable);
                    SetType(_nodeBinder.CreateErrorType("var"));
                }

                return(this._type);
            }
示例#2
0
            protected override TypeWithAnnotations InferTypeOfVarVariable(DiagnosticBag diagnostics)
            {
                switch (_nodeToBind.Kind())
                {
                case SyntaxKind.ThisConstructorInitializer:
                case SyntaxKind.BaseConstructorInitializer:
                    var initializer = (ConstructorInitializerSyntax)_nodeToBind;
                    _nodeBinder.BindConstructorInitializer(initializer, diagnostics);
                    break;

                case SyntaxKind.SimpleBaseType:
                    _nodeBinder.BindConstructorInitializer((SimpleBaseTypeSyntax)_nodeToBind, diagnostics);
                    break;

                case SyntaxKind.ArgumentList:
                    var invocation = (ConstructorInitializerSyntax)_nodeToBind.Parent;
                    _nodeBinder.BindConstructorInitializer(invocation, diagnostics);
                    break;

                case SyntaxKind.CasePatternSwitchLabel:
                    _nodeBinder.BindPatternSwitchLabelForInference((CasePatternSwitchLabelSyntax)_nodeToBind, diagnostics);
                    break;

                case SyntaxKind.VariableDeclarator:
                    // This occurs, for example, in
                    // int x, y[out var Z, 1 is int I];
                    // for (int x, y[out var Z, 1 is int I]; ;) {}
                    _nodeBinder.BindDeclaratorArguments((VariableDeclaratorSyntax)_nodeToBind, diagnostics);
                    break;

                case SyntaxKind.SwitchExpressionArm:
                    var arm       = (SwitchExpressionArmSyntax)_nodeToBind;
                    var armBinder = (SwitchExpressionArmBinder)_nodeBinder;
                    armBinder.BindSwitchExpressionArm(arm, diagnostics);
                    break;

                case SyntaxKind.GotoCaseStatement:
                    _nodeBinder.BindStatement((GotoStatementSyntax)_nodeToBind, diagnostics);
                    break;

                default:
                    _nodeBinder.BindExpression((ExpressionSyntax)_nodeToBind, diagnostics);
                    break;
                }

                if (this._type == null)
                {
                    Debug.Assert(this.DeclarationKind == LocalDeclarationKind.DeclarationExpressionVariable);
                    SetTypeWithAnnotations(TypeWithAnnotations.Create(_nodeBinder.CreateErrorType("var")));
                }

                return(_type.Value);
            }