protected override TypeSymbol InferTypeOfVarVariable(DiagnosticBag diagnostics) { var newBinder = new ImplicitlyTypedLocalBinder(this.binder, this); var initializerOpt = newBinder.BindInferredVariableInitializer(diagnostics, _initializer, _initializer); if (initializerOpt != null) { return initializerOpt.Type; } return null; }
private TypeSymbol GetTypeSymbol() { var diagnostics = DiagnosticBag.GetInstance(); Binder typeBinder = this.binder; bool isVar; TypeSymbol declType = typeBinder.BindType(typeSyntax, diagnostics, out isVar); if (isVar) { TypeSymbol inferredType = null; if (this.DeclarationKind == LocalDeclarationKind.ForEach) { // Normally, it would not be safe to cast to a specific binder type. However, we verified the type // in the factory method call for this symbol. inferredType = ((ForEachLoopBinder)typeBinder).InferCollectionElementType(diagnostics, collection); } else if (initializer != null) { var newBinder = new ImplicitlyTypedLocalBinder(typeBinder, this); var initializerOpt = newBinder.BindInferredVariableInitializer(diagnostics, initializer, initializer); if (initializerOpt != null) { inferredType = initializerOpt.Type; } } // If we got a valid result that was not void then use the inferred type // else create an error type. if ((object)inferredType != null && inferredType.SpecialType != SpecialType.System_Void) { declType = inferredType; } else { declType = typeBinder.CreateErrorType("var"); } } Debug.Assert((object)declType != null); diagnostics.Free(); return(declType); }
protected override TypeSymbol InferTypeOfVarVariable(DiagnosticBag diagnostics) { // Since initializer might use Out Variable Declarations and Pattern Variable Declarations, we need to find // the right binder to use for the initializer. // Climb up the syntax tree looking for a first binder that we can find, but stop at the first statement syntax. CSharpSyntaxNode currentNode = _initializer; Binder initializerBinder; do { initializerBinder = this.binder.GetBinder(currentNode); if (initializerBinder != null || currentNode is StatementSyntax) { break; } currentNode = currentNode.Parent; }while (currentNode != null); #if DEBUG Binder parentBinder = initializerBinder; while (parentBinder != null) { if (parentBinder == this.binder) { break; } parentBinder = parentBinder.Next; } Debug.Assert(parentBinder != null); #endif var newBinder = new ImplicitlyTypedLocalBinder(initializerBinder ?? this.binder, this); var initializerOpt = newBinder.BindInferredVariableInitializer(diagnostics, RefKind, _initializer, _initializer); if (initializerOpt != null) { return(initializerOpt.Type); } return(null); }
private TypeSymbol GetTypeSymbol() { var diagnostics = DiagnosticBag.GetInstance(); Binder typeBinder = this.binder; bool isVar; TypeSymbol declType = typeBinder.BindType(typeSyntax, diagnostics, out isVar); if (isVar) { TypeSymbol inferredType = null; if (this.DeclarationKind == LocalDeclarationKind.ForEach) { // Normally, it would not be safe to cast to a specific binder type. However, we verified the type // in the factory method call for this symbol. inferredType = ((ForEachLoopBinder)typeBinder).InferCollectionElementType(diagnostics, collection); } else if (initializer != null) { var newBinder = new ImplicitlyTypedLocalBinder(typeBinder, this); var initializerOpt = newBinder.BindInferredVariableInitializer(diagnostics, initializer, initializer); if (initializerOpt != null) { inferredType = initializerOpt.Type; } } // If we got a valid result that was not void then use the inferred type // else create an error type. if ((object)inferredType != null && inferredType.SpecialType != SpecialType.System_Void) { declType = inferredType; } else { declType = typeBinder.CreateErrorType("var"); } } Debug.Assert((object)declType != null); diagnostics.Free(); return declType; }
protected override TypeSymbol InferTypeOfVarVariable(DiagnosticBag diagnostics) { // Since initializer might use Out Variable Declarations and Pattern Variable Declarations, we need to find // the right binder to use for the initializer. // Climb up the syntax tree looking for a first binder that we can find, but stop at the first statement syntax. CSharpSyntaxNode currentNode = _initializer; Binder initializerBinder; do { initializerBinder = this.binder.GetBinder(currentNode); if (initializerBinder != null || currentNode is StatementSyntax) { break; } currentNode = currentNode.Parent; } while (currentNode != null); #if DEBUG Binder parentBinder = initializerBinder; while (parentBinder != null) { if (parentBinder == this.binder) { break; } parentBinder = parentBinder.Next; } Debug.Assert(parentBinder != null); #endif var newBinder = new ImplicitlyTypedLocalBinder(initializerBinder ?? this.binder, this); var initializerOpt = newBinder.BindInferredVariableInitializer(diagnostics, RefKind, _initializer, _initializer); if (initializerOpt != null) { return initializerOpt.Type; } return null; }
protected override TypeSymbol InferTypeOfVarVariable(DiagnosticBag diagnostics) { var newBinder = new ImplicitlyTypedLocalBinder(this.binder, this); var initializerOpt = newBinder.BindInferredVariableInitializer(diagnostics, initializer, initializer); if (initializerOpt != null) { return initializerOpt.Type; } return null; }