@@ -19,7 +19,6 @@ private sealed class ExplicitConversion
1919 private Expr _exprSrc ;
2020 private readonly CType _typeSrc ;
2121 private readonly CType _typeDest ;
22- private readonly ExprClass _exprTypeDest ;
2322
2423 // This is for lambda error reporting. The reason we have this is because we
2524 // store errors for lambda conversions, and then we don't bind the conversion
@@ -36,7 +35,6 @@ private sealed class ExplicitConversion
3635 // to report the error on, so that when the lambda conversion fails, it reports
3736 // errors on the correct type.
3837
39- private readonly CType _pDestinationTypeForLambdaErrorReporting ;
4038 private Expr _exprDest ;
4139 private readonly bool _needsExprDest ;
4240 private readonly CONVERTTYPE _flags ;
@@ -45,14 +43,12 @@ private sealed class ExplicitConversion
4543 // BindExplicitConversion
4644 // ----------------------------------------------------------------------------
4745
48- public ExplicitConversion ( ExpressionBinder binder , Expr exprSrc , CType typeSrc , ExprClass typeDest , CType pDestinationTypeForLambdaErrorReporting , bool needsExprDest , CONVERTTYPE flags )
46+ public ExplicitConversion ( ExpressionBinder binder , Expr exprSrc , CType typeSrc , CType typeDest , bool needsExprDest , CONVERTTYPE flags )
4947 {
5048 _binder = binder ;
5149 _exprSrc = exprSrc ;
5250 _typeSrc = typeSrc ;
53- _typeDest = typeDest . Type ;
54- _pDestinationTypeForLambdaErrorReporting = pDestinationTypeForLambdaErrorReporting ;
55- _exprTypeDest = typeDest ;
51+ _typeDest = typeDest ;
5652 _needsExprDest = needsExprDest ;
5753 _flags = flags ;
5854 _exprDest = null ;
@@ -100,7 +96,7 @@ public bool Bind()
10096 // The set of explicit conversions includes all implicit conversions.
10197
10298 // Don't try user-defined conversions now because we'll try them again later.
103- if ( _binder . BindImplicitConversion ( _exprSrc , _typeSrc , _exprTypeDest , _pDestinationTypeForLambdaErrorReporting , _needsExprDest , out _exprDest , _flags | CONVERTTYPE . ISEXPLICIT ) )
99+ if ( _binder . BindImplicitConversion ( _exprSrc , _typeSrc , _typeDest , _needsExprDest , out _exprDest , _flags | CONVERTTYPE . ISEXPLICIT ) )
104100 {
105101 return true ;
106102 }
@@ -194,7 +190,7 @@ private bool bindExplicitConversionFromNub()
194190
195191 // If S and T are value types and there is a builtin conversion from S => T then there is an
196192 // explicit conversion from S? => T that throws on null.
197- if ( _typeDest . IsValType ( ) && _binder . BindExplicitConversion ( null , _typeSrc . StripNubs ( ) , _exprTypeDest , _pDestinationTypeForLambdaErrorReporting , _flags | CONVERTTYPE . NOUDC ) )
193+ if ( _typeDest . IsValType ( ) && _binder . BindExplicitConversion ( null , _typeSrc . StripNubs ( ) , _typeDest , _flags | CONVERTTYPE . NOUDC ) )
198194 {
199195 if ( _needsExprDest )
200196 {
@@ -205,7 +201,7 @@ private bool bindExplicitConversionFromNub()
205201 }
206202
207203 Debug . Assert ( valueSrc . Type == _typeSrc . StripNubs ( ) ) ;
208- if ( ! _binder . BindExplicitConversion ( valueSrc , valueSrc . Type , _exprTypeDest , _pDestinationTypeForLambdaErrorReporting , _needsExprDest , out _exprDest , _flags | CONVERTTYPE . NOUDC ) )
204+ if ( ! _binder . BindExplicitConversion ( valueSrc , valueSrc . Type , _typeDest , _needsExprDest , out _exprDest , _flags | CONVERTTYPE . NOUDC ) )
209205 {
210206 Debug . Fail ( "BindExplicitConversion failed unexpectedly" ) ;
211207 return false ;
@@ -263,7 +259,7 @@ private bool bindExplicitConversionFromArrayToIList()
263259 }
264260
265261 if ( _needsExprDest )
266- _binder . bindSimpleCast ( _exprSrc , _exprTypeDest , out _exprDest , EXPRFLAG . EXF_REFCHECK ) ;
262+ _binder . bindSimpleCast ( _exprSrc , _typeDest , out _exprDest , EXPRFLAG . EXF_REFCHECK ) ;
267263 return true ;
268264 }
269265
@@ -304,7 +300,7 @@ private bool bindExplicitConversionFromIListToArray(ArrayType arrayDest)
304300 return false ;
305301 }
306302 if ( _needsExprDest )
307- _binder . bindSimpleCast ( _exprSrc , _exprTypeDest , out _exprDest , EXPRFLAG . EXF_REFCHECK ) ;
303+ _binder . bindSimpleCast ( _exprSrc , _typeDest , out _exprDest , EXPRFLAG . EXF_REFCHECK ) ;
308304 return true ;
309305 }
310306
@@ -330,7 +326,7 @@ private bool bindExplicitConversionFromArrayToArray(ArrayType arraySrc, ArrayTyp
330326 if ( CConversions . FExpRefConv ( GetSymbolLoader ( ) , arraySrc . GetElementType ( ) , arrayDest . GetElementType ( ) ) )
331327 {
332328 if ( _needsExprDest )
333- _binder . bindSimpleCast ( _exprSrc , _exprTypeDest , out _exprDest , EXPRFLAG . EXF_REFCHECK ) ;
329+ _binder . bindSimpleCast ( _exprSrc , _typeDest , out _exprDest , EXPRFLAG . EXF_REFCHECK ) ;
334330 return true ;
335331 }
336332
@@ -361,7 +357,7 @@ private bool bindExplicitConversionToArray(ArrayType arrayDest)
361357 if ( _binder . canConvert ( _binder . GetPredefindType ( PredefinedType . PT_ARRAY ) , _typeSrc , CONVERTTYPE . NOUDC ) )
362358 {
363359 if ( _needsExprDest )
364- _binder . bindSimpleCast ( _exprSrc , _exprTypeDest , out _exprDest , EXPRFLAG . EXF_REFCHECK ) ;
360+ _binder . bindSimpleCast ( _exprSrc , _typeDest , out _exprDest , EXPRFLAG . EXF_REFCHECK ) ;
365361 return true ;
366362 }
367363 return false ;
@@ -380,7 +376,7 @@ private bool bindExplicitConversionToPointer()
380376 if ( _typeSrc is PointerType || _typeSrc . fundType ( ) <= FUNDTYPE . FT_LASTINTEGRAL && _typeSrc . isNumericType ( ) )
381377 {
382378 if ( _needsExprDest )
383- _binder . bindSimpleCast ( _exprSrc , _exprTypeDest , out _exprDest ) ;
379+ _binder . bindSimpleCast ( _exprSrc , _typeDest , out _exprDest ) ;
384380 return true ;
385381 }
386382 return false ;
@@ -428,7 +424,7 @@ private AggCastResult bindExplicitConversionFromEnumToAggregate(AggregateType ag
428424
429425 if ( _exprSrc . GetConst ( ) != null )
430426 {
431- ConstCastResult result = _binder . bindConstantCast ( _exprSrc , _exprTypeDest , _needsExprDest , out _exprDest , true ) ;
427+ ConstCastResult result = _binder . bindConstantCast ( _exprSrc , _typeDest , _needsExprDest , out _exprDest , true ) ;
432428 if ( result == ConstCastResult . Success )
433429 {
434430 return AggCastResult . Success ;
@@ -440,7 +436,7 @@ private AggCastResult bindExplicitConversionFromEnumToAggregate(AggregateType ag
440436 }
441437
442438 if ( _needsExprDest )
443- _binder . bindSimpleCast ( _exprSrc , _exprTypeDest , out _exprDest ) ;
439+ _binder . bindSimpleCast ( _exprSrc , _typeDest , out _exprDest ) ;
444440 return AggCastResult . Success ;
445441 }
446442
@@ -453,7 +449,7 @@ private AggCastResult bindExplicitConversionFromDecimalToEnum(AggregateType aggT
453449 if ( _exprSrc . GetConst ( ) != null )
454450 {
455451 // Fold the constant cast if possible.
456- ConstCastResult result = _binder . bindConstantCast ( _exprSrc , _exprTypeDest , _needsExprDest , out _exprDest , true ) ;
452+ ConstCastResult result = _binder . bindConstantCast ( _exprSrc , _typeDest , _needsExprDest , out _exprDest , true ) ;
457453 if ( result == ConstCastResult . Success )
458454 {
459455 return AggCastResult . Success ; // else, don't fold and use a regular cast, below.
@@ -478,7 +474,7 @@ private AggCastResult bindExplicitConversionFromDecimalToEnum(AggregateType aggT
478474 if ( bIsConversionOK )
479475 {
480476 // upcast to the Enum type
481- _binder . bindSimpleCast ( _exprDest , _exprTypeDest , out _exprDest ) ;
477+ _binder . bindSimpleCast ( _exprDest , _typeDest , out _exprDest ) ;
482478 }
483479 }
484480 return bIsConversionOK ? AggCastResult . Success : AggCastResult . Failure ;
@@ -502,16 +498,15 @@ private AggCastResult bindExplicitConversionFromEnumToDecimal(AggregateType aggT
502498 }
503499 else
504500 {
505- ExprClass underlyingExpr = GetExprFactory ( ) . CreateClass ( underlyingType ) ;
506- _binder . bindSimpleCast ( _exprSrc , underlyingExpr , out exprCast ) ;
501+ _binder . bindSimpleCast ( _exprSrc , underlyingType , out exprCast ) ;
507502 }
508503
509504 // There is always an implicit conversion from any integral type to decimal.
510505
511506 if ( exprCast . GetConst ( ) != null )
512507 {
513508 // Fold the constant cast if possible.
514- ConstCastResult result = _binder . bindConstantCast ( exprCast , _exprTypeDest , _needsExprDest , out _exprDest , true ) ;
509+ ConstCastResult result = _binder . bindConstantCast ( exprCast , _typeDest , _needsExprDest , out _exprDest , true ) ;
515510 if ( result == ConstCastResult . Success )
516511 {
517512 return AggCastResult . Success ; // else, don't fold and use a regular cast, below.
@@ -558,7 +553,7 @@ private AggCastResult bindExplicitConversionToEnum(AggregateType aggTypeDest)
558553 // Transform constant to constant.
559554 if ( _exprSrc . GetConst ( ) != null )
560555 {
561- ConstCastResult result = _binder . bindConstantCast ( _exprSrc , _exprTypeDest , _needsExprDest , out _exprDest , true ) ;
556+ ConstCastResult result = _binder . bindConstantCast ( _exprSrc , _typeDest , _needsExprDest , out _exprDest , true ) ;
562557 if ( result == ConstCastResult . Success )
563558 {
564559 return AggCastResult . Success ;
@@ -569,14 +564,14 @@ private AggCastResult bindExplicitConversionToEnum(AggregateType aggTypeDest)
569564 }
570565 }
571566 if ( _needsExprDest )
572- _binder . bindSimpleCast ( _exprSrc , _exprTypeDest , out _exprDest ) ;
567+ _binder . bindSimpleCast ( _exprSrc , _typeDest , out _exprDest ) ;
573568 return AggCastResult . Success ;
574569 }
575570 else if ( _typeSrc . isPredefined ( ) &&
576571 ( _typeSrc . isPredefType ( PredefinedType . PT_OBJECT ) || _typeSrc . isPredefType ( PredefinedType . PT_VALUE ) || _typeSrc . isPredefType ( PredefinedType . PT_ENUM ) ) )
577572 {
578573 if ( _needsExprDest )
579- _binder . bindSimpleCast ( _exprSrc , _exprTypeDest , out _exprDest , EXPRFLAG . EXF_UNBOX ) ;
574+ _binder . bindSimpleCast ( _exprSrc , _typeDest , out _exprDest , EXPRFLAG . EXF_UNBOX ) ;
580575 return AggCastResult . Success ;
581576 }
582577 return AggCastResult . Failure ;
@@ -620,7 +615,7 @@ private AggCastResult bindExplicitConversionBetweenSimpleTypes(AggregateType agg
620615 if ( _exprSrc . GetConst ( ) != null )
621616 {
622617 // Fold the constant cast if possible.
623- ConstCastResult result = _binder . bindConstantCast ( _exprSrc , _exprTypeDest , _needsExprDest , out _exprDest , true ) ;
618+ ConstCastResult result = _binder . bindConstantCast ( _exprSrc , _typeDest , _needsExprDest , out _exprDest , true ) ;
624619 if ( result == ConstCastResult . Success )
625620 {
626621 return AggCastResult . Success ; // else, don't fold and use a regular cast, below.
@@ -644,7 +639,7 @@ private AggCastResult bindExplicitConversionBetweenSimpleTypes(AggregateType agg
644639 }
645640 else
646641 {
647- _binder . bindSimpleCast ( _exprSrc , _exprTypeDest , out _exprDest , ( _flags & CONVERTTYPE . CHECKOVERFLOW ) != 0 ? EXPRFLAG . EXF_CHECKOVERFLOW : 0 ) ;
642+ _binder . bindSimpleCast ( _exprSrc , _typeDest , out _exprDest , ( _flags & CONVERTTYPE . CHECKOVERFLOW ) != 0 ? EXPRFLAG . EXF_CHECKOVERFLOW : 0 ) ;
648643 }
649644 }
650645 return bConversionOk ? AggCastResult . Success : AggCastResult . Failure ;
@@ -681,11 +676,11 @@ private AggCastResult bindExplicitConversionBetweenAggregates(AggregateType aggT
681676 {
682677 if ( aggDest . IsValueType ( ) && aggSrc . getThisType ( ) . fundType ( ) == FUNDTYPE . FT_REF )
683678 {
684- _binder . bindSimpleCast ( _exprSrc , _exprTypeDest , out _exprDest , EXPRFLAG . EXF_UNBOX ) ;
679+ _binder . bindSimpleCast ( _exprSrc , _typeDest , out _exprDest , EXPRFLAG . EXF_UNBOX ) ;
685680 }
686681 else
687682 {
688- _binder . bindSimpleCast ( _exprSrc , _exprTypeDest , out _exprDest , EXPRFLAG . EXF_REFCHECK | ( _exprSrc ? . Flags & EXPRFLAG . EXF_CANTBENULL ?? 0 ) ) ;
683+ _binder . bindSimpleCast ( _exprSrc , _typeDest , out _exprDest , EXPRFLAG . EXF_REFCHECK | ( _exprSrc ? . Flags & EXPRFLAG . EXF_CANTBENULL ?? 0 ) ) ;
689684 }
690685 }
691686 return AggCastResult . Success ;
@@ -697,7 +692,7 @@ private AggCastResult bindExplicitConversionBetweenAggregates(AggregateType aggT
697692 CConversions . HasGenericDelegateExplicitReferenceConversion ( GetSymbolLoader ( ) , _typeSrc , aggTypeDest ) )
698693 {
699694 if ( _needsExprDest )
700- _binder . bindSimpleCast ( _exprSrc , _exprTypeDest , out _exprDest , EXPRFLAG . EXF_REFCHECK | ( _exprSrc ? . Flags & EXPRFLAG . EXF_CANTBENULL ?? 0 ) ) ;
695+ _binder . bindSimpleCast ( _exprSrc , _typeDest , out _exprDest , EXPRFLAG . EXF_REFCHECK | ( _exprSrc ? . Flags & EXPRFLAG . EXF_CANTBENULL ?? 0 ) ) ;
701696 return AggCastResult . Success ;
702697 }
703698 return AggCastResult . Failure ;
@@ -716,7 +711,7 @@ private AggCastResult bindExplicitConversionFromPointerToInt(AggregateType aggTy
716711 return AggCastResult . Failure ;
717712 }
718713 if ( _needsExprDest )
719- _binder . bindSimpleCast ( _exprSrc , _exprTypeDest , out _exprDest ) ;
714+ _binder . bindSimpleCast ( _exprSrc , _typeDest , out _exprDest ) ;
720715 return AggCastResult . Success ;
721716 }
722717
0 commit comments