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); }
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); }
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]; ;) {} var declarator = (VariableDeclaratorSyntax)_nodeToBind; if (declarator.ArgumentList != null) { foreach (var arg in declarator.ArgumentList.Arguments) { var expression = arg.Expression; if (expression.Kind() == SyntaxKind.DeclarationExpression) { this.SetType(_nodeBinder.CreateErrorType("var")); // no error is necessary, as they would be dropped on the floor by the caller } else { _nodeBinder.BindExpression(expression, diagnostics); } } } break; default: _nodeBinder.BindExpression((ExpressionSyntax)_nodeToBind, diagnostics); break; } Debug.Assert((object)this._type != null); return(this._type); }