@@ -325,7 +325,7 @@ public Expression Parse(Type resultType, bool createParameterCtor)
325
325
int exprPos = _textParser . CurrentToken . Pos ;
326
326
Expression expr = ParseExpression ( ) ;
327
327
if ( resultType != null )
328
- if ( ( expr = PromoteExpression ( expr , resultType , true ) ) == null )
328
+ if ( ( expr = PromoteExpression ( expr , resultType , true , false ) ) == null )
329
329
throw ParseError ( exprPos , Res . ExpressionTypeMismatch , GetTypeName ( resultType ) ) ;
330
330
_textParser . ValidateToken ( TokenId . End , Res . SyntaxError ) ;
331
331
return expr ;
@@ -596,11 +596,11 @@ Expression ParseComparison()
596
596
if ( left . Type != right . Type )
597
597
{
598
598
Expression e ;
599
- if ( ( e = PromoteExpression ( right , left . Type , true ) ) != null )
599
+ if ( ( e = PromoteExpression ( right , left . Type , true , false ) ) != null )
600
600
{
601
601
right = e ;
602
602
}
603
- else if ( ( e = PromoteExpression ( left , right . Type , true ) ) != null )
603
+ else if ( ( e = PromoteExpression ( left , right . Type , true , false ) ) != null )
604
604
{
605
605
left = e ;
606
606
}
@@ -1067,8 +1067,8 @@ Expression GenerateConditional(Expression test, Expression expr1, Expression exp
1067
1067
throw ParseError ( errorPos , Res . FirstExprMustBeBool ) ;
1068
1068
if ( expr1 . Type != expr2 . Type )
1069
1069
{
1070
- Expression expr1As2 = expr2 != NullLiteral ? PromoteExpression ( expr1 , expr2 . Type , true ) : null ;
1071
- Expression expr2As1 = expr1 != NullLiteral ? PromoteExpression ( expr2 , expr1 . Type , true ) : null ;
1070
+ Expression expr1As2 = expr2 != NullLiteral ? PromoteExpression ( expr1 , expr2 . Type , true , false ) : null ;
1071
+ Expression expr2As1 = expr1 != NullLiteral ? PromoteExpression ( expr2 , expr1 . Type , true , false ) : null ;
1072
1072
if ( expr1As2 != null && expr2As1 == null )
1073
1073
{
1074
1074
expr1 = expr1As2 ;
@@ -1448,7 +1448,7 @@ Expression ParseElementAccess(Expression expr)
1448
1448
{
1449
1449
if ( expr . Type . GetArrayRank ( ) != 1 || args . Length != 1 )
1450
1450
throw ParseError ( errorPos , Res . CannotIndexMultiDimArray ) ;
1451
- Expression index = PromoteExpression ( args [ 0 ] , typeof ( int ) , true ) ;
1451
+ Expression index = PromoteExpression ( args [ 0 ] , typeof ( int ) , true , false ) ;
1452
1452
if ( index == null )
1453
1453
throw ParseError ( errorPos , Res . InvalidIndex ) ;
1454
1454
return Expression . ArrayIndex ( expr , index ) ;
@@ -1771,15 +1771,15 @@ bool IsApplicable(MethodData method, Expression[] args)
1771
1771
{
1772
1772
ParameterInfo pi = method . Parameters [ i ] ;
1773
1773
if ( pi . IsOut ) return false ;
1774
- Expression promoted = PromoteExpression ( args [ i ] , pi . ParameterType , false ) ;
1774
+ Expression promoted = PromoteExpression ( args [ i ] , pi . ParameterType , false , method . MethodBase . DeclaringType != typeof ( IEnumerableSignatures ) ) ;
1775
1775
if ( promoted == null ) return false ;
1776
1776
promotedArgs [ i ] = promoted ;
1777
1777
}
1778
1778
method . Args = promotedArgs ;
1779
1779
return true ;
1780
1780
}
1781
1781
1782
- Expression PromoteExpression ( Expression expr , Type type , bool exact )
1782
+ Expression PromoteExpression ( Expression expr , Type type , bool exact , bool convertExpr )
1783
1783
{
1784
1784
if ( expr . Type == type ) return expr ;
1785
1785
@@ -1837,7 +1837,7 @@ Expression PromoteExpression(Expression expr, Type type, bool exact)
1837
1837
1838
1838
if ( IsCompatibleWith ( expr . Type , type ) )
1839
1839
{
1840
- if ( type . GetTypeInfo ( ) . IsValueType || exact )
1840
+ if ( type . GetTypeInfo ( ) . IsValueType || exact || ( expr . Type . GetTypeInfo ( ) . IsValueType && convertExpr ) )
1841
1841
return Expression . Convert ( expr , type ) ;
1842
1842
1843
1843
return expr ;
0 commit comments